diff gpp/core/logging.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/core/logging.py	Mon Apr 06 02:43:12 2009 +0000
@@ -0,0 +1,36 @@
+'''This module adds a simple logging facility to the portal.
+Applications can log information to a database table for debugging.
+The logger is similar to the python logging module.
+The verbosity of the logging is controlled via settings.GPP_LOG_LEVEL. 
+'''
+
+from settings import GPP_LOG_LEVEL
+from core.models import DebugLog
+
+DEBUG = 10
+INFO = 20
+WARNING = 30
+ERROR = 40
+CRITICAL = 50
+
+def log(level, msg):
+   if GPP_LOG_LEVEL <= level:
+      log_item = DebugLog()
+      log_item.level = level
+      log_item.msg = msg
+      log_item.save()
+
+def debug(msg):
+   log(DEBUG, msg)
+
+def info(msg):
+   log(INFO, msg)
+
+def warning(msg):
+   log(WARNING, msg)
+
+def error(msg):
+   log(WARNING, msg)
+
+def critical(msg):
+   log(WARNING, msg)