Skip to content

Commit

Permalink
logging: add a switch to log to syslog
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
  • Loading branch information
mathstuf committed Sep 27, 2015
1 parent ca1ce25 commit 45852ba
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/offlineimap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ included), implies the single-thread option -1.

Send logs to <file.log>.

-s::

Send logs to syslog.


-f <folder1[,folder1[,...]]>::

Expand Down
9 changes: 9 additions & 0 deletions offlineimap/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def __parse_cmd_options(self):
parser.add_option("-l", dest="logfile", metavar="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",
metavar="folder1[,folder2[,...]]",
help="only sync the specified folders")
Expand Down Expand Up @@ -196,6 +201,10 @@ def __parse_cmd_options(self):
if options.logfile:
self.ui.setlogfile(options.logfile)

#set up syslog
if options.syslog:
self.ui.setup_sysloghandler()

#welcome blurb
self.ui.init_banner()

Expand Down
12 changes: 12 additions & 0 deletions offlineimap/ui/UIBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ def setup_consolehandler(self):
self.logger.info(offlineimap.banner)
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):
"""Create file handler which logs to file."""

Expand Down

0 comments on commit 45852ba

Please sign in to comment.