Name: ulogger
Owner: Spotify
Description: A simple micrologging framework
Created: 2017-11-02 19:57:29.0
Updated: 2018-04-03 10:44:03.0
Pushed: 2017-11-30 16:06:01.0
Homepage: null
Size: 32
Language: Python
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A micro Python logging library.
Supported handlers:
) $ pip install ulogger
use the stackdriver handler, you need to specify an extra dependency:
) $ pip install "ulogger[stackdriver]"
ython
rt logging
ulogger import setup_logging
e handler
p_logging('my_program', 'INFO', ['syslog'])
ltiple handlers
p_logging('my_program', 'INFO', ['syslog', 'stream'])
e a different logging facility for syslog (default 16/LOG_LOCAL0)
p_logging('my_program', 'INFO', ['syslog'], facility=1)
p_logging('my_program', 'INFO', ['syslog'], facility=logging.handlers.SysLogHandler.LOG_USER)
en log messages normally
ing.info('ohai')
To just setup a specific handler, e.g. Syslog:
rt logging
ulogger import syslog
er = logging.getLogger('my_logger')
ler = syslog.get_handler('my_program')
er.addHandler(handler)
To setup a Syslog handler with a specific address:
rt logging
ulogger import syslog
er = logging.getLogger('my_logger')
og_addr = ('10.99.0.1', 9514) # (host, port) tuple
just a host is given, the default port 514 is used
og_addr = ('localhost', None) # (host, port)
lepath is supported
og_addr = '/dev/log'
ler = syslog.get_handler('my_program', address=syslog_addr)
v vars are also supported, but will be overwritten if `address` is explicitly given
nviron['SYSLOG_HOST'] = 'localhost'
nviron['SYSLOG_PORT'] = 325
ler = syslog.get_handler('my_program')
P & UDP are supported
o = 1 # TCP
o = socket.SOCK_STREAM # TCP
o = 2 # UDP - default
o = socket.SOCK_DGRAM # UDP - default
ler = syslog.get_handler('my_program', address=syslog_addr, proto=proto)
er.addHandler(handler)
The default date format for all handlers is the following: '%Y-%m-%dT%H:%M:%S'
(example 2017-11-02T09:51:33.792
).
The default log format is slightly different depending on the handler you select:
sctime)s.%(msecs)03dZ <PROGNAME> (%(process)d) %(levelname)s: %(message)s'
Example:
-11-02T09:51:33.792Z my_awesome_program (63079) INFO: Beginning awesome program v3.
sctime)s.%(msecs)03dZ <PROGNAME> (%(process)d): %(message)s'
Example:
-11-02T09:51:33.792Z my_awesome_program (63079): Beginning awesome program v3.
OGNAME> (%(process)d): %(message)s'
Example:
25 13:00:51 my-host.example.net my_awesome_program (63079): Beginning awesome program v3.
NOTE: Default syslog on OS X appends the date and hostname to the log record.
sctime)s.%(msecs)03d <HOST> <PROGNAME> (%(process)d): %(message)s'
Example:
-11-02T19:00:55.850 my-gcp-host my_awesome_program (63079): Beginning awesome program v3"
To add your custom log and/or date formatter:
rt logging
ulogger import setup_logging
fmt = '%(created)f %(levelno)d %(message)s'
date_fmt = '%Y-%m-%dT%H:%M:%S'
p_logging('my_program', 'INFO', ['syslog'], log_fmt, log_date_fmt)
For development and running tests, your system must have all supported versions of Python installed. We suggest using pyenv.
t clone git@github.com:spotify/ulogger.git && cd ulogger
ke a virtualenv
) $ pip install -r dev-requirements.txt
To run the entire test suite:
tside of the virtualenv
tox is not yet installed
p install tox
x
If you want to run the test suite for a specific version of Python:
tside of the virtualenv
x -e py27
x -e py36
To run an individual test, call pytest
directly:
side virtualenv
) $ pytest tests/test_syslog.py
This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.