Skip to content
Snippets Groups Projects
Commit dc93a8fa authored by Hans Fangohr's avatar Hans Fangohr
Browse files

improve logging formatting

parent 929eab21
No related branches found
No related tags found
1 merge request!22Introduce logging module
......@@ -12,6 +12,7 @@ import time
from pathlib import Path
from typing import List, Tuple
about_tool = """
Build toolchains using Spack.\n
......@@ -50,20 +51,19 @@ def set_up_logging(loglevel="warning", filename="test.log"):
assert log_level_numeric
if not isinstance(log_level_numeric, int):
raise ValueError("Invalid log level: %s" % loglevel)
if log_level_numeric == logging.DEBUG:
linenumbers = "%(lineno)d:"
else:
linenumbers = ""
formatstring = "%(asctime)s:%(levelname)s:" + linenumbers + "%(message)s"
handlers = [logging.StreamHandler(sys.stdout)]
handlers = []
if filename:
handlers.append(logging.FileHandler(filename))
# set up logging
handlers.append(logging.StreamHandler())
if log_level_numeric == logging.DEBUG:
linenumbers = " %(lineno)4d"
else:
linenumbers = ""
logging.basicConfig(
format=formatstring,
datefmt="%H:%M:%S",
format="%(asctime)s %(levelname)7s" + linenumbers + " | %(message)s",
datefmt="[%X]",
level=log_level_numeric,
handlers=handlers,
force=True,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment