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
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)
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
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')