summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Mas <lolando@debian.org>2016-01-07 09:03:02 +0100
committerLars Wirzenius <liw@liw.fi>2016-01-08 20:38:47 +0200
commit0b7d3ecfbfda6ab18e87a604d5d3bb5288933b6d (patch)
tree509e75a78eb23c195eb49de0e81267c378e1b483
parent6b11572afcaa1ba9003ee8bf49adb4529e0f1188 (diff)
downloadcliapp-0b7d3ecfbfda6ab18e87a604d5d3bb5288933b6d.tar.gz
Added --log=stderr to log to STDERR
-rw-r--r--NEWS5
-rw-r--r--cliapp/app.py16
-rw-r--r--cliapp/settings.py1
3 files changed, 21 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index bd905dd..bba3b30 100644
--- a/NEWS
+++ b/NEWS
@@ -16,7 +16,7 @@ Bug fix:
for `--foo`) are now sorted after the non-negated ones in manual
pages.
-New feature:
+New features:
* Configuration files may now also be in YAML format, if names with an
`.yaml` suffix.
@@ -24,6 +24,9 @@ New feature:
* If the `python-xdg` library is available, it is used to allow user
to specify locations of XDG Base Directory locations.
+* Log to STDERR support has been added. Use `--log=stderr`. Patch by
+ Roland Mas.
+
Version 1.20150829
------------------
diff --git a/cliapp/app.py b/cliapp/app.py
index cd1b576..494d4b2 100644
--- a/cliapp/app.py
+++ b/cliapp/app.py
@@ -405,6 +405,8 @@ class Application(object):
if self.settings['log'] == 'syslog':
handler = self.setup_logging_handler_for_syslog()
+ elif self.settings['log'] == 'stderr':
+ handler = self.setup_logging_handler_for_stderr()
elif self.settings['log'] and self.settings['log'] != 'none':
handler = self.setup_logging_handler_for_file()
else:
@@ -431,6 +433,20 @@ class Application(object):
fmt = progname + ": %(levelname)s %(message)s"
return logging.Formatter(fmt)
+ def setup_logging_handler_for_stderr(self): # pragma: no cover
+ '''Setup a logging.Handler for logging to stderr.'''
+
+ handler = logging.StreamHandler()
+ formatter = self.setup_logging_formatter_for_stderr()
+ handler.setFormatter(formatter)
+
+ return handler
+
+ def setup_logging_formatter_for_stderr(self): # pragma: no cover
+ '''Setup a logging.Formatter for stderr.'''
+ fmt = "%(levelname)s %(message)s"
+ return logging.Formatter(fmt)
+
def setup_logging_handler_for_file(self): # pragma: no cover
'''Setup a logging handler for logging to a named file.'''
diff --git a/cliapp/settings.py b/cliapp/settings.py
index 969600b..f05f11e 100644
--- a/cliapp/settings.py
+++ b/cliapp/settings.py
@@ -329,6 +329,7 @@ class Settings(object):
self.string(['log'],
'write log entries to FILE (default is to not write log '
'files at all); use "syslog" to log to system log, '
+ '"stderr" to log to the standard error output, '
'or "none" to disable logging',
metavar='FILE', group=log_group_name)
self.choice(['log-level'],