SingleLog
Project description
SingleLog
A python logger, super easy to use and thread safe.
Install
pip install SingleLog
Tutorials
Init
log_level = Logger.INFO # default
# log_level = Logger.DEBUG
# log_level = Logger.TRACE
logger = Logger('demo', log_level)
Display
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 Logger.DEBUG
or Logger.TRACE
, the location will be displayed.
logger = Logger('demo', Logger.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.
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
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.
def log_to_file(msg):
with open('single_log.txt', 'a', encoding='utf8') as f:
f.write(f'{msg}\n')
logger = Logger('INFO', Logger.INFO, handler=log_to_file)
logger.info('1')
logger.info(2)
logger.info('show value', 456)
Handler can also be a list.
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', Logger.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.
Project details
Release history Release notifications | RSS feed
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.6.tar.gz
(6.6 kB
view details)
Built Distribution
File details
Details for the file SingleLog-1.1.6.tar.gz
.
File metadata
- Download URL: SingleLog-1.1.6.tar.gz
- Upload date:
- Size: 6.6 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb4b438ef927c8bb312d2f251f54a63b968f3d3ccc00a96e2baab7a99539f3ad |
|
MD5 | b5c7c7f9d63ee60fb3683a54fdbf792c |
|
BLAKE2b-256 | 8b2bc2232ff4ffbf52246122151a903f3550927410ab7991d905cfdb4b710179 |
File details
Details for the file SingleLog-1.1.6-py2.py3-none-any.whl
.
File metadata
- Download URL: SingleLog-1.1.6-py2.py3-none-any.whl
- Upload date:
- Size: 4.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 092dae7690b82f91cbfbc53a325cfb366d31a4d6cc851a35eb419aa3a08e6690 |
|
MD5 | 22bc3eb002f4c0ef6d8921c9d0f20754 |
|
BLAKE2b-256 | e88ce1a37f79e58f52aabe6d52f7941527f9c3de15544d20a0f95c273ddc34f7 |