ait.core.log module¶
AIT Logging
The ait.core.log module logs warnings, errors, and other information to standard output and via syslog.
-
class
ait.core.log.
LogFormatter
¶ Bases:
logging.Formatter
Log output format is:
YYYY-MM-DDTHH:MM:SS | levelname | messageWhere levelname is one of ‘critical’, ‘error’, ‘warning’, ‘command’, ‘info’, or ‘debug’.
-
__init__
()¶ LogFormatter()
Creates and returns a new LogFormatter.
-
formatTime
(record, datefmt=None)¶ Return the creation time of the specified LogRecord as formatted text.
-
DATEFMT
= '%Y-%m-%dT%H:%M:%S'¶
-
-
class
ait.core.log.
SysLogFormatter
(bsd=False)¶ Bases:
logging.Formatter
-
__init__
(bsd=False)¶ LogFormatter([bsd=False])
Creates and returns a new SysLogFormatter. If BSD is True, the sylog message is formatted according to the BSD Syslog Protocol:
RFC 3164 - The BSD Syslog Protocol http://tools.ietf.org/html/rfc3164Otherwise, the syslog message is formatted according to the Syslog Protocol:
RFC 5424 - The Syslog Protocol http://tools.ietf.org/html/rfc5424
-
format
(record)¶ Returns the given LogRecord as formatted text.
-
formatTime
(record, datefmt=None)¶ Returns the creation time of the given LogRecord as formatted text.
NOTE: The datefmt parameter and self.converter (the time conversion method) are ignored. BSD Syslog Protocol messages always use local time, and by our convention, Syslog Protocol messages use UTC.
-
BSD_DATEFMT
= '%b %d %H:%M:%S'¶
-
BSD_FMT
= '%(asctime)s %(hostname)s %(name)s[%(process)d]: %(message)s'¶
-
SYSLOG_FMT
= '1 %(asctime)s %(hostname)s %(name)s %(process)d %(levelname)s - %(message)s'¶
-
SYS_DATEFMT
= '%Y-%m-%dT%H:%M:%S.%fZ'¶
-
-
class
ait.core.log.
SysLogHandler
(address=None, facility=None, socktype=None)¶ Bases:
logging.handlers.SysLogHandler
-
__init__
(address=None, facility=None, socktype=None)¶ Initialize a handler.
If address is specified as a string, a UNIX socket is used. To log to a local syslogd, “SysLogHandler(address=”/dev/log”)” can be used. If facility is not specified, LOG_USER is used. If socktype is specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific socket type will be used. For Unix sockets, you can also specify a socktype of None, in which case socket.SOCK_DGRAM will be used, falling back to socket.SOCK_STREAM.
-
-
ait.core.log.
addLocalHandlers
(logger)¶ Adds logging handlers to logger to log to the following local resources:
- The terminal
- localhost:514 (i.e. syslogd)
- localhost:2514 (i.e. the AIT GUI syslog-like handler)
-
ait.core.log.
addRemoteHandlers
(logger)¶ Adds logging handlers to logger to remotely log to:
ait.config.logging.hostname:514 (i.e. syslogd)If not set or hostname cannot be resolved, this method has no effect.
-
ait.core.log.
begin
()¶ Command-line tools should begin logging with core.log.begin() to log the command name and arguments.
-
ait.core.log.
command
(*args, **kwargs)¶
-
ait.core.log.
end
()¶ Command-line tools should end logging with log.end() to log the completion of the command.
-
ait.core.log.
init
()¶
-
ait.core.log.
notice
(*args, **kwargs)¶
-
ait.core.log.
parseSyslog
(msg)¶ Parses Syslog messages (RFC 5424)
The Syslog Message Format (RFC 5424) can be parsed with simple whitespace tokenization:
SYSLOG-MSG = HEADER SP STRUCTURED-DATA [SP MSG] HEADER = PRI VERSION SP TIMESTAMP SP HOSTNAME SP APP-NAME SP PROCID SP MSGID ... NILVALUE = "-"
This method does not return STRUCTURED-DATA. It parses NILVALUE (“-“) STRUCTURED-DATA or simple STRUCTURED-DATA which does not contain (escaped) ‘]’.
Returns: A dictionary keyed by the constituent parts of the Syslog message.
-
ait.core.log.
program
(*args, **kwargs)¶
-
ait.core.log.
reinit
()¶