[autotest] Record log for abort_suite
Currently, it's impossible to debug whether a suite is aborted
by builder or by lab bug.
Record log in abort_suite module so that we can track back when
a suite is aborted via the module.
BUG=chromium:440905
TEST=./site_utils/abort_suite.py -s dummy -i nyan_big-release/R38-6029.0.0
Change-Id: Ief636ebe547b47db4b563b81edb9147acf1afea4
Reviewed-on: https://chromium-review.googlesource.com/234436
Reviewed-by: Fang Deng <fdeng@chromium.org>
Tested-by: Mungyung Ryu <mkryu@google.com>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
diff --git a/server/site_utils.py b/server/site_utils.py
index 22479e9..c49030e 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -393,3 +393,29 @@
}
return ('%(prefix)s.%(board)s.%(build_type)s.%(branch)s.%(suite)s'
% data_key_dict)
+
+
+def setup_logging(logfile=None):
+ """Setup basic logging with all logging info stripped.
+
+ Calls to logging will only show the message. No severity is logged.
+
+ @param logfile: If specified dump output to a file as well.
+ """
+ # Remove all existing handlers. client/common_lib/logging_config adds
+ # a StreamHandler to logger when modules are imported, e.g.,
+ # autotest_lib.client.bin.utils. A new StreamHandler will be added here to
+ # log only messages, not severity.
+ logging.getLogger().handlers = []
+
+ screen_handler = logging.StreamHandler()
+ screen_handler.setFormatter(logging.Formatter('%(asctime)s '
+ '%(levelname)-5s| %(message)s'))
+ logging.getLogger().addHandler(screen_handler)
+ logging.getLogger().setLevel(logging.INFO)
+ if logfile:
+ file_handler = logging.FileHandler(logfile)
+ file_handler.setFormatter(logging.Formatter('%(asctime)s '
+ '%(levelname)-5s| %(message)s'))
+ file_handler.setLevel(logging.DEBUG)
+ logging.getLogger().addHandler(file_handler)