Skip to main content

Alog

https://travis-ci.org/keitheis/alog.svg?branch=master https://codecov.io/gh/keitheis/alog/branch/master/graph/badge.svg http://img.shields.io/pypi/v/alog.svg?style=flat

Python logging for Humans. Your goto logging module without panic on context swtich.

Warning: No more logger = logging.getLogger(__name__) in your every file.

>>> import alog
>>> alog.info("Hi.")
2016-12-18 20:44:30 INFO  <stdin> Hi.
>>> def test():
...     alog.info("Test 1")
...     alog.error("Test 2")
...
>>> test()
2016-12-18 20:45:19 INFO  <stdin:2> Test 1
2016-12-18 20:45:19 ERROR <stdin:3> Test 2
>>> alog.set_level("ERROR")
>>> test()
2016-12-18 20:45:41 ERROR <stdin:3> Test 2

If you’re new to logging, see Why should you use logging instead of print.

Installation

pip install alog

Features

  • Instant logging with expected defaults.

    You can do logging instantly by reading a small piece of README. Alog comes with useful defaults:

    • A default logger.

    • Logging level: logging.INFO

    • Logging format:

      "%(asctime)s %(levelname)-5.5s [parent_module.current_module:%(lineno)s]%(message)s",
      "%Y-%m-%d %H:%M:%S"
  • No more __name__ whenever you start to do logging in a module.

    Alog builds the default module names on the fly.

  • Compatible with default Python logging module.

    Alog is built upon default Python logging module. You can configure it by the same way of default Python logging module when it’s needed.

Comparing alog with Python default logging module

Comparing alog :

In [1]: import alog

In [2]: alog.info("Hello alog!")
2016-11-23 12:20:34 INFO  <IPython> Hello alog!

with logging module:

In [1]: import logging

In [2]: logging.basicConfig(
   ...:     level=logging.INFO,
   ...:     format="%(asctime)s %(levelname)-5.5s "
   ...:            "[%(name)s:%(lineno)s] %(message)s")

In [3]: # In every file you want to do log, otherwise %(names)s won't work.
In [4]: logger = logging.getLogger(__name__)

In [5]: logger.info("Hello log!")
2016-11-23 12:16:30 INFO  [__main__:1] Hello log!

Why should you use logging instead of print

The main goal of logging is to figure out what was going on and to get the insights. print, by default, does only pure string output. No timestamp, no module hint, and no level control, comparing to a pretty logging record.

Lets start with aproject/models/user.py :

class User:
    def __init__(self, user_id, username):
        ...
        print(username)
        ...

What you got output of print :

>>> admin = User(1, "admin")
"admin"

Now use alog :

import alog

class User:
    def __init__(self, user_id, username):
        ...
        alog.info(username)
        ...

What you got output of alog.info :

>>> admin = User(1, "admin")
2016-11-23 11:32:58 INFO  [models.user:6] admin

In the output of hundreds of lines, it helps (a lot).

What if you have used print a log? That’s as easy:

import alog

print = alog.info

... # A lot of print code no needed to change

(Unrelease)

  • Support not showing_log_datetime by turn_log_datetime(on=False).

0.9.12 (2017-06-16)

  • Support not showing_log_datetime by turn_log_datetime(on=False).

0.9.11 (2017-04-07)

  • Add alog.getLogger() for handy replacing logging.getLogger.

0.9.10 (2017-03-27)

  • Default logging format asctime to “%Y-%m-%d %H:%M:%S” instead of “%Y-%m-%d,%H:%M:%S.%f”.

  • Update package info and usage (setup.py, README, …).

0.9.9 (2016-08-28)

  • Update to turn_thread_name and turn_process_id.

0.9.8 (2016-08-27)

  • Support showing_thread_name and showing_process_id.

  • Support global reset.

0.9.7 (2016-08-17)

  • Better paths log for None default root name.

0.9.6 (2016-08-16)

  • First public release.

Download files

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

Source Distribution

alog-0.9.12.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alog-0.9.12-py2.py3-none-any.whl (7.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file alog-0.9.12.tar.gz.

File metadata

  • Download URL: alog-0.9.12.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for alog-0.9.12.tar.gz
Algorithm Hash digest
SHA256 a1bfab7e8067b5fe29f4c6c8bd961e99f07e61dca3236f6d16869c89b154377a
MD5 c292d29d97f91f126b120d594e432e69
BLAKE2b-256 42a4208c32e20658fbed76df029c74ca6ab3ac4180909c6962da4f226a696cb6

See more details on using hashes here.

File details

Details for the file alog-0.9.12-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for alog-0.9.12-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8c2458a93917a4de43517e38d14f118fc07b56105f427149c31c7e9c363ba253
MD5 ae04898c7a3e09d3e1970cb1085550be
BLAKE2b-256 61b4d95ddd649c1d96cf9738677b68562ce6532d994ac31eb02b7863dbe2e8ff

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.9.13

2 files

This release

0.9.12 This release

2 files

0.9.11

2 files

0.9.10

2 files

0.9.9

2 files

0.9.8

2 files

0.9.7

2 files

0.9.6

2 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