From: W. Trevor King Date: Thu, 20 Feb 2014 22:31:53 +0000 (-0800) Subject: main: Teach package-cache the --syslog option X-Git-Tag: v0.1~10 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5c7b9309a873e1aeb050bb0fb263f39dff4c12bf;p=package-cache.git main: Teach package-cache the --syslog option --- diff --git a/package_cache/main.py b/package_cache/main.py index 11e0e07..9daabdb 100644 --- a/package_cache/main.py +++ b/package_cache/main.py @@ -17,6 +17,7 @@ import argparse as _argparse import logging as _logging +import logging.handlers as _logging_handlers import wsgiref.simple_server as _wsgiref_simple_server from . import __version__ @@ -52,6 +53,9 @@ def run(*args, **kwargs): parser.add_argument( '--verbose', '-v', action='count', help='Increment the logging verbosity') + parser.add_argument( + '--syslog', action='store_const', const=True, + help='Increment the logging verbosity') parser.add_argument( '--host', metavar='HOSTNAME', default='localhost', help='Host to listen as') @@ -71,6 +75,13 @@ def run(*args, **kwargs): _MAIN_LOG.setLevel(max( _logging.DEBUG, _MAIN_LOG.level - 10 * args.verbose)) + if args.syslog: + while _MAIN_LOG.handlers: + h = _MAIN_LOG.handlers[0] + _MAIN_LOG.removeHandler(h) + handler = _logging_handlers.SysLogHandler( + address='/dev/log', facility='daemon') + _MAIN_LOG.addHandler(handler) server = _server.Server(sources=args.source or [], cache=args.cache) wsgi = _wsgiref_simple_server.make_server(