Skip to main content

SingleLog

Project description

SingleLog

Package Version PyPI - Downloads PyPI - Python Version Python package

A python logger, super easy to use and thread safe.

Install

pip install SingleLog

Tutorials

Init

from SingleLog import Logger
from SingleLog import LogLevel

log_level = LogLevel.INFO # default
# log_level = Logger.DEBUG
# log_level = Logger.TRACE
logger = Logger('demo', log_level)

Display

from SingleLog import Logger

logger = Logger('demo')

logger.info(1)
logger.debug(2)
logger.trace(3)

Result

[20210501 11:19:48][demo] 1

When the log level is set to LogLevel.DEBUG or LogLevel.TRACE, the location will be displayed.

from SingleLog import Logger
from SingleLog import LogLevel

logger = Logger('demo', LogLevel.TRACE)
logger.info('This is the description', 'demo')
logger.debug('This is the description', 'demo')
logger.trace('This is the description', 'demo')

Result

[20211104 09:13:16][demo] This is the description [demo]
[20211104 09:13:16][demo][demo.py 7] This is the description [demo]
[20211104 09:13:16][demo][demo.py 8] This is the description [demo]

SingleLog Supports some common types to display. Such as list, dict and tuple.

from SingleLog import Logger

logger = Logger('demo')
logger.info('show int list', [101, 102, 103])
logger.info('show tuple', ('12', '14', '16'))
logger.info('data', {'1': 'value1', '2': 'value2'})

Result

[20210501 12:14:48][demo] show int list [101 102 103]
[20210501 12:14:48][demo] show tuple (12 14 16)
[20210501 12:14:48][demo] data 
{
  "1": "value1",
  "2": "value2"
}

SingleLog supports args as parameter.
It helps you to format your log message

from SingleLog import Logger

logger = Logger('demo')
logger.info('This is the description', 'value 0', 'value 1', 99)

Result

[20210501 12:10:01][demo] This is the description [value 0] [value 1] [99]

Handler

Sometimes, you want to catch the log message at higher level.
Use log handler.

from SingleLog import Logger
from SingleLog import LogLevel

def log_to_file(msg):
    with open('single_log.txt', 'a', encoding='utf8') as f:
        f.write(f'{msg}\n')


logger = Logger('INFO', LogLevel.INFO, handler=log_to_file)

logger.info('1')
logger.info(2)
logger.info('show value', 456)

Handler can also be a list.

from SingleLog import Logger
from SingleLog import LogLevel

def log_to_file(msg):
    with open('single_log.txt', 'a', encoding='utf8') as f:
        f.write(f'{msg}\n')

def log_to_file2(msg):
    with open('single_log_2.txt', 'a', encoding='utf8') as f:
        f.write(f'{msg}\n')


logger = Logger('INFO', LogLevel.INFO, handler=[log_to_file, log_to_file2])

logger.info('1')
logger.info(2)
logger.info('show value', 456)

In this demo, the log message will display on the screen.
Also you can find it in local file.

You can check all the demo in demo.py.

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

SingleLog-1.1.15.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

SingleLog-1.1.15-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file SingleLog-1.1.15.tar.gz.

File metadata

  • Download URL: SingleLog-1.1.15.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for SingleLog-1.1.15.tar.gz
Algorithm Hash digest
SHA256 9b456c70cac60a59d14ff94334c3c3f6daa02a91deb312af1b3a6c7b60e6d912
MD5 9751d7e99234af89c2385b887696845b
BLAKE2b-256 6cde195e08f7f623c128ee85e452bcab6362a5db3012b5d3e87569dce227bdc9

See more details on using hashes here.

File details

Details for the file SingleLog-1.1.15-py2.py3-none-any.whl.

File metadata

  • Download URL: SingleLog-1.1.15-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for SingleLog-1.1.15-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 11fae82d33e494492fc7db5de7b690c33385f4256373e797f815b8013ae6a4d0
MD5 377bec605d257299c472e60379868654
BLAKE2b-256 d927dd70f55051c59e12913d0976b424aefa5b452d0fef016ebc9c38ef78124f

See more details on using hashes here.

Supported by

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