titanfe.log module

setup the logging with a custom metric-level

class titanfe.log.FlowContext(flowuid: str = '', flowname: str = '', brickuid: str = '', brickname: str = '')[source]

Bases: object

The Flow Context

asdict()[source]
brickname: str = ''
brickuid: str = ''
flowname: str = ''
flowuid: str = ''
classmethod from_brick(brick: titanfe.apps.control_peer.brick.Brick)[source]
classmethod from_flow(flow: titanfe.apps.control_peer.flow.Flow)[source]
class titanfe.log.KafkaLogHandler(bootstrap_server, topic)[source]

Bases: logging.Handler

Stream LogRecords to Kafka

Parameters:
  • bootstrap_server (str) – ‘Host:Port’ of a kafka bootstrap server

  • topic (str) – the kafka topic to produce into

close()[source]

Tidy up any resources used by the handler.

This version removes the handler from an internal map of handlers, _handlers, which is used for handler lookup by name. Subclasses should ensure that this gets called from overridden close() methods.

emit(record)[source]

emits the record

flush()[source]

Ensure all logging output has been flushed.

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

class titanfe.log.TitanLogAdapter(logger, extra)[source]

Bases: logging.LoggerAdapter

The Log Adapter wraps a logger and adds some context to each log record

property context
getChild(suffix)[source]
metric(message, *args, **kwargs)
class titanfe.log.TitanLogRecord(name, level, pathname, lineno, msg, args, exc_info, func=None, sinfo=None, **kwargs)[source]

Bases: logging.LogRecord

A log record - Titan style

brickname = ''
brickuid = ''
flowname = ''
flowuid = ''
hostname = 'build-19467538-project-510666-titanfe'
servicename = ''
class titanfe.log.TitanPlatformLogger(name, context: Optional[titanfe.log.FlowContext] = None)[source]

Bases: logging.Logger

to write contextual logging information use e.g. log.with_context.info

getChild(suffix)titanfe.log.TitanPlatformLogger[source]

Get a logger which is a descendant to this one.

This is a convenience method, such that

logging.getLogger(‘abc’).getChild(‘def.ghi’)

is the same as

logging.getLogger(‘abc.def.ghi’)

It’s useful, for example, when the parent logger is named using __name__ rather than a literal string.

property with_context
class titanfe.log.UjoBinFormatter(fmt=None, datefmt=None, style='%')[source]

Bases: logging.Formatter

Format log records as an UjoBinary

format(record)[source]

Format a log record as an UjoBinary

Parameters:

record (logging.Record) – the log record

Returns:

binary UjoMap

Return type:

bytes

titanfe.log.add_logging_level(level, level_name, method_name=None)[source]

add a level to the logging module

Parameters:
  • level (int) – level number

  • level_name – name of the level

  • method_name – name of the method that gets attached to logging

titanfe.log.flush_kafka_log_handler()[source]

“Flush messages sent to KafkaLogHandler and suppress warnings from kafka –> called during shutdown of brick runner

titanfe.log.getLogger(name: str, context: Optional[titanfe.log.FlowContext] = None) → logging.Logger[source]

Get a Logger :param name: the logger name :param context: a flow context (if available)

Returns:

a Logger

Return type:

logging.Logger

titanfe.log.initialize(service='')[source]

initialize the titan logging module, e.g. set up a KafkaLogHandler

Parameters:

service – name of the current service