Sandro Bonazzola has uploaded a new change for review. Change subject: log: write only errors on stderr ......................................................................
log: write only errors on stderr Previously the logging system wrote all the messages to the standard error. Now only errors are logged to the standard error, all the other message are logged to standard output. Change-Id: I4e6cde74421c5b513cba0c2b56fa73acfa212e87 Bug-Url: https://bugzilla.redhat.com/1006792 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/__main__.py 1 file changed, 19 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-iso-uploader refs/changes/24/19124/1 diff --git a/src/__main__.py b/src/__main__.py index ca6275f..07229d4 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -58,6 +58,7 @@ PERMS_MASK = '640' PYTHON = '/usr/bin/python' +#{Logging system STREAM_LOG_FORMAT = '%(levelname)s: %(message)s' FILE_LOG_FORMAT = ( '%(asctime)s::' @@ -77,9 +78,16 @@ ) +class NotAnError(logging.Filter): + + def filter(self, entry): + return entry.levelno < logging.ERROR + + def multilog(logger, msg): for line in str(msg).splitlines(): logger(line) +#} def get_from_prompt(msg, default=None, prompter=raw_input): @@ -376,10 +384,17 @@ logging.error("Could not configure file logging: %s" % e) def __log_to_stream(self, level): - sh = logging.StreamHandler() fmt = logging.Formatter(STREAM_LOG_FORMAT) + #Errors should always be there, on stderr + h_err = logging.StreamHandler(sys.stderr) + h_err.setLevel(logging.ERROR) + h_err.setFormatter(fmt) + logging.root.addHandler(h_err) + #Other logs should go to stdout + sh = logging.StreamHandler(sys.stdout) sh.setLevel(level) sh.setFormatter(fmt) + sh.addFilter(NotAnError()) logging.root.addHandler(sh) def __initLogger(self, logLevel=logging.INFO, quiet=None, logFile=None): @@ -387,7 +402,6 @@ Initialize the logger based on information supplied from the command line or configuration file. """ - # If you call basicConfig more than once without removing handlers # it is effectively a noop. In this program it is possible to call # __initLogger more than once as we learn information about what @@ -395,7 +409,7 @@ # command line; hence, we will need to load and unload the handlers # to ensure consistently fomatted output. log = logging.getLogger() - for h in log.handlers: + for h in list(log.handlers): log.removeHandler(h) if quiet: @@ -414,14 +428,13 @@ else: if logFile: # Case: Not quiet and log file supplied. - # Log to both file and - # stdout/stderr + # Log to both file and stdout/stderr self.__log_to_file(logFile, logLevel) self.__log_to_stream(logLevel) else: # Case: Not quiet and no log file supplied. # Log to only stdout/stderr - logging.basicConfig(level=logLevel, format=STREAM_LOG_FORMAT) + self.__log_to_stream(logLevel) class ISOUploader(object): -- To view, visit http://gerrit.ovirt.org/19124 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4e6cde74421c5b513cba0c2b56fa73acfa212e87 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-iso-uploader Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches