from twisted.web.server import NOT_DONE_YET
import twisted.web.static
+import twisted.python.syslog
import hippotatlib.ownsource
from hippotatlib.ownsource import SourceShipmentPreparer
for sig in (signal.SIGINT, signal.SIGTERM):
signal.signal(sig, partial(signal_handler, sig.name))
+def daemonise():
+ global syslogfacility
+ if opts.daemon and opts.syslogfacility is None:
+ opts.syslogfacility = 'daemon'
+
+ if opts.syslogfacility is not None:
+ facilnum = syslog.__dict__['LOG_' + opts.syslogfacility.upper()]
+ syslog.openlog('hippotatd',
+ facility=facilnum,
+ logoption=syslog.LOG_PID)
+ def emit(event):
+ m = twisted.logger.formatEvent(event)
+ #print(repr(event), m, file=org_stderr)
+ level = event.get('log_level')
+ if event.get('dflag',None) is not None: sl = syslog.LOG_DEBUG
+ elif level == LogLevel.critical : sl = syslog.LOG_CRIT
+ elif level == LogLevel.error : sl = syslog.LOG_ERR
+ elif level == LogLevel.warn : sl = syslog.LOG_WARNING
+ else : sl = syslog.LOG_INFO
+ syslog.syslog(sl,m)
+ glp = twisted.logger.globalLogPublisher
+ glp.addObserver(emit)
+ log_debug(DBG.INIT, 'starting to log to syslog')
+
+ glp.removeObserver(hippotatlib.file_log_observer)
+
optparser.add_option('--ownsource', default=2,
action='store_const', dest='ownsource', const=2,
help='source download fully enabled (default)')
action='store_const', dest='ownsource', const=0,
help='source download disabled (for testing only)')
+optparser.add_option('--syslog-facility',
+ nargs=1, type='string',action='store',
+ metavar='FACILITY', dest='syslogfacility',
+ default=None,
+ help='log to syslog, with specified facility')
+
common_startup(process_cfg)
catch_termination()
ipif = start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d)))
start_http()
+daemonise()
common_run()
stdsomething_obs = twisted.logger.FilteringLogObserver(
stderr_obs, [pred], stdout_obs
)
- log_observer = twisted.logger.FilteringLogObserver(
+ global file_log_observer
+ file_log_observer = twisted.logger.FilteringLogObserver(
stdsomething_obs, [LogNotBoringTwisted()]
)
#log_observer = stdsomething_obs
twisted.logger.globalLogBeginner.beginLoggingTo(
- [ log_observer, crash_on_critical ]
+ [ file_log_observer, crash_on_critical ]
)
def common_run():