lector.log#

Helpers to pretty print/log objects using Rich.

Classes#

ColoredFormatter

A custom formatter controlling message color.

Functions#

dict_view(d[, title, expand, width, padding])

pformat(obj[, console, markup, end, strip])

Pretty format any object, if possible with Rich.

schema_comparison(s1, s2[, title, padding, left, right])

schema_diff_view(diff[, title, padding])

Make a rich view for an arrow schema diff.

schema_view(schema[, title, padding])

Make a rich view for arrow schema.

setup_logging([level, color])

Ensure logging handler is only added once.

table_view(tbl[, title, n_rows_max, n_columns_max, ...])

Pyarrow table to rich table.

track(items[, columns, total, desc, update_period])

Rich track with elapsed time by default.

type_view(type)

More compact strinf represenation of arrow data types.

Attributes#

BOX

CONSOLE

Item

LOG

iformat

Shortcut for inline formatting, avoiding strings terminating in line breaks.

class lector.log.ColoredFormatter(datefmt=None, validate=True)[source]#

Bases: logging.Formatter

A custom formatter controlling message color.

COLORS[source]#
FORMAT = Multiline-String[source]#
Show Value
"""<COL>{asctime} {levelname} | {name} | {module}.{funcName}:{lineno}<RESET>
{message}"""
RESET = '\x1b[0m'[source]#
format(record)[source]#

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

lector.log.dict_view(d, title='', expand=False, width=None, padding=1, **kwds)[source]#
Parameters:
  • d (dict) –

  • title (str) –

  • expand (bool) –

Return type:

rich.panel.Panel

lector.log.pformat(obj, console=None, markup=True, end='', strip=False, **kwargs)[source]#

Pretty format any object, if possible with Rich.

lector.log.schema_comparison(s1, s2, title=None, padding=1, left='Before', right='After')[source]#
Parameters:
  • s1 (pyarrow.Schema) –

  • s2 (pyarrow.Schema) –

  • title (str | None) –

  • padding (int) –

  • left (str) –

  • right (str) –

lector.log.schema_diff_view(diff, title=None, padding=1)[source]#

Make a rich view for an arrow schema diff.

Parameters:
  • diff (dict) –

  • title (str | None) –

  • padding (int) –

Return type:

rich.table.Table

lector.log.schema_view(schema, title='Schema', padding=1)[source]#

Make a rich view for arrow schema.

Parameters:
  • schema (pyarrow.Schema) –

  • title (str | None) –

  • padding (int) –

Return type:

rich.table.Table

lector.log.setup_logging(level=logging.DEBUG, color=True)[source]#

Ensure logging handler is only added once.

lector.log.table_view(tbl, title=None, n_rows_max=10, n_columns_max=6, max_column_width=20, padding=1)[source]#

Pyarrow table to rich table.

Parameters:
  • tbl (pyarrow.Table) –

  • title (str | None) –

  • n_rows_max (int) –

  • n_columns_max (int) –

  • max_column_width (int) –

  • padding (int) –

Return type:

rich.table.Table

lector.log.track(items, columns=None, total=None, desc='Processing', update_period=0.1, **kwds)[source]#

Rich track with elapsed time by default.

Parameters:
  • items (collections.abc.Iterable[Item] | collections.abc.Sequence[Item]) –

  • columns (collections.abc.Iterable[rich.table.Column] | None) –

  • total (float | None) –

  • desc (str) –

  • update_period (float) –

Return type:

collections.abc.Iterable[Item]

lector.log.type_view(type)[source]#

More compact strinf represenation of arrow data types.

Parameters:

type (pyarrow.DataType) –

Return type:

str

lector.log.BOX[source]#
lector.log.CONSOLE[source]#
lector.log.Item[source]#
lector.log.LOG[source]#
lector.log.iformat[source]#

Shortcut for inline formatting, avoiding strings terminating in line breaks.