* 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
+7 -2
View File
@@ -67,11 +67,15 @@ def init(database = True, write = True,
else: else:
ctx.ui = ui ctx.ui = ui
if os.access('/var/log', os.W_OK):
ctx.log = True
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-8s %(message)s', format='%(asctime)s %(levelname)-8s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S', datefmt='%a, %d %b %Y %H:%M:%S',
filename='/var/log/pisi.log', filename='/var/log/pisi.log')
filemode='w') 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,6 +114,7 @@ def init(database = True, write = True,
def finalize(): def finalize():
if ctx.initialized: if ctx.initialized:
if ctx.log:
logging.shutdown() logging.shutdown()
pisi.repodb.finalize() pisi.repodb.finalize()
+4
View File
@@ -75,6 +75,7 @@ class CLI(UI):
def warning(self, msg, verbose = False): def warning(self, msg, verbose = False):
msg = unicode(msg) msg = unicode(msg)
if ctx.log:
logging.warning(msg) 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)
@@ -83,6 +84,7 @@ class CLI(UI):
def error(self, msg): def error(self, msg):
msg = unicode(msg) msg = unicode(msg)
if ctx.log:
logging.error(msg) 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)
@@ -92,6 +94,7 @@ 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)
if ctx.log:
logging.info(msg) logging.info(msg)
self.output(colorize(msg + '\n', 'green')) self.output(colorize(msg + '\n', 'green'))
@@ -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'))
if ctx.log:
logging.info(msg) logging.info(msg)