* 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:
ctx.ui = ui
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',
filemode='w')
if os.access('/var/log', os.W_OK):
ctx.log = True
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')
else:
ctx.log = False
# If given define stdout and stderr. Needed by buildfarm currently
# but others can benefit from this too.
@@ -110,7 +114,8 @@ def init(database = True, write = True,
def finalize():
if ctx.initialized:
logging.shutdown()
if ctx.log:
logging.shutdown()
pisi.repodb.finalize()
pisi.installdb.finalize()
+8 -4
View File
@@ -75,7 +75,8 @@ class CLI(UI):
def warning(self, msg, verbose = False):
msg = unicode(msg)
logging.warning(msg)
if ctx.log:
logging.warning(msg)
if ctx.get_option('no_color'):
self.output(_('Warning: ') + msg + '\n', err=True, verbose=verbose)
else:
@@ -83,7 +84,8 @@ class CLI(UI):
def error(self, msg):
msg = unicode(msg)
logging.error(msg)
if ctx.log:
logging.error(msg)
if ctx.get_option('no_color'):
self.output(_('Error: ') + msg + '\n', err=True)
else:
@@ -92,7 +94,8 @@ class CLI(UI):
def action(self, msg, verbose = False):
#TODO: this seems quite redundant?
msg = unicode(msg)
logging.info(msg)
if ctx.log:
logging.info(msg)
self.output(colorize(msg + '\n', 'green'))
def choose(self, msg, opts):
@@ -151,4 +154,5 @@ class CLI(UI):
msg = None
if msg:
self.output(colorize(msg + '\n', 'cyan'))
logging.info(msg)
if ctx.log:
logging.info(msg)