Logging prettified
This commit is contained in:
@@ -9,7 +9,7 @@ except DistributionNotFound:
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
import multiprocessing as mp
|
import multiprocessing as mp
|
||||||
import logging
|
import logging, logging.handlers
|
||||||
|
|
||||||
from . import camera, gui
|
from . import camera, gui
|
||||||
from .Config import Config
|
from .Config import Config
|
||||||
@@ -135,14 +135,30 @@ def run(argv):
|
|||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
|
||||||
logging.basicConfig(filename='photobooth.log', level=logging.INFO)
|
# Setup log level and format
|
||||||
logging.getLogger().addHandler(logging.StreamHandler())
|
log_level = logging.INFO
|
||||||
|
formatter = logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
|
# create console handler and set format
|
||||||
|
ch = logging.StreamHandler()
|
||||||
|
ch.setFormatter(formatter)
|
||||||
|
|
||||||
|
# create file handler and set format
|
||||||
|
fh = logging.handlers.TimedRotatingFileHandler('photobooth.log',
|
||||||
|
when='d', interval=1, backupCount=10)
|
||||||
|
fh.setFormatter(formatter)
|
||||||
|
|
||||||
|
# Apply config
|
||||||
|
logging.basicConfig(level=log_level, handlers=(ch,fh))
|
||||||
|
|
||||||
|
# Set of known status codes which trigger a restart of the application
|
||||||
known_status_codes = {
|
known_status_codes = {
|
||||||
999: 'Initializing photobooth',
|
999: 'Initializing photobooth',
|
||||||
123: 'Restarting photobooth and reloading config'
|
123: 'Restarting photobooth and reloading config'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Run the application until a status code not in above list is encountered
|
||||||
status_code = 999
|
status_code = 999
|
||||||
|
|
||||||
while status_code in known_status_codes:
|
while status_code in known_status_codes:
|
||||||
|
|||||||
Reference in New Issue
Block a user