Skip to main content

nanolog

Life is too short. Use nanolog to make logging and printing simpler!

nanolog features a convenient logger API built on top of python’s builtin logging.

The library also ships with many printing utilities. Python 3 only.

Installation

From stable package on PyPI

pip install nanolog

From bleeding edge master branch

pip install git+git://github.com/SurrealAI/nanolog.git

nanolog.Logger

Logging levels, from least severe to most:

  • LOG_ALL: log everything

  • TRACE: fine-grained debugging messages

  • DEBUG: normal debugging

  • INFO: messages you usually don’t want to see

  • NOTICE (i.e. INFO5): non-error messages you usually want to see

  • WARNING: exceptional circumstances that might not be errors

  • ERROR: errors that occur, but are anticipated and handled

  • CRITICAL: fatal errors that lead to termination

  • LOG_OFF: turn off all logging

import nanolog as nl

logger = nl.Logger.create_logger(
    'main',
    stream='out',
    level='debug',
)

logger.info('my', 3, 'world', 1/16.)  # just like print
# >>> my 3 world 0.0625

# nanolog use 'warn' instead of 'warning'
logger.warnfmt('{}, we are {:.3f} miles from {planet}',
               'Houston', 17/7, planet='Mars')  # just like str.format
# >>> Houston, we are 2.429 miles from Mars

Use a trailing number to indicate level, the larger the higher priority

logger.info7(...)  # info level 7
logger.errorfmt8(...)  # error level 8

Display a banner line or block

logger.infobanner3('my', 3, 'world', symbol='!', banner_len=16, banner_lines=3)

prints:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!! my 3 world !!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Of course, banner method also comes with a str.format version

logger.debugbannerfmt(
    '{3}&{0}&{2}&{1}', 'a', 'b', 'c', 'd',
    symbol='<*_*>', banner_len=16, banner_lines=6
)

displays:

<*_*><*_*><*_*><*_*><*_*>
<*_*><*_*><*_*><*_*><*_*>
<*_*><*_ d&a&c&b <*_*><*_
<*_*><*_*><*_*><*_*><*_*>
<*_*><*_*><*_*><*_*><*_*>
<*_*><*_*><*_*><*_*><*_*>

Prettyprint support (uses the thirdparty lib prettyprinter)

logger.infopp7(...)
logger.warnppfmt('my warning {:.3f} format {:.2f} string', 1/7., 1/9.)

Logger config

TODO

Time formatting

TODO

Printing utililites

prettyprint

Better alternatives for the pprint module in python standard lib.

  • pprint: takes variable number of objects, just like print()

  • pprintstr: return string instead of printing to IO stream

  • pprintfmt: just like print('...'.format)

  • pprintfmtstr: return string instead of printing to IO stream

Convenient aliases (pp stands for prettyprint; a single p means normal print)

short

original

pf

printfmt

pferr

printfmterr

pstr

printstr

perr

printerr

pp

pprint

ppstr

pprintstr

ppf

pprintfmt

ppfstr

pprintfmtstr

TODO: talk about global configs

Print redirection context managers

  • PrintRedirection

  • PrintFile

  • PrintSuppress

  • PrintString

Release files for nanolog 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanolog 0.1.3
File Size Uploaded
nanolog-0.1.3.tar.gz 16.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nanolog 0.1.3
File Interpreter ABI Platform
nanolog-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / nanolog-0.1.3.tar.gz

Download URL nanolog-0.1.3.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a85ef8e441b76bba9daf7ba7b1fdafc79097f91c80b4cd2ef16f08c5eb38f433
BLAKE2b-256 checksum
How to use checksums
0b46f7161ded9682d7b341cf6399bb43c4341b2b0a40bef2f2c6a760b9f99b4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / nanolog-0.1.3-py3-none-any.whl

Download URL nanolog-0.1.3-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
173d95aaa3ede2e2521b4d1f742fdd2462ab16e0b0bc478cf42dc800d1f1cb21
BLAKE2b-256 checksum
How to use checksums
946cc629e4b4bc3474aae6b60974f61d83849fd6343b007a095f613f8c693654
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page