* fix: don't use basicconfig, instantiate handler manually, this

becomes re-entrant now, and works with build farm, but downside:
  info messages don't show up!
This commit is contained in:
Eray Özkural
2006-05-03 20:33:27 +00:00
parent b72eac4b6b
commit fdb34a98c1
2 changed files with 13 additions and 14 deletions
+9 -10
View File
@@ -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:
+4 -4
View File
@@ -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)