Noninteractive.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Noninteractive UI
  2. # Copyright (C) 2002-2016 John Goerzen & contributors.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. import logging
  18. import offlineimap
  19. from offlineimap.ui.UIBase import UIBase
  20. class Basic(UIBase):
  21. """'Basic' simply sets log level to INFO."""
  22. def __init__(self, config, loglevel = logging.INFO):
  23. return super(Basic, self).__init__(config, loglevel)
  24. class Quiet(UIBase):
  25. """'Quiet' simply sets log level to WARNING"""
  26. def __init__(self, config, loglevel = logging.WARNING):
  27. return super(Quiet, self).__init__(config, loglevel)
  28. class Syslog(UIBase):
  29. """'Syslog' sets log level to INFO and outputs to syslog instead of stdout"""
  30. def __init__(self, config, loglevel = logging.INFO):
  31. return super(Syslog, self).__init__(config, loglevel)
  32. def setup_consolehandler(self):
  33. # create syslog handler
  34. ch = logging.handlers.SysLogHandler('/dev/log')
  35. # create formatter and add it to the handlers
  36. self.formatter = logging.Formatter("%(message)s")
  37. ch.setFormatter(self.formatter)
  38. # add the handlers to the logger
  39. self.logger.addHandler(ch)
  40. self.logger.info(offlineimap.banner)
  41. return ch
  42. def setup_sysloghandler(self):
  43. pass # Do not honor -s (log to syslog) CLI option.