diff --git a/pisi/api.py b/pisi/api.py index 4be02397..ae4f87c7 100644 --- a/pisi/api.py +++ b/pisi/api.py @@ -17,6 +17,7 @@ import os import sys import logging +import logging.handlers from os.path import exists import bsddb3.db as db @@ -67,17 +68,15 @@ def init(database = True, write = True, else: ctx.ui = ui - if os.access('/var/log', os.W_OK): - # FIXME: Breaks buildfarm - #ctx.log = True - ctx.log = False - logging.basicConfig(level=logging.DEBUG, - format='%(asctime)s %(levelname)-8s %(message)s', - datefmt='%a, %d %b %Y %H:%M:%S', - filename='/var/log/pisi.log') + handler = logging.handlers.RotatingFileHandler('/var/log/pisi.log') + handler.setLevel(logging.DEBUG) + formatter = logging.Formatter('%(asctime)-12s: %(levelname)-8s %(message)s') + handler.setFormatter(formatter) + ctx.log = logging.getLogger('pisi') + ctx.log.addHandler(handler) else: - ctx.log = False + ctx.log = None # If given define stdout and stderr. Needed by buildfarm currently # but others can benefit from this too. @@ -118,7 +117,7 @@ def finalize(): if ctx.log: logging.shutdown() - + pisi.repodb.finalize() pisi.installdb.finalize() if ctx.filesdb != None: diff --git a/pisi/cli/__init__.py b/pisi/cli/__init__.py index 5e737ff2..eb7f7163 100644 --- a/pisi/cli/__init__.py +++ b/pisi/cli/__init__.py @@ -76,7 +76,7 @@ class CLI(UI): def warning(self, msg, verbose = False): msg = unicode(msg) if ctx.log: - logging.warning(msg) + ctx.log.warning(msg) if ctx.get_option('no_color'): self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose) else: @@ -85,7 +85,7 @@ class CLI(UI): def error(self, msg): msg = unicode(msg) if ctx.log: - logging.error(msg) + ctx.log.error(msg) if ctx.get_option('no_color'): self.output(_('Error: ') + msg + '\n', err=True) else: @@ -95,7 +95,7 @@ class CLI(UI): #TODO: this seems quite redundant? msg = unicode(msg) if ctx.log: - logging.info(msg) + ctx.log.info(msg) self.output(colorize(msg + '\n', 'green')) def choose(self, msg, opts): @@ -155,4 +155,4 @@ class CLI(UI): if msg: self.output(colorize(msg + '\n', 'cyan')) if ctx.log: - logging.info(msg) + ctx.log.info(msg)