seqlog package

Module contents

seqlog.clear_global_log_properties()[source]

Remove all global properties.

seqlog.configure_from_dict(config, override_root_logger=True, use_structured_logger=True, support_extra_properties=None, support_stack_info=None, ignore_seq_submission_errors=None, use_clef=None)[source]

Configure Seq logging using a dictionary.

Uses logging.config.dictConfig().

Note that if you provide None to any of the default arguments, it just won’t get changed (ie. it will stay the same).

Parameters
  • config (dict) – A dict containing the configuration.

  • override_root_logger (bool) – Override the root logger to use a Seq-specific implementation? (default: True)

  • use_structured_logger (bool) – Configure the default logger class to be StructuredLogger, which support named format arguments? (default: True)

  • support_extra_properties (bool) – Support passing of additional properties to log via the extra argument?

  • support_stack_info (bool) – Support attaching of stack-trace information (if available) to log records?

  • ignore_seq_submission_errors (bool) – Ignore errors encountered while sending log records to Seq?

  • use_clef (bool) – use the newer submission format CLEF

seqlog.configure_from_file(file_name, override_root_logger=True, support_extra_properties=False, support_stack_info=False, ignore_seq_submission_errors=False, use_clef=False)[source]

Configure Seq logging using YAML-format configuration file.

Uses logging.config.dictConfig().

Parameters
  • file_name (str) – The name of the configuration file to use.

  • override_root_logger (bool) – Override the root logger to use a Seq-specific implementation? (default: True)

  • support_extra_properties (bool) – Support passing of additional properties to log via the extra argument?

  • support_stack_info (bool) – Support attaching of stack-trace information (if available) to log records?

  • ignore_seq_submission_errors (bool) – Ignore errors encountered while sending log records to Seq?

  • use_clef (bool) – use the newer submission format CLEF

seqlog.get_global_log_properties()[source]

Get the properties to be added to all structured log entries.

Returns

A copy of the global log properties.

Return type

dict

seqlog.log_to_console(level=30, override_root_logger=False, support_extra_properties=False, support_stack_info=False, **kwargs)[source]

Configure the logging system to send log entries to the console.

Note that the root logger will not log to Seq by default.

Parameters
  • level – The minimum level at which to log.

  • override_root_logger – Override the root logger, too? Note - this might cause problems if third-party components try to be clever when using the logging.XXX functions.

  • support_extra_properties (bool) – Support passing of additional properties to log via the extra argument?

  • support_stack_info (bool) – Support attaching of stack-trace information (if available) to log records?

seqlog.log_to_seq(server_url, api_key=None, level=30, batch_size=10, auto_flush_timeout=None, additional_handlers=None, override_root_logger=False, json_encoder_class=None, support_extra_properties=False, support_stack_info=False, ignore_seq_submission_errors=False, use_clef=False, **kwargs)[source]

Configure the logging system to send log entries to Seq.

Note that the root logger will not log to Seq by default.

Parameters
  • server_url – The Seq server URL.

  • api_key – The Seq API key (optional).

  • level – The minimum level at which to log.

  • batch_size – The number of log entries to collect before publishing to Seq.

  • auto_flush_timeout – If specified, the time (in seconds) before the current batch is automatically flushed.

  • additional_handlers – Additional `LogHandler`s (if any).

  • override_root_logger – Override the root logger, too? Note - this might cause problems if third-party components try to be clever when using the logging.XXX functions.

  • json_encoder_class – The custom JSONEncoder class (if any) to use. It not specified, the default JSONEncoder will be used.

  • support_extra_properties (bool) – Support passing of additional properties to log via the extra argument?

  • support_stack_info (bool) – Support attaching of stack-trace information (if available) to log records?

  • ignore_seq_submission_errors (bool) – Ignore errors encountered while sending log records to Seq?

  • use_clef (bool) – use more modern format to send events to Seq

Returns

The SeqLogHandler that sends events to Seq. Can be used to forcibly flush records to Seq.

Return type

SeqLogHandler

seqlog.reset_global_log_properties()[source]

Initialize global log properties to their default values.

seqlog.set_callback_on_failure(callback: Callable[[Exception], None]) None[source]

