diff options
-rw-r--r-- | LightInstallation.py | 5 | ||||
-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 |
5 files changed, 93 insertions, 1 deletions
diff --git a/LightInstallation.py b/LightInstallation.py index 6546f7e..5882806 100644 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -6,10 +6,13 @@ from pygame.locals import * import util.TimeOps as clock import util.Config as configGetter import util.ComponentRegistry as compReg +from logger import main_log #Python class to instantiate and drive a Screen through different patterns, #and effects. class LightInstallation: def __init__(self, configFileName): + main_log.critical("hi russell, i'm sending info to the log files") + main_log.critical("initializing based on file: " + str(configFileName)) self.timer = clock.Stopwatch() self.timer.start() self.inputs = {} #dict of inputs and their bound behaviors, keyed by InputId @@ -54,7 +57,7 @@ class LightInstallation: componentToMap = compReg.getComponent(defaults[defaultSelection]) compReg.registerComponent(compReg.getComponent(defaults[defaultSelection]),\ 'Default'+defaultSelection) - + def initializeMapper(self, mapperConfig): self.mappers = self.initializeComponent(mapperConfig) def initializeScreen(self, layoutConfig): diff --git a/logger/Logger.py b/logger/Logger.py new file mode 100644 index 0000000..7115e47 --- /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 hello") + 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 |