Logger Module

logger.logger

TcEx Framework Logger module

class tcex.logger.logger.Logger(tcex, logger_name)[source]

Bases: object

Framework logger module.

_log_app_data()[source]

Log the App data information.

_log_platform()[source]

Log the current Platform.

_log_python_version()[source]

Log the current Python version.

_log_tc_proxy(args)[source]

Log the proxy settings.

_log_tcex_version()[source]

Log the current TcEx version number.

add_api_handler(name='api', level=None)[source]

Add API logging handler.

Parameters:name (str, optional) – The name of the handler. Defaults to ‘api’.
add_cache_handler(name)[source]

Add cache logging handler.

Parameters:name (str) – The name of the handler.
add_rotating_file_handler(name, filename, path, backup_count, max_bytes, level, formatter=None, mode='a')[source]

Add a rotating file handler

Parameters:
  • name (str, optional) – The name of the handler. Defaults to ‘rfh’.
  • filename (str) – The name of the logfile.
  • path (str) – The path for the logfile.
  • backup_count (int, optional) – The maximum # of backup files. Defaults to 0.
  • max_bytes (int) – The max file size before rotating. Defaults to 0.
  • level (str) – The logging level. Defaults to None.
  • formatter (str, optional) – The logging formatter to use. Defaults to None.
  • mode (str, optional) – The write mode for the file. Defaults to ‘a’.
add_stream_handler(name='sh', formatter=None, level=None)[source]

Return stream logging handler.

Parameters:
  • name (str, optional) – The name of the handler. Defaults to ‘sh’.
  • formatter (str, optional) – The logging formatter to use. Defaults to None.
  • level (int, optional) – The logging level. Defaults to None.
add_thread_file_handler(name, filename, level, path, formatter=None)[source]

Add File logging handler.

Parameters:
  • name (str) – The name of the handler.
  • filename (str) – The name of the logfile.
  • level (int, optional) – The logging level. Defaults to None.
  • path (str) – The path for the logfile.
  • formatter (str, optional) – The logging formatter to use. Defaults to None.
log

Return logger.

log_info(args)[source]

Send System and App data to logs.

static log_level(level)[source]

Return proper level from string.

Parameters:level (str) – The logging level. Default to ‘debug’.
remove_handler_by_name(handler_name)[source]

Remove a file handler by name.

Parameters:handler_name (str) – The handler name to remove.
replay_cached_events(handler_name='cache')[source]

Replay cached log events and remove handler.

update_handler_level(level)[source]

Update all handlers log level.

Parameters:level (int, optional) – The logging level. Defaults to None.

logger.api_handler

API Handler Class

class tcex.logger.api_handler.ApiHandler(session, flush_limit=100)[source]

Bases: logging.Handler

Logger handler for ThreatConnect Exchange API logging.

emit(record)[source]

Emit a record.

Parameters:record (obj) – The record to be logged.
entries

Return a copy and clear self._entries.

flush()[source]

Close the logger and flush entries.

log_to_api(entries)[source]

Send log events to the ThreatConnect API

class tcex.logger.api_handler.ApiHandlerFormatter[source]

Bases: logging.Formatter

Logger formatter for ThreatConnect Exchange API logging.

format(record)[source]

Format log record for ThreatConnect API.

Example log event:

[{
    "timestamp": 1478907537000,
    "message": "Test Message",
    "level": "DEBUG"
}]
Parameters:record (obj) – The record to be logged.

logger.cache_handler

Cache Handler Class

class tcex.logger.cache_handler.CacheHandler(max_cache=100)[source]

Bases: logging.Handler

Logger handler for caching event until all handlers are availabe.

emit(record)[source]

Emit a record.

Parameters:record (obj) – The record to be logged.
events

Return a copy and clear self._events.

logger.rotating_file_handler_custom

API Handler Class

class tcex.logger.rotating_file_handler_custom.RotatingFileHandlerCustom(filename, mode='a', maxBytes=0, backupCount=0, encoding=None, delay=0)[source]

Bases: logging.handlers.RotatingFileHandler

Logger handler for ThreatConnect Exchange File logging.

logger.thread_file_handler

API Handler Class

class tcex.logger.thread_file_handler.ThreadFileHandler(filename, mode='a', encoding=None, delay=0)[source]

Bases: logging.FileHandler

Logger handler for ThreatConnect Exchange File logging.

emit(record)[source]

Emit a record.

Parameters:record (obj) – The record to be logged.

logger.trace_logger

Trace Logger Class

class tcex.logger.trace_logger.TraceLogger(name, level=0)[source]

Bases: logging.Logger

Add trace level to logging

findCaller(stack_info=False)[source]

Find the caller for the current log event.

Parameters:stack_info (bool, optional) – Defaults to False.
Returns:The caller stack information.
Return type:tuple
trace(msg, *args, **kwargs)[source]

Set trace logging level

Parameters:msg (str) – The message to be logged.