Skip to main content

All code should use Python standard log module instead of print() function.

Install

python3 setup.py install

Usage

Basic usage.

from alogs import get_logger

logger = get_logger('module_name')

logger.debug('Debug message')
logger.info('Info message')
logger.warning('Warning message')
logger.error('Error message')
logger.critical('Critical message')

Log file

Store logs into a file.

from alogs import get_logger

logger = get_logger('module_name', 'log_file.log')

logger.debug('Debug message')  # Debug messages *are not* logged into the file
logger.info('Info message')

Disable existing loggers

Prevent existing loggers to log.

from alogs import get_logger

logger = get_logger('module_name', disable_existing_loggers=True)

logger.debug('Debug message')

Change default log level

The default log level is DEBUG, but it can be changed:

from alogs import get_logger

logger = get_logger('module_name', root_level='warning')

logger.debug('Debug message')  # won't appear
logger.warning('Info message')

Test

To test it just execute the test.py:

~ python3 test.py

You should see:

*** Simple logs ***
DEBUG 2021-02-02 12:58:18,672 MainProcess:16581 test:test_simple_logs() test.py:7 [alogs] = Debug simple message
INFO 2021-02-02 12:58:18,672 MainProcess:16581 test:test_simple_logs() test.py:8 [alogs] = Info simple message
WARNING 2021-02-02 12:58:18,672 MainProcess:16581 test:test_simple_logs() test.py:9 [alogs] = Warning simple message
ERROR 2021-02-02 12:58:18,672 MainProcess:16581 test:test_simple_logs() test.py:10 [alogs] = Error simple message
CRITICAL 2021-02-02 12:58:18,672 MainProcess:16581 test:test_simple_logs() test.py:11 [alogs] = Critical simple message

*** Module logs ***
DEBUG 2021-02-02 12:58:18,672 MainProcess:16581 test:test_module_name_logs() test.py:16 [module_name] = Debug module message
INFO 2021-02-02 12:58:18,672 MainProcess:16581 test:test_module_name_logs() test.py:17 [module_name] = Info module message
WARNING 2021-02-02 12:58:18,673 MainProcess:16581 test:test_module_name_logs() test.py:18 [module_name] = Warning module message
ERROR 2021-02-02 12:58:18,673 MainProcess:16581 test:test_module_name_logs() test.py:19 [module_name] = Error module message
CRITICAL 2021-02-02 12:58:18,673 MainProcess:16581 test:test_module_name_logs() test.py:20 [module_name] = Critical module message

*** File logs ***
DEBUG 2021-02-02 12:58:18,673 MainProcess:16581 test:test_file_logs() test.py:25 [file_logs] = THIS MESSAGE SHOULD NOT APPEAR ON THE FILE
INFO 2021-02-02 12:58:18,673 MainProcess:16581 test:test_file_logs() test.py:26 [file_logs] = Info file message
WARNING 2021-02-02 12:58:18,715 MainProcess:16581 test:test_file_logs() test.py:27 [file_logs] = Warning file message
ERROR 2021-02-02 12:58:18,715 MainProcess:16581 test:test_file_logs() test.py:28 [file_logs] = Error file message
CRITICAL 2021-02-02 12:58:18,715 MainProcess:16581 test:test_file_logs() test.py:29 [file_logs] = Critical file message
* Logs written on file "test.log" *
INFO 02/Feb/2021:12:58:18 -0300 MainProcess:16581 test:test_file_logs() test.py:26 [file_logs] = Info file message
WARNING 02/Feb/2021:12:58:18 -0300 MainProcess:16581 test:test_file_logs() test.py:27 [file_logs] = Warning file message
ERROR 02/Feb/2021:12:58:18 -0300 MainProcess:16581 test:test_file_logs() test.py:28 [file_logs] = Error file message
CRITICAL 02/Feb/2021:12:58:18 -0300 MainProcess:16581 test:test_file_logs() test.py:29 [file_logs] = Critical file message

Release files for alogs 3.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 alogs 3.3
File Size Uploaded
alogs-3.3.tar.gz 3.6 kB Details

Release files / alogs-3.3.tar.gz

Download URL alogs-3.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5edcb637ff9b82f061955c9597ae79c215ce2f0d86f0c2e90526c37af2e203cb
BLAKE2b-256 checksum
How to use checksums
7cf12e4b8e03b2ca2fe81ca4a75efb0cb676352e7ca22404123e1b8e8083bd73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.6.8

Release history Release notifications | RSS feed

This release

3.3 This release

1 release file

3.0

1 release file

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