Move check partition size logs to a file
Don't contaminate the build log.
Test: m check-all-partition-sizes -j (verbose logs stored to file)
Test: m check-all-partition-sizes-nodeps -j (see verbose logs)
Test: manually run the script with[out] -v and with[out] --logfile
Change-Id: I345a340deab3e29bb9cb05d4970a55d8758607a7
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 031db1d..ffcd748 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -87,6 +87,7 @@
# Stash size cannot exceed cache_size * threshold.
self.cache_size = None
self.stash_threshold = 0.8
+ self.logfile = None
OPTIONS = Options()
@@ -158,13 +159,14 @@
'default': {
'class': 'logging.StreamHandler',
'formatter': 'standard',
+ 'level': 'WARNING',
},
},
'loggers': {
'': {
'handlers': ['default'],
- 'level': 'WARNING',
'propagate': True,
+ 'level': 'INFO',
}
}
}
@@ -177,8 +179,19 @@
# Increase the logging level for verbose mode.
if OPTIONS.verbose:
- config = copy.deepcopy(DEFAULT_LOGGING_CONFIG)
- config['loggers']['']['level'] = 'INFO'
+ config = copy.deepcopy(config)
+ config['handlers']['default']['level'] = 'INFO'
+
+ if OPTIONS.logfile:
+ config = copy.deepcopy(config)
+ config['handlers']['logfile'] = {
+ 'class': 'logging.FileHandler',
+ 'formatter': 'standard',
+ 'level': 'INFO',
+ 'mode': 'w',
+ 'filename': OPTIONS.logfile,
+ }
+ config['loggers']['']['handlers'].append('logfile')
logging.config.dictConfig(config)
@@ -1797,6 +1810,9 @@
-h (--help)
Display this usage message and exit.
+
+ --logfile <file>
+ Put verbose logs to specified file (regardless of --verbose option.)
"""
def Usage(docstring):
@@ -1822,7 +1838,7 @@
"java_path=", "java_args=", "public_key_suffix=",
"private_key_suffix=", "boot_signer_path=", "boot_signer_args=",
"verity_signer_path=", "verity_signer_args=", "device_specific=",
- "extra="] +
+ "extra=", "logfile="] +
list(extra_long_opts))
except getopt.GetoptError as err:
Usage(docstring)
@@ -1864,6 +1880,8 @@
elif o in ("-x", "--extra"):
key, value = a.split("=", 1)
OPTIONS.extras[key] = value
+ elif o in ("--logfile",):
+ OPTIONS.logfile = a
else:
if extra_option_handler is None or not extra_option_handler(o, a):
assert False, "unknown option \"%s\"" % (o,)