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.

Also addresses minor pep8 issues preventing make check
to exit with success.

Bug-Url: https://bugzilla.redhat.com/956518
Change-Id: Iee176b539dc7bcecc64b26e3c05db7c8a7ee86d6
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M src/__main__.py
M src/config.py.in.in
2 files changed, 29 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/95/19195/1

diff --git a/src/__main__.py b/src/__main__.py
index 78e4e4b..017375f 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -41,7 +41,13 @@
 from ovirt_log_collector import config
 from ovirt_log_collector import util
 
+DEFAULT_SSH_USER = 'root'
+DEFAULT_TIME_SHIFT_FILE = 'time_diff.txt'
+PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
+DEFAULT_SCRATCH_DIR = None  # Will be initialized by __main__
+SSH_SERVER_ALIVE_INTERVAL = 600
 
+#{Logging system
 STREAM_LOG_FORMAT = '%(levelname)s: %(message)s'
 FILE_LOG_FORMAT = (
     '%(asctime)s::'
@@ -60,11 +66,13 @@
     )
 )
 
-DEFAULT_SSH_USER = 'root'
-DEFAULT_TIME_SHIFT_FILE = 'time_diff.txt'
-PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
-DEFAULT_SCRATCH_DIR = None  # Will be initialized by __main__
-SSH_SERVER_ALIVE_INTERVAL = 600
+
+class NotAnError(logging.Filter):
+
+    def filter(self, entry):
+        return entry.levelno < logging.ERROR
+#}
+
 
 # Default DB connection params
 pg_user = 'postgres'
@@ -274,6 +282,7 @@
             parser.error(
                 _('Options --quiet and --verbose are mutually exclusive')
             )
+
         if self.options.log_file or self.options.quiet:
             level = logging.INFO
             if self.options.verbose:
@@ -422,10 +431,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):
@@ -440,7 +456,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:
@@ -465,7 +481,7 @@
             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 CollectorBase(object):
@@ -920,10 +936,10 @@
             self.conf["path"] = os.path.join(
                 self.conf["output"],
                 "sosreport-%s-%s-%s.tar.%s" % (
-                'LogCollector',
-                self.conf["ticket_number"],
-                time.strftime("%Y%m%d%H%M%S"),
-                report_file_ext
+                    'LogCollector',
+                    self.conf["ticket_number"],
+                    time.strftime("%Y%m%d%H%M%S"),
+                    report_file_ext
                 )
             )
 
diff --git a/src/config.py.in.in b/src/config.py.in.in
index 64a6d8b..0548fdd 100644
--- a/src/config.py.in.in
+++ b/src/config.py.in.in
@@ -14,7 +14,7 @@
 DEFAULT_CA_PEM = "@sysconfdir_POST@/pki/ovirt-engine/ca.pem"
 DEFAULT_SSH_KEY = "@sysconfdir_POST@/pki/ovirt-engine/keys/engine_id_rsa"
 DEFAULT_CONFIGURATION_FILE = "@engineconfigdir_POST@/logcollector.conf"
-DEFAULT_LOG_DIR =  os.path.join(
+DEFAULT_LOG_DIR = os.path.join(
     '@localstatedir_POST@',
     'log',
     'ovirt-engine',


-- 
To view, visit http://gerrit.ovirt.org/19195
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee176b539dc7bcecc64b26e3c05db7c8a7ee86d6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.3
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to