A Python content management system designed for kirsle.net featuring a blog, comments and photo albums. https://rophako.kirsle.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

log.py 773B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals, print_function, absolute_import
  3. """Debug and logging functions."""
  4. import logging
  5. from rophako.settings import Config
  6. class LogHandler(logging.Handler):
  7. """A custom logging handler."""
  8. def emit(self, record):
  9. # The initial log line, which has the $prefix$ in it.
  10. line = self.format(record)
  11. line = line.replace('$prefix$', '')
  12. print(line)
  13. # Set up the logger.
  14. logger = logging.getLogger("rophako")
  15. handler = LogHandler()
  16. handler.setFormatter(logging.Formatter("[%(asctime)s] [%(levelname)s] $prefix$%(message)s"))
  17. logger.addHandler(handler)
  18. # Log level.
  19. if Config.site.debug == "true":
  20. logger.setLevel(logging.DEBUG)
  21. else:
  22. logger.setLevel(logging.INFO)