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 868B

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