Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: acc98c1a0bdf
Choose a base ref
...
head repository: GlasgowEmbedded/glasgow
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: db3240872645
Choose a head ref
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jul 25, 2019

  1. Copy the full SHA
    db32408 View commit details
Showing with 22 additions and 10 deletions.
  1. +22 −10 software/glasgow/cli.py
32 changes: 22 additions & 10 deletions software/glasgow/cli.py
Original file line number Diff line number Diff line change
@@ -70,6 +70,9 @@ def create_argparser():
parser.add_argument(
"-q", "--quiet", default=0, action="count",
help="decrease logging verbosity")
parser.add_argument(
"-L", "--log-file", metavar="FILE", type=argparse.FileType("w"),
help="save log messages at highest verbosity to FILE")
parser.add_argument(
"-F", "--filter-log", metavar="FILTER", type=str, action="append",
help="raise TRACE log messages to DEBUG if they begin with 'FILTER: '")
@@ -307,7 +310,7 @@ def _applet(revision, args):
return target, applet


class ANSIColorFormatter(logging.Formatter):
class TerminalFormatter(logging.Formatter):
LOG_COLORS = {
"TRACE" : "\033[37m",
"DEBUG" : "\033[36m",
@@ -329,7 +332,7 @@ def format(self, record):
class SubjectFilter:
def __init__(self, level, subjects):
self.level = level
self.subjects = subjects
self.subjects = subjects or ()

def filter(self, record):
levelno = record.levelno
@@ -340,22 +343,31 @@ def filter(self, record):


def create_logger(args):
formatter_args = {"fmt": "{levelname[0]:s}: {name:s}: {message:s}", "style": "{"}
handler = logging.StreamHandler()
root_logger = logging.getLogger()

term_formatter_args = {"style": "{",
"fmt": "{levelname[0]:s}: {name:s}: {message:s}"}
term_handler = logging.StreamHandler()
if sys.stderr.isatty() and sys.platform != 'win32':
handler.setFormatter(ANSIColorFormatter(**formatter_args))
term_handler.setFormatter(TerminalFormatter(**term_formatter_args))
else:
handler.setFormatter(logging.Formatter(**formatter_args))
term_handler.setFormatter(logging.Formatter(**term_formatter_args))
root_logger.addHandler(term_handler)

root_logger = logging.getLogger()
root_logger.addHandler(handler)
file_formatter_args = {"style": "{",
"fmt": "[{asctime:s}] {levelname:s}: {name:s}: {message:s}"}
file_handler = None
if args.log_file:
file_handler = logging.StreamHandler(args.log_file)
file_handler.setFormatter(logging.Formatter(**file_formatter_args))
root_logger.addHandler(file_handler)

level = logging.INFO + args.quiet * 10 - args.verbose * 10
if level < 0:
dump_hex.limit = 0

if args.filter_log:
handler.addFilter(SubjectFilter(level, args.filter_log))
if args.log_file or args.filter_log:
term_handler.addFilter(SubjectFilter(level, args.filter_log))
root_logger.setLevel(logging.TRACE)
else:
# By setting the log level on the root logger, we avoid creating LogRecords in the first