Logging

This module implements the logging framework for the SKA base device.

class TangoLoggingServiceHandler(tango_logger: Logger)[source]

Handler that emit logs via Tango device’s logger to TLS.

emit(record: LogRecord) None[source]

Emit a log record.

Parameters:

record – the log to be emitted.

class LoggingUtils[source]

Utility functions to aid logger configuration.

These functions are encapsulated in class to aid testing - it allows dependent functions to be mocked.

static sanitise_logging_targets(targets: list[str] | None, device_name: str) list[str][source]

Validate and return logging targets ‘<type>::<name>’ strings.

Parameters:
  • targets – List of candidate logging target strings, like ‘<type>[::<name>]’ Empty and whitespace-only strings are ignored. Can also be None.

  • device_name – Tango device name, like ‘domain/family/member’, used for the default file name

Returns:

list of ‘<type>::<name>’ strings, with default name, if applicable

Raises:

LoggingTargetError – for invalid target string that cannot be corrected

static get_syslog_address_and_socktype(url: str) tuple[tuple[str, int] | str, SocketKind | None][source]

Parse syslog URL and extract address and socktype parameters for SysLogHandler.

Parameters:

url

Universal resource locator string for syslog target. Three types are supported: file path, remote UDP server, remote TCP server.

  • Output to a file: ‘file://<path to file>’. For example, ‘file:///dev/log’ will write to ‘/dev/log’.

  • Output to remote server over UDP: ‘udp://<hostname>:<port>’. For example, ‘udp://syslog.com:514’ will send to host ‘syslog.com’ on UDP port 514

  • Output to remote server over TCP: ‘tcp://<hostname>:<port>’. For example, ‘tcp://rsyslog.com:601’ will send to host ‘rsyslog.com’ on TCP port 601

For backwards compatibility, if the protocol prefix is missing, the type is interpreted as file. This is deprecated. For example, ‘/dev/log’ is equivalent to ‘file:///dev/log’.

Returns:

An (address, socktype) tuple.

For file types:

  • the address is the file path as as string

  • socktype is None

For UDP and TCP:

  • the address is tuple of (hostname, port), with hostname a string, and port an integer.

  • socktype is socket.SOCK_DGRAM for UDP, or socket.SOCK_STREAM for TCP.

Raises:

LoggingTargetError – for invalid url string

static create_logging_handler(target: str, tango_logger: Logger | None = None) Any[source]

Create a Python log handler based on the target type.

Supported target types are “console”, “file”, “syslog”, “tango”.

Parameters:
  • target – Logging target for logger, <type>::<name>

  • tango_logger – Instance of tango.Logger, optional. Only required if creating a target of type “tango”.

Returns:

StreamHandler, RotatingFileHandler, SysLogHandler, or TangoLoggingServiceHandler

Raises:

LoggingTargetError – for invalid target string

static update_logging_handlers(targets: list[str], logger: Logger) None[source]

Update a logger’s handlers.

Parameters:
  • targets – a list of handler names. Current handlers whose name is not included here will be removed. Names for which the logger currently does not have a handler will have handlers created and added.

  • logger – the logger whose handlers are to be updated.