Doc string and types bump in loggin mod

service_subpkg_backup
Tyler Goodlet 2023-03-08 14:22:23 -05:00
parent ad6b655d7d
commit 5683eb8ef0
1 changed files with 36 additions and 10 deletions

View File

@ -21,7 +21,11 @@ import logging
import json import json
import tractor 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__`` # Makes it so we only see the full module name when using ``__name__``
# without the extra "piker." prefix. # without the extra "piker." prefix.
@ -32,26 +36,48 @@ def get_logger(
name: str = None, name: str = None,
) -> logging.Logger: ) -> 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) return tractor.log.get_logger(name=name, _root_name=_proj_name)
def get_console_log(level: str = None, name: str = None) -> logging.Logger: def get_console_log(
'''Get the package logger and enable a handler which writes to stderr. 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... Yeah yeah, i know we can use ``DictConfig``. You do it...
''' '''
return tractor.log.get_console_log( 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'): def colorize_json(
"""Colorize json output using ``pygments``. data: dict,
""" style='algol_nu',
formatted_json = json.dumps(data, sort_keys=True, indent=4) ):
'''
Colorize json output using ``pygments``.
'''
formatted_json = json.dumps(
data,
sort_keys=True,
indent=4,
)
return highlight( return highlight(
formatted_json, lexers.JsonLexer(), formatted_json,
lexers.JsonLexer(),
# likeable styles: algol_nu, tango, monokai # likeable styles: algol_nu, tango, monokai
formatters.TerminalTrueColorFormatter(style=style) formatters.TerminalTrueColorFormatter(style=style)
) )