From 5c7b9309a873e1aeb050bb0fb263f39dff4c12bf Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 20 Feb 2014 14:31:53 -0800 Subject: [PATCH] main: Teach package-cache the --syslog option --- package_cache/main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) 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( -- 2.26.2