* fix: log to /var/log/ only if we have permission to write (not like syslog)

This commit is contained in:
Eray Özkural
2006-05-02 16:31:15 +00:00
parent ecdc8e7010
commit 65ba0dcf99
2 changed files with 19 additions and 10 deletions
+11 -6
View File
@@ -67,11 +67,15 @@ def init(database = True, write = True,
else: else:
ctx.ui = ui ctx.ui = ui
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s', if os.access('/var/log', os.W_OK):
datefmt='%a, %d %b %Y %H:%M:%S', ctx.log = True
filename='/var/log/pisi.log', logging.basicConfig(level=logging.DEBUG,
filemode='w') format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename='/var/log/pisi.log')
else:
ctx.log = False
# If given define stdout and stderr. Needed by buildfarm currently # If given define stdout and stderr. Needed by buildfarm currently
# but others can benefit from this too. # but others can benefit from this too.
@@ -110,7 +114,8 @@ def init(database = True, write = True,
def finalize(): def finalize():
if ctx.initialized: if ctx.initialized:
logging.shutdown() if ctx.log:
logging.shutdown()
pisi.repodb.finalize() pisi.repodb.finalize()
pisi.installdb.finalize() pisi.installdb.finalize()
+8 -4
View File
@@ -75,7 +75,8 @@ class CLI(UI):
def warning(self, msg, verbose = False): def warning(self, msg, verbose = False):
msg = unicode(msg) msg = unicode(msg)
logging.warning(msg) if ctx.log:
logging.warning(msg)
if ctx.get_option('no_color'): if ctx.get_option('no_color'):
self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose) self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose)
else: else:
@@ -83,7 +84,8 @@ class CLI(UI):
def error(self, msg): def error(self, msg):
msg = unicode(msg) msg = unicode(msg)
logging.error(msg) if ctx.log:
logging.error(msg)
if ctx.get_option('no_color'): if ctx.get_option('no_color'):
self.output(_('Error: ') + msg + '\n', err=True) self.output(_('Error: ') + msg + '\n', err=True)
else: else:
@@ -92,7 +94,8 @@ class CLI(UI):
def action(self, msg, verbose = False): def action(self, msg, verbose = False):
#TODO: this seems quite redundant? #TODO: this seems quite redundant?
msg = unicode(msg) msg = unicode(msg)
logging.info(msg) if ctx.log:
logging.info(msg)
self.output(colorize(msg + '\n', 'green')) self.output(colorize(msg + '\n', 'green'))
def choose(self, msg, opts): def choose(self, msg, opts):
@@ -151,4 +154,5 @@ class CLI(UI):
msg = None msg = None
if msg: if msg:
self.output(colorize(msg + '\n', 'cyan')) self.output(colorize(msg + '\n', 'cyan'))
logging.info(msg) if ctx.log:
logging.info(msg)