Add function to provide logged user feedback
authorKlaus Aehlig <aehlig@google.com>
Tue, 12 Jan 2016 14:54:33 +0000 (15:54 +0100)
committerKlaus Aehlig <aehlig@google.com>
Tue, 12 Jan 2016 15:22:17 +0000 (16:22 +0100)
Add a utility function that provides feedback to the
user on stdout that is additionally logged (at INFO level)
in the log file.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/cli.py

index c9ab93d..5e0b68f 100644 (file)
@@ -275,6 +275,7 @@ __all__ = [
   "UsesRPC",
   # Formatting functions
   "ToStderr", "ToStdout",
+  "ToStdoutAndLoginfo",
   "FormatError",
   "FormatQueryResult",
   "FormatParamsDictInfo",
@@ -3826,6 +3827,12 @@ def ToStdout(txt, *args):
   _ToStream(sys.stdout, txt, *args)
 
 
+def ToStdoutAndLoginfo(txt, *args):
+  """Write a message to stdout and additionally log it at INFO level"""
+  ToStdout(txt, *args)
+  logging.info(txt, *args)
+
+
 def ToStderr(txt, *args):
   """Write a message to stderr only, bypassing the logging system