From 5683eb8ef0426fee1abb7d11c3b690e802904538 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 8 Mar 2023 14:22:23 -0500 Subject: [PATCH] Doc string and types bump in loggin mod --- piker/log.py | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/piker/log.py b/piker/log.py index 804e09dc..a36beec0 100644 --- a/piker/log.py +++ b/piker/log.py @@ -21,7 +21,11 @@ import logging import json import tractor -from pygments import highlight, lexers, formatters +from pygments import ( + highlight, + lexers, + formatters, +) # Makes it so we only see the full module name when using ``__name__`` # without the extra "piker." prefix. @@ -32,26 +36,48 @@ def get_logger( name: str = None, ) -> logging.Logger: - '''Return the package log or a sub-log for `name` if provided. + ''' + Return the package log or a sub-log for `name` if provided. + ''' return tractor.log.get_logger(name=name, _root_name=_proj_name) -def get_console_log(level: str = None, name: str = None) -> logging.Logger: - '''Get the package logger and enable a handler which writes to stderr. +def get_console_log( + level: str | None = None, + name: str | None = None, + +) -> logging.Logger: + ''' + Get the package logger and enable a handler which writes to stderr. Yeah yeah, i know we can use ``DictConfig``. You do it... + ''' return tractor.log.get_console_log( - level, name=name, _root_name=_proj_name) # our root logger + level, + name=name, + _root_name=_proj_name, + ) # our root logger -def colorize_json(data, style='algol_nu'): - """Colorize json output using ``pygments``. - """ - formatted_json = json.dumps(data, sort_keys=True, indent=4) +def colorize_json( + data: dict, + style='algol_nu', +): + ''' + Colorize json output using ``pygments``. + + ''' + formatted_json = json.dumps( + data, + sort_keys=True, + indent=4, + ) return highlight( - formatted_json, lexers.JsonLexer(), + formatted_json, + lexers.JsonLexer(), + # likeable styles: algol_nu, tango, monokai formatters.TerminalTrueColorFormatter(style=style) )