log.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. #
  3. # This file is part of Radicale Server - Calendar Server
  4. # Copyright © 2011-2012 Guillaume Ayoub
  5. #
  6. # This library is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This library is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Radicale. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. Radicale logging module.
  20. Manage logging from a configuration file. For more information, see:
  21. http://docs.python.org/library/logging.config.html
  22. """
  23. import os
  24. import sys
  25. import logging
  26. import logging.config
  27. from radicale import config
  28. LOGGER = logging.getLogger()
  29. FILENAME = os.path.expanduser(config.get("logging", "config"))
  30. def start():
  31. """Start the logging according to the configuration."""
  32. if os.path.exists(FILENAME):
  33. # Configuration taken from file
  34. logging.config.fileConfig(FILENAME)
  35. else:
  36. # Default configuration, standard output
  37. handler = logging.StreamHandler(sys.stdout)
  38. handler.setFormatter(logging.Formatter("%(message)s"))
  39. LOGGER.addHandler(handler)
  40. if config.getboolean("logging", "debug"):
  41. LOGGER.setLevel(logging.DEBUG)
  42. for handler in LOGGER.handlers:
  43. handler.setLevel(logging.DEBUG)