Split console logging between stdout and stderr

This commit is contained in:
Eric Torres 2019-02-20 02:30:17 -08:00
parent bf2adbd49e
commit cd0bac368a
2 changed files with 22 additions and 10 deletions

View File

@ -31,11 +31,17 @@ console_formatter = logging.Formatter(LOGFORMAT)
syslog = logging.getLogger('packaging_scripts') syslog = logging.getLogger('packaging_scripts')
syslog.setLevel(logging.DEBUG) syslog.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler() stdout_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO) stdout_handler.setLevel(logging.INFO)
console_handler.setFormatter(console_formatter) stdout_handler.setFormatter(console_formatter)
stdout_handler.addFilter(lambda record: record.levelno <= logging.INFO)
syslog.addHandler(console_handler) stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.setLevel(logging.WARNING)
stderr_handler.setFormatter(console_formatter)
syslog.addHandler(stdout_handler)
syslog.addHandler(stderr_handler)
# ========== Functions ========== # ========== Functions ==========
@ -84,7 +90,7 @@ if __name__ == '__main__':
db = f"{cachedir}/{repo}.{DB_EXT}" db = f"{cachedir}/{repo}.{DB_EXT}"
if args.verbose: if args.verbose:
console_handler.setLevel(logging.DEBUG) stdout_handler.setLevel(logging.DEBUG)
if pkgs: if pkgs:
pkg_tarballs = pkgs pkg_tarballs = pkgs

View File

@ -26,11 +26,17 @@ console_formatter = logging.Formatter('==> %(levelname)s %(message)s')
syslog = logging.getLogger('packaging_scripts') syslog = logging.getLogger('packaging_scripts')
syslog.setLevel(logging.DEBUG) syslog.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler() stdout_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.INFO) stdout_handler.setLevel(logging.INFO)
console_handler.setFormatter(console_formatter) stdout_handler.setFormatter(console_formatter)
stdout_handler.addFilter(lambda record: record.levelno <= logging.INFO)
syslog.addHandler(console_handler) stderr_handler = logging.StreamHandler(sys.stderr)
stderr_handler.setLevel(logging.WARNING)
stderr_handler.setFormatter(console_formatter)
syslog.addHandler(stdout_handler)
syslog.addHandler(stderr_handler)
# ========== Functions ========== # ========== Functions ==========
@ -73,7 +79,7 @@ if __name__ == '__main__':
db = f"{cachedir}/{repo}.{DB_EXT}" db = f"{cachedir}/{repo}.{DB_EXT}"
if args.verbose: if args.verbose:
console_handler.setLevel(logging.DEBUG) stdout_handler.setLevel(logging.DEBUG)
for pkg in pkgs: for pkg in pkgs:
pkg_tarballs = pkgfiles.get_pkgfiles(query=pkg, pkg_tarballs = pkgfiles.get_pkgfiles(query=pkg,