Ignore:
Timestamp:
Jan 12, 2012, 5:37:11 PM (12 years ago)
Author:
Jessica B. Hamrick <jhamrick@…>
Branches:
no-cups
Children:
d17381b, c500bc2, 8d89b3d
Parents:
d994f15
git-author:
Jessica B. Hamrick <jhamrick@…> (01/12/12 17:37:11)
git-committer:
Jessica B. Hamrick <jhamrick@…> (01/12/12 17:37:11)
Message:

Add logging configuration option

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach/server/__init__.py

    r609a9b0 ra9eb577e  
    2121import sys
    2222import traceback
     23import os
     24import shutil
    2325
    2426# configure and initialize logging
     
    3032    sys.exit(1)
    3133
     34def new_logfile(logfile):
     35    if os.path.exists(logfile):
     36        pth = os.path.abspath(os.path.dirname(logfile))
     37        filename = os.path.basename(logfile)
     38        logfiles = [f for f in os.listdir(pth) if f.startswith(filename + ".")]
     39        lognums = [0]
     40        for f in logfiles:
     41            try:
     42                lognums.append(int(f.lstrip(filename + ".")))
     43            except TypeError:
     44                pass
     45        nextnum = max(lognums) + 1
     46        shutil.move(logfile, os.path.join(pth, "%s.%d" % (filename, nextnum)))
     47
    3248def start(config):
    3349    global logger
    34     loglevel_num = getattr(logging, config['loglevel'].upper())
    35     logging.basicConfig(level=loglevel_num)
    36     logger = logging.getLogger(__name__)   
     50    logkwargs = {}
     51    logkwargs['level'] = getattr(logging, config['loglevel'].upper())
     52    if 'logfile' in config:
     53        logkwargs['filename'] = config['logfile']
     54        new_logfile(config['logfile'])           
     55    logging.basicConfig(**logkwargs)
     56    logger = logging.getLogger(__name__)
     57   
    3758    logger.info("Starting Gutenbach server...")
    3859    printers = sorted(config['printers'].keys())
Note: See TracChangeset for help on using the changeset viewer.