diff options
author | Thomas B Thompson <tbent@spice.(none)> | 2010-12-24 03:18:43 -0500 |
---|---|---|
committer | Thomas B Thompson <tbent@spice.(none)> | 2010-12-24 03:23:26 -0500 |
commit | 64eafb98f988818de423e91f662817cf2b94942f (patch) | |
tree | 5ce876dc64131cf0fc405a0d0bd1f1027b57d9fe /logger | |
parent | 8cecf83f16fcdec5b3ee68cc40c2b360e0f845d0 (diff) |
done with logging stuff -- pretty simple, just need to import from logger module and then run something like "main_log.debug("text")"
Diffstat (limited to 'logger')
-rw-r--r-- | logger/Logger.py | 19 | ||||
-rw-r--r-- | logger/UTF8LogFormatter.py | 8 | ||||
-rw-r--r-- | logger/__init__.py | 1 | ||||
-rw-r--r-- | logger/loggingConfig.ini | 61 |
4 files changed, 89 insertions, 0 deletions
diff --git a/logger/Logger.py b/logger/Logger.py new file mode 100644 index 0000000..9c8598f --- /dev/null +++ b/logger/Logger.py @@ -0,0 +1,19 @@ +import logging +import logging.config + +logging.config.fileConfig("logger/loggingConfig.ini") + +# create logger +screen_log = logging.getLogger("root") +main_log = logging.getLogger("smoot_light") +exception_log = logging.getLogger("exception") + +#test code -- won't work unless file is imported by a file from the directory above this "logger" directory +#main_log.debug("debug mesage") +#main_log.info("info message") +#main_log.warn("warn message") +#main_log.error("error message") +#main_log.critical("critical message") +#exception_log.critical("hi") +#screen_log.error("whoa") + diff --git a/logger/UTF8LogFormatter.py b/logger/UTF8LogFormatter.py new file mode 100644 index 0000000..2d3fae5 --- /dev/null +++ b/logger/UTF8LogFormatter.py @@ -0,0 +1,8 @@ +from logging import Formatter + +class UTF8LogFormatter(Formatter): + def format(self, record): + try: + return Formatter.format(self, record) + except Exception, e: + return Formatter.format(self, record).encode('utf8') diff --git a/logger/__init__.py b/logger/__init__.py new file mode 100644 index 0000000..ff356f4 --- /dev/null +++ b/logger/__init__.py @@ -0,0 +1 @@ +from Logger import screen_log, main_log, exception_log diff --git a/logger/loggingConfig.ini b/logger/loggingConfig.ini new file mode 100644 index 0000000..ee35749 --- /dev/null +++ b/logger/loggingConfig.ini @@ -0,0 +1,61 @@ +# Logging configuration +# Add additional loggers, handlers, formatters here +# Uses pythons logging config file format +# http://docs.python.org/lib/logging-config-fileformat.html +[loggers] +keys = root, smoot_light, exception + +[handlers] +keys = console, file, exception + +[formatters] +keys = generic, utf8encode + +#################################################################### + +[logger_root] +level = INFO +handlers = console + +[logger_smoot_light] +level = INFO +handlers = file +qualname = smoot_light +propagate = 0 + +[logger_exception] +level = DEBUG +handlers = exception +qualname = exception +propagate = 0 + +#################################################################### + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[handler_file] +class = FileHandler +args = ('/var/log/smoot_light/main.log', 'a') +level = INFO +formatter = generic + +[handler_exception] +class = FileHandler +args = ('/var/log/smoot_light/exception.log', 'a') +level = DEBUG +formatter = utf8encode + +#################################################################### + +[formatter_generic] +format = %(asctime)s %(levelname)-8s [%(name)s] %(message)s +#datefmt = %H:%M:%S + +[formatter_utf8encode] +format = %(asctime)s %(levelname)-8s [%(name)s] %(message)s +class = logger.UTF8LogFormatter.UTF8LogFormatter +#datefmt = %H:%M:%S |