Debug logging

from alexandria3k import debug

Maintain debug state and output enabled messages.

Use example:

import debug

debug.set_flags(["parsing", "time"])
debug.log("flag_name", "Some message")
if debug.enable("flag_name") ...
debug.enabled(flag)

Check if the specified flag is enabled.

Parameters

flag (str) – Flag to check.

Returns

True if the specified flag is enabled.

Return type

bool

debug.log(flag, message, flush=True, end='\n')

Output the specified message if the corresponding flag is enabled.

Parameters
  • flag (str) – Flag that controls the message output.

  • message (str) – Message to output.

debug.set_flags(flags)

Enable the specified debug flags. The following flags are supported:

  • exception: Raise an exception when an error occurs;

  • files-read: Counts of Crossref data files read;

  • link: Record linking operations;

  • sql: Executed SQL statements;

  • perf: Performance timings;

  • progress: Report population progress;

  • progress_bar: Display a progress bar;

  • sorted-tables: Topologically ordered Crossref query tables;

  • stderr: Log to standard error;

Parameters

flags (list) – Flags to enable.

debug.set_output(output_file)

Direct output to the specified output target.

Parameters

output_file (file object) – File object on which output the debug messages, e.g. sys.stderr.