Merge branch 'mathstuf-syslog-logging' into next
This commit is contained in:
commit
f591fe66cc
@ -105,6 +105,10 @@ included), implies the single-thread option -1.
|
|||||||
|
|
||||||
Send logs to <file.log>.
|
Send logs to <file.log>.
|
||||||
|
|
||||||
|
-s::
|
||||||
|
|
||||||
|
Send logs to syslog.
|
||||||
|
|
||||||
|
|
||||||
-f <folder1[,folder1[,...]]>::
|
-f <folder1[,folder1[,...]]>::
|
||||||
|
|
||||||
|
@ -89,6 +89,11 @@ class OfflineImap:
|
|||||||
parser.add_option("-l", dest="logfile", metavar="FILE",
|
parser.add_option("-l", dest="logfile", metavar="FILE",
|
||||||
help="log to FILE")
|
help="log to FILE")
|
||||||
|
|
||||||
|
parser.add_option("-s",
|
||||||
|
action="store_true", dest="syslog",
|
||||||
|
default=False,
|
||||||
|
help="log to syslog")
|
||||||
|
|
||||||
parser.add_option("-f", dest="folders",
|
parser.add_option("-f", dest="folders",
|
||||||
metavar="folder1[,folder2[,...]]",
|
metavar="folder1[,folder2[,...]]",
|
||||||
help="only sync the specified folders")
|
help="only sync the specified folders")
|
||||||
@ -196,6 +201,10 @@ class OfflineImap:
|
|||||||
if options.logfile:
|
if options.logfile:
|
||||||
self.ui.setlogfile(options.logfile)
|
self.ui.setlogfile(options.logfile)
|
||||||
|
|
||||||
|
#set up syslog
|
||||||
|
if options.syslog:
|
||||||
|
self.ui.setup_sysloghandler()
|
||||||
|
|
||||||
#welcome blurb
|
#welcome blurb
|
||||||
self.ui.init_banner()
|
self.ui.init_banner()
|
||||||
|
|
||||||
|
@ -91,6 +91,18 @@ class UIBase(object):
|
|||||||
self.logger.info(offlineimap.banner)
|
self.logger.info(offlineimap.banner)
|
||||||
return ch
|
return ch
|
||||||
|
|
||||||
|
def setup_sysloghandler(self):
|
||||||
|
"""Backend specific syslog handler."""
|
||||||
|
|
||||||
|
# create console handler with a higher log level
|
||||||
|
ch = logging.SysLogHandler(sys.stdout)
|
||||||
|
#ch.setLevel(logging.DEBUG)
|
||||||
|
# create formatter and add it to the handlers
|
||||||
|
self.formatter = logging.Formatter("%(message)s")
|
||||||
|
ch.setFormatter(self.formatter)
|
||||||
|
# add the handlers to the logger
|
||||||
|
self.logger.addHandler(ch)
|
||||||
|
|
||||||
def setlogfile(self, logfile):
|
def setlogfile(self, logfile):
|
||||||
"""Create file handler which logs to file."""
|
"""Create file handler which logs to file."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user