diff options
-rw-r--r-- | LightInstallation.py | 4 | ||||
-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, 0 deletions
diff --git a/LightInstallation.py b/LightInstallation.py index e4adab7..87aa629 100644 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -3,10 +3,13 @@ from pixelcore.Screen import * from pixelcore.PixelStrip import * import pdb, sys, time, Util, thread from pygame.locals import * +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 = Util.Stopwatch() self.timer.start() self.inputs = {} #dict of inputs and their bound behaviors, keyed by InputId @@ -45,6 +48,7 @@ class LightInstallation: self.timer.stop() print 'Initialization done. Time: ', self.timer.elapsed(), 'ms' self.mainLoop() + def initializeMapper(self, mapperConfig): self.mapper = self.initializeComponent(mapperConfig)[0] #TODO: support #multiple mappers 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 |