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:

pip install nanolog

nanolog.Logger

import nanolog as nl

logger = nl.Logger.get_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 <*_*><*_
<*_*><*_*><*_*><*_*><*_*>
<*_*><*_*><*_*><*_*><*_*>
<*_*><*_*><*_*><*_*><*_*>

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:

original

short

pprint

pp

pprintstr

pps

pprintfmt

ppf

pprintfmtstr

ppfs

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.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

nanolog-0.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file nanolog-0.1.tar.gz.

File metadata

  • Download URL: nanolog-0.1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nanolog-0.1.tar.gz
Algorithm Hash digest
SHA256 f075abf732091fbf132b26d1260ac604d6557df52ee241b1ec59f80a7f958525
MD5 9b7525f3e29793e84edcb9c2f6e122b6
BLAKE2b-256 522d2325b8ca37cfce45fbd69216a8cd0774646b725bc14d90e92a46d25a241a

See more details on using hashes here.

File details

Details for the file nanolog-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for nanolog-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a2e983654c5c3cadd4125394669bd37af2431a1ac8a91a7f620aae05cabd669
MD5 7faa91d303a3c71e280fd89c760f2fa4
BLAKE2b-256 2330f84417c732950d40d902d1f042537f4e42063a16580115d803f813bf6ac5

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