PythonCK.logging package¶
Submodules¶
PythonCK.logging.filters module¶
-
class
PythonCK.logging.filters.Blacklist(*whitelist)[source]¶ Bases:
PythonCK.logging.filters.Whitelist>>> filt = Blacklist('PythonCK') >>> filt.filter(LogRecord('muon')) True >>> filt.filter(LogRecord('PythonCK.logging')) False
-
__module__= 'PythonCK.logging.filters'¶
-
-
class
PythonCK.logging.filters.FuncFileNameRegexFilter(pattern)[source]¶ Bases:
logging.FilterValid if re.search returns non-null.
>>> filt = FuncFileNameRegexFilter(r'tauh[13]') >>> print(filt) FuncFileNameRegexFilter: tauh[13]
>>> filt.filter(LogRecord('tauh1')) True >>> filt.filter(LogRecord('tauh3')) True >>> filt.filter(LogRecord('taumu', func=func0)) False
-
__init__(pattern)[source]¶ Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
-
__module__= 'PythonCK.logging.filters'¶
-
-
class
PythonCK.logging.filters.Whitelist(*whitelist)[source]¶ Bases:
logging.FilterFilter the log by name.
>>> filt = Whitelist('muon', 'tau') >>> filt.filter(LogRecord('muon')) True >>> filt.filter(LogRecord('tau.h1')) True >>> filt.filter(LogRecord('123')) False
-
__init__(*whitelist)[source]¶ Initialize a filter.
Initialize with the name of the logger which, together with its children, will have its events allowed through the filter. If no name is specified, allow every event.
-
__module__= 'PythonCK.logging.filters'¶
-
PythonCK.logging.handlers module¶
Custom logging handler derived from RainbowLoggingHandler.
-
class
PythonCK.logging.handlers.MyLoggingHandler(width=34)[source]¶ Bases:
logging.StreamHandlerMy custom log handler, with following touches - support extra field name_override, file_override - changeable column width
-
__module__= 'PythonCK.logging.handlers'¶
-
-
PythonCK.logging.handlers.add_indent(lines, width_full, width_column)[source]¶ Given a paragraph, add indent on each line except first one.
>>> print(add_indent('123', 40, 12)) 123
>>> print(add_indent(u'123', 40, 12)) 123
>>> print(add_indent(['123'], 40, 12)) ['123']
-
PythonCK.logging.handlers.check_term_width()[source]¶ Try do determine current terminal width if possible, otherwise default to 120
-
PythonCK.logging.handlers.condense_two_strings(s1, s2, width)[source]¶ Given 2 strings (e.g., funcname & filename), return 2 strings pair such that the length is does not exceed given width, in order to maximize space in the left-column of logging.
>>> condense_two_strings('aa', 'bb', 8) ('aa', 'bb ') >>> condense_two_strings('aaaa', 'bbbb', 8) ('aaaa', 'bbbb') >>> condense_two_strings('aaaaaaa', 'bbbb', 8) ('aa..', 'bbbb') >>> condense_two_strings('aaa', 'bbbbbbb', 8) ('aaa', 'bbb..')
PythonCK.logging.logger module¶
-
class
PythonCK.logging.logger.MyLogger(name, level=0)[source]¶ Bases:
logging.Logger-
DEBUG= 10¶
-
ERROR= 40¶
-
INFO= 20¶
-
WARNING= 30¶
-
__module__= 'PythonCK.logging.logger'¶
-
capture(**kwds)[source]¶ Usage:
>>> logger = getfixture('logger') >>> with logger.capture() as lines: ... print('Inside capture') ... logger.info("It should be silent here") ... logger.warning("even if it's very loud.") Inside capture
>>> for line in lines: ... print(line) INFO: <module> - It should be silent here WARNING: <module> - even if it's very loud.
-
PythonCK.logging.utils module¶
Module contents¶
Entry point to using my custom logging facility.
- Colored log (via RainbowLoggingHandler).
- Log capture contextmanager.
- Flexible 2-columns width.
- Regex filter.
REF: