Changeset a9eb577e


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

Location:
server/lib
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • server/lib/gutenbach-config

    r609a9b0 ra9eb577e  
    11port: 8000
    2 loglevel: info
     2loglevel: debug
     3logfile: gutenbach.log
    34
    45printers:
  • server/lib/gutenbach-server.py

    • Property mode changed from 100644 to 100755
    r609a9b0 ra9eb577e  
     1#!/usr/bin/python
     2
    13import gutenbach.server
    24import sys
  • 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())
  • server/lib/gutenbach/server/player.py

    rc94fa32 ra9eb577e  
    6767            self._done = False
    6868
    69         command = "/usr/bin/mplayer -really-quiet -slave".split()+[self.fh.name]
    70         logger.info("Running %r", command)
     69        command = ["mplayer", "-really-quiet", "-slave", self.fh.name]
     70        logger.info("running '%s'", " ".join(command))
    7171
    7272        if self._dryrun:
     
    7979
    8080        else:
    81             # open mplayer
    82 
    8381            with self.lock:
    8482                self.player = subprocess.Popen(
Note: See TracChangeset for help on using the changeset viewer.