Custom logging filter for PINT using loguru.

To use this do:

import pint.logging

If you want to emit messages later in your code, set things up with:

from loguru import logger as log"INFO test")

This can happen before or after the setup().

You can optionally pass the desired logging level to the setup() function, formats, custom filters, colors, etc. See documentation for pint.logging.setup().

level can be any of the existing loguru levels: TRACE, DEBUG, INFO, WARNING, ERROR, or you can define new ones.

The format can be something new, or you can use pint.logging.format. A full format that might be useful as a reference is:

format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"

while the default for this module is:

format = "<level>{level: <8}</level> ({name: <30}): <level>{message}</level>"

If you want to use command-line arguments in a script to set the level you can do that like:

parser.add_argument("--log-level",type=str,choices=pint.logging.levels,default=pint.logging.script_level,help="Logging level",dest="loglevel")
    "-v", "--verbosity", default=0, action="count", help="Increase output verbosity"
    "-q", "--quiet", default=0, action="count", help="Decrease output verbosity"
args = parser.parse_args(argv)
    level=pint.logging.get_level(args.loglevel, args.verbosity, args.quiet)

Note that loguru does not allow you to change the properties of an existing logger. Instead it’s better to remove it and make another (e.g., if you want to change the level).

Defaults can be changed with environment variables like: $LOGURU_LEVEL, $LOGURU_FORMAT, $LOGURU_DEBUG_COLOR.

See loguru documentation for full set of options.


get_level(starting_level_name, verbosity, ...)

Get appropriate logging level given command-line input

setup([level, sink, format, filter, ...])

Setup the PINT logging using loguru

showwarning(message, category, filename, lineno)

Function to allow loguru to capture warnings emitted by warnings.warn().


LogFilter([onlyonce, never, onlyonce_level])

Custom logging filter for loguru.