Skip to main content

python logging on steroids, lightweight and convenient

Project description

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

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

logger.warningfmt('{}, 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.warningppfmt('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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanolog-0.1.2.post1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

nanolog-0.1.2.post1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file nanolog-0.1.2.post1.tar.gz.

File metadata

File hashes

Hashes for nanolog-0.1.2.post1.tar.gz
Algorithm Hash digest
SHA256 fdcdd35e781407031720fe6f5292846ac0d31ed665ddd83e999dfb92552eb246
MD5 b641069e1e93a7b0d125e628afb55129
BLAKE2b-256 e86141308d6f854f7b7064755eb8e644db0c3cb5286cf2975b15563168550988

See more details on using hashes here.

File details

Details for the file nanolog-0.1.2.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for nanolog-0.1.2.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ef4a42efd562a4495c7fb3f5b947785f2443823d43483bbf1b98120c51d6ac8
MD5 4b42e076b964ddcb6be03a21f4a2e41f
BLAKE2b-256 6cb441d3430fbcbc71d012a33d582916c2baff0dffb5e70577a93ada1d76098b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page