您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

66 行
1.6 KiB

  1. from __future__ import unicode_literals
  2. import frappe
  3. import logging
  4. import logging.config
  5. import os
  6. import json
  7. from pprint import pformat
  8. class ContextFilter(logging.Filter):
  9. """
  10. This is a filter which injects request information (if available) into the log.
  11. """
  12. def filter(self, record):
  13. record.form_dict = pformat(getattr(frappe.local, 'form_dict', None))
  14. record.site = getattr(frappe.local, 'site', None)
  15. record.tb = frappe.utils.get_traceback()
  16. return True
  17. def setup_logging():
  18. conf = frappe.get_site_config(sites_path=os.environ.get('SITES_PATH', '.'))
  19. if conf.logging_conf:
  20. logging_conf = conf.logging_conf
  21. else:
  22. logging_conf = {
  23. "version": 1,
  24. "disable_existing_loggers": True,
  25. "filters": {
  26. "context_filter": {
  27. "()": "frappe.setup_logging.ContextFilter"
  28. }
  29. },
  30. "formatters": {
  31. "site_wise": {
  32. "format": "\n%(asctime)s %(message)s \n site: %(site)s\n form: %(form_dict)s\n\n%(tb)s\n--------------"
  33. }
  34. },
  35. "loggers": {
  36. "frappe": {
  37. "level": "INFO",
  38. "propagate": False,
  39. "filters": ["context_filter"],
  40. "handlers": ["request_exception"]
  41. }
  42. },
  43. "handlers": {
  44. "request_exception": {
  45. "level": "ERROR",
  46. "formatter": "site_wise",
  47. "class": "logging.StreamHandler",
  48. }
  49. }
  50. }
  51. if conf.request_exception_log_file:
  52. logging_conf.update({
  53. "handlers": {
  54. "request_exception": {
  55. "level": "ERROR",
  56. "formatter": "site_wise",
  57. "class": "logging.handlers.WatchedFileHandler",
  58. "filename": conf.request_exception_log_file
  59. }
  60. }
  61. })
  62. logging.config.dictConfig(logging_conf)