From 5c3f21f481e7472d2b8a6834c47d8894e7251736 Mon Sep 17 00:00:00 2001 From: Cameron Patrick Date: Sun, 1 Aug 2004 08:07:29 +0000 Subject: [PATCH] make syslog logging work --- sql-edition/servers/VendServer.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sql-edition/servers/VendServer.py b/sql-edition/servers/VendServer.py index 9e1ba7a..6e870ff 100755 --- a/sql-edition/servers/VendServer.py +++ b/sql-edition/servers/VendServer.py @@ -5,7 +5,7 @@ USE_DB = 0 import ConfigParser import sys, os, string, re, pwd, signal -import logging +import logging, logging.handlers from traceback import format_tb if USE_DB: import pg from time import time, sleep @@ -442,7 +442,8 @@ def create_pid_file(name): logging.warning('unable to write to pid file '+name+': '+str(e)) def set_stuff_up(): - def do_nothing(signum, stack): pass + def do_nothing(signum, stack): + signal.signal(signum, do_nothing) def stop_server(signum, stack): raise KeyboardInterrupt signal.signal(signal.SIGHUP, do_nothing) signal.signal(signal.SIGTERM, stop_server) @@ -450,8 +451,8 @@ def set_stuff_up(): options = parse_args() config_opts = VendConfigFile(options.config_file, config_options) - set_up_logging(options) if options.daemon: become_daemon() + set_up_logging(options) if options.pid_file != '': create_pid_file(options.pid_file) return options, config_opts @@ -477,12 +478,16 @@ def set_up_logging(options): logger.addHandler(file_logger) except IOError, e: logger.warning('unable to write to log file '+options.log_file+': '+str(e)) + + if options.syslog: + sys_logger = logging.handlers.SysLogHandler('/dev/log', 'daemon') + sys_logger.setFormatter(logging.Formatter('vendserver[%d]'%(os.getpid()) + ' %(levelname)s: %(message)s')) + logger.addHandler(sys_logger) if options.verbose: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) - def become_daemon(): dev_null = file('/dev/null') -- 2.20.1