1. Arnaud Grausem
  2. thot

Commits

Arnaud Grausem  committed 2b64fc5

Bug fixed: Bad log level passed to the logging module

  • Participants
  • Parent commits 678d154
  • Branches stable

Comments (0)

Files changed (1)

File thot/log.py

View file
 
 import os
 import logging
-import logging.config
+from logging import handlers
 
 from django.conf import settings
 
-# loggers
-logger = logging.getLogger("ar")
-logger.setLevel(settings.LOG_LEVEL)
+# log level form settings
+log_level = logging.__getattribute__(settings.LOG_LEVEL)
+
+#------------------------------------------------------------------------------#
+# LOGGERS                                                                      #    
+#------------------------------------------------------------------------------#
+
+# default project logger
+logger = logging.getLogger("thot")
+logger.setLevel(log_level)
+
+# timesheet app logger
+timesheet_logger = logging.getLogger("thot.timesheet")
+logger.setLevel(log_level)
+
+# registration  app logger
+registration_logger = logging.getLogger("thot.registration")
+logger.setLevel(log_level)
+
+# report app logger
+report_logger = logging.getLogger("thot.report")
+logger.setLevel(log_level)
 
 # logger for the dajaxice api
 dajax_logger = logging.getLogger("dajaxice.DajaxiceRequest")
-dajax_logger.setLevel(settings.LOG_LEVEL)
+dajax_logger.setLevel(log_level)
 
-# handlers
-rfh = logging.handlers.RotatingFileHandler(settings.LOG_FILE, 1000, 5)
-rfh.setLevel(settings.LOG_LEVEL)
+#------------------------------------------------------------------------------#
+# FORMATTERS                                                                   #
+#------------------------------------------------------------------------------#
+formatter = logging.Formatter(
+    "%(name)s: %(levelname)s %(asctime)s  %(message)s", "%d-%m-%Y %Hh%M"
+)
 
-# formatter
-formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
-
+#------------------------------------------------------------------------------#
+# HANDLERS                                                                     #
+#------------------------------------------------------------------------------#
+rfh = handlers.RotatingFileHandler(
+    settings.LOG_FILE,  
+    maxBytes=1048576, 
+    backupCount=10, 
+    mode='a+'
+)
+rfh.setLevel(log_level)
 rfh.setFormatter(formatter)
 
 logger.addHandler(rfh)
+timesheet_logger.addHandler(rfh)
+report_logger.addHandler(rfh)
+registration_logger.addHandler(rfh)
 dajax_logger.addHandler(rfh)