UIBase: add a syslog ui
Rather than having an option for syslog output, make a separate UI option. Signed-off-by: Ben Boeckel <mathstuf@gmail.com> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:

committed by
Nicolas Sebrecht

parent
3daddb9b33
commit
e18428b25b
@ -115,7 +115,7 @@ class OfflineImap:
|
||||
|
||||
parser.add_option("-u", dest="interface",
|
||||
help="specifies an alternative user interface"
|
||||
" (quiet, basic, ttyui, blinkenlights, machineui)")
|
||||
" (quiet, basic, syslog, ttyui, blinkenlights, machineui)")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
globals.set_options (options)
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import logging
|
||||
from offlineimap.ui.UIBase import UIBase
|
||||
import offlineimap
|
||||
|
||||
class Basic(UIBase):
|
||||
"""'Basic' simply sets log level to INFO"""
|
||||
@ -27,3 +28,22 @@ class Quiet(UIBase):
|
||||
"""'Quiet' simply sets log level to WARNING"""
|
||||
def __init__(self, config, loglevel = logging.WARNING):
|
||||
return super(Quiet, self).__init__(config, loglevel)
|
||||
|
||||
class Syslog(UIBase):
|
||||
"""'Syslog' sets log level to INFO and outputs to syslog instead of stdout"""
|
||||
def __init__(self, config, loglevel = logging.INFO):
|
||||
return super(Syslog, self).__init__(config, loglevel)
|
||||
|
||||
def setup_consolehandler(self):
|
||||
# create syslog handler
|
||||
ch = logging.handlers.SysLogHandler('/dev/log')
|
||||
# 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)
|
||||
self.logger.info(offlineimap.banner)
|
||||
return ch
|
||||
|
||||
def setup_sysloghandler(self):
|
||||
pass
|
||||
|
@ -16,6 +16,7 @@
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
import logging
|
||||
import logging.handlers
|
||||
import re
|
||||
import time
|
||||
import sys
|
||||
@ -94,9 +95,8 @@ class UIBase(object):
|
||||
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 syslog handler
|
||||
ch = logging.handlers.SysLogHandler('/dev/log')
|
||||
# create formatter and add it to the handlers
|
||||
self.formatter = logging.Formatter("%(message)s")
|
||||
ch.setFormatter(self.formatter)
|
||||
|
@ -21,6 +21,7 @@ from offlineimap.ui import TTY, Noninteractive, Machine
|
||||
UI_LIST = {'ttyui': TTY.TTYUI,
|
||||
'basic': Noninteractive.Basic,
|
||||
'quiet': Noninteractive.Quiet,
|
||||
'syslog': Noninteractive.Syslog,
|
||||
'machineui': Machine.MachineUI}
|
||||
|
||||
#add Blinkenlights UI if it imports correctly (curses installed)
|
||||
|
Reference in New Issue
Block a user