log.py - Gate One Logging Module

Logging Module for Gate One

This module contains a number of pre-defined loggers for use within Gate One:

Name Description
go_log Used for logging internal Gate One events.
auth_log Used for logging authentication and authorization events.
msg_log Used for logging messages sent to/from users.

Applications may also use their own loggers for differentiation purposes. Such loggers should be prefixed with 'gateone.app.' like so:

>>> import logging
>>> logger = logging.getLogger("gateone.app.myapp")

Additional loggers may be defined within a GOApplication with additional prefixing:

>>> xfer_log = logging.getLogger("gateone.app.myapp.xfer")
>>> lookup_log = logging.getLogger("gateone.app.myapp.lookup")

Note

This module does not cover session logging within the Terminal application. That is a built-in feature of the termio module.

exception gateone.core.log.UnknownFacility[source]

Raised if string_to_syslog_facility is given a string that doesn't match a known syslog facility.

class gateone.core.log.JSONAdapter(logger, extra)[source]

A logging.LoggerAdapter that prepends keyword argument information to log entries. Expects the passed in dict-like object which will be included.

Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.

You can effectively pass keyword arguments as shown in the following example:

adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2"))

gateone.core.log.string_to_syslog_facility(facility)[source]

Given a string (facility) such as, "daemon" returns the numeric syslog.LOG_* equivalent.

gateone.core.log.go_logger(name, **kwargs)[source]

Returns a new logging.Logger instance using the given name pre-configured to match Gate One's usual logging output. The given name will automatically be prefixed with 'gateone.' if it is not already. So if name is 'app.foo' the Logger would end up named 'gateone.app.foo'. If the given name is already prefixed with 'gateone.' it will be left as-is.

The log will be saved in the same location as Gate One's configured log_file_prefix using the given name with the following convention:

gateone/logs/<modified *name*>.log

The file name will be modified like so:

  • It will have the 'gateone' portion removed (since it's redundant).
  • Dots will be replaced with dashes (-).

Examples:

>>> auth_logger = go_logger('gateone.auth.terminal')
>>> auth_logger.info('test1')
>>> app_logger = go_logger('gateone.app.terminal')
>>> app_logger.info('test2')
>>> import os
>>> os.lisdir('/opt/gateone/logs')
['auth.log', 'auth-terminal.log', 'app-terminal.log' 'webserver.log']

If any kwargs are given they will be JSON-encoded and included in the log message after the date/metadata like so:

>>> auth_logger.info('test3', {"user": "bob", "ip": "10.1.1.100"})
[I 130828 15:00:56 app.py:10] {"user": "bob", "ip": "10.1.1.100"} test3