Configure a callback to be invoked each time logging fails.

Parameters

callback (callable) – A callable that takes an Exception (representing the logging failure) as its only argument.

seqlog.set_global_log_properties(**properties)[source]

Configure the properties to be added to all structured log entries.

Parameters

properties (str) – Keyword arguments representing the properties.

Submodules

seqlog.structured_logging module

class seqlog.structured_logging.ConsoleStructuredLogHandler[source]

Bases: Handler

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

class seqlog.structured_logging.SeqLogHandler(server_url, api_key=None, batch_size=10, auto_flush_timeout=None, json_encoder_class=None)[source]

Bases: Handler

Log handler that posts to Seq.

close()[source]

Close the log handler.

emit(record)[source]

Emit a log record.

Parameters

record – The LogRecord.

flush()[source]

Ensure all logging output has been flushed.

This version does nothing and is intended to be implemented by subclasses.

handleError(record: StructuredLogRecord)[source]

Handle errors which occur during an emit() call.

Parameters

record – The StructuredLogRecord being logged.

publish_log_batch(batch: List[StructuredLogRecord]) None[source]

Publish a batch of log records.

Parameters

batch – A list representing the batch.

property server_url
class seqlog.structured_logging.StructuredLogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None, log_props=None, **kwargs)[source]

Bases: LogRecord

An extended LogRecord that with custom properties to be logged to Seq.

getMessage()[source]

Get a formatted message representing the log record (with arguments replaced by values as appropriate). :return: The formatted message.

getMessageTemplate()[source]

Get the raw (unformatted) message template used to generate the message for the log record (used in cases where formatting will be performed by the target that receives the published log record). :return: The message template.

class seqlog.structured_logging.StructuredLogger(name, level=0)[source]

Bases: Logger

Custom (dummy) logger that understands named log arguments.

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)[source]

Create a LogRecord.

Parameters
  • name – The name of the logger that produced the log record.

  • level – The logging level (severity) associated with the logging record.

  • fn – The name of the file (if known) where the log entry was created.

  • lno – The line number (if known) in the file where the log entry was created.

  • msg – The log message (or message template).

  • args – Ordinal message format arguments (if any).

  • exc_info – Exception information to be included in the log entry.

  • func – The function (if known) where the log entry was created.

  • extra – Extra information (if any) to add to the log record.

  • sinfo – Stack trace information (if known) for the log entry.

class seqlog.structured_logging.StructuredRootLogger(level=0)[source]

Bases: RootLogger

Custom root logger that understands named log arguments.

makeRecord(name, level, fn, lno, msg, args, exc_info, func=None, extra=None, sinfo=None)[source]

Create a LogRecord.

Parameters
  • name – The name of the logger that produced the log record.

  • level – The logging level (severity) associated with the logging record.

  • fn – The name of the file (if known) where the log entry was created.

  • lno – The line number (if known) in the file where the log entry was created.

  • msg – The log message (or message template).

  • args – Ordinal message format arguments (if any).

  • exc_info – Exception information to be included in the log entry.

  • func – The function (if known) where the log entry was created.

  • extra – Extra information (if any) to add to the log record.

  • sinfo – Stack trace information (if known) for the log entry.

seqlog.structured_logging.best_effort_json_encode(arg)[source]
seqlog.structured_logging.clear_global_log_properties()[source]

Remove all global properties.

seqlog.structured_logging.get_global_log_properties(logger_name=None)[source]

Get the properties to be added to all structured log entries.

Parameters

logger_name (str) – An optional logger name to be added to the log entry.

Returns

A copy of the global log properties.

Return type

dict

seqlog.structured_logging.reset_global_log_properties()[source]

Initialize global log properties to their default values.

seqlog.structured_logging.set_callback_on_failure(callback: Callable[[Exception], None]) None[source]

Configure a callback to be invoked each time logging fails.

Parameters

callback (callable) – A callable that takes an Exception (representing the logging failure) as its only argument.

seqlog.structured_logging.set_global_log_properties(**properties)[source]

Configure the properties to be added to all structured log entries.

Parameters

properties (str) – Keyword arguments representing the properties.