# SingleLog
Project description
SingleLog
A single python logger, super easy to use and thread safe.
Install
pip install SingleLog -U
Tutorials
Init
from SingleLog import Logger
from SingleLog import LogLevel
log_level = LogLevel.INFO # default
# log_level = LogLevel.DEBUG
# log_level = LogLevel.TRACE
logger = Logger('demo', log_level)
### Display
```python
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][demo.py 6] 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 in format. 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"
}
Supports the do
method that you can call it, when you finish the work.
import time
from SingleLog import Logger
logger = Logger('demo')
logger.do_info('do something')
time.sleep(1)
logger.done('ok')
Output
[08.30 10:36:57][logger] do something ... ok
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.
License
MIT License
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
Built Distribution
File details
Details for the file SingleLog-2.0.2.tar.gz
.
File metadata
- Download URL: SingleLog-2.0.2.tar.gz
- Upload date:
- Size: 1.4 MB
- 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 | 66fc342ed4ee46c4561970456e0c18e1d7b28522423248d8bd136cf9300764a6 |
|
MD5 | 2ce231dd51ce29612428682f1b0d3f40 |
|
BLAKE2b-256 | 57388d36497e27e17a2304459fd35640afb85b1bba036793c76ce1245cb30804 |
File details
Details for the file SingleLog-2.0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: SingleLog-2.0.2-py2.py3-none-any.whl
- Upload date:
- Size: 5.9 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 | 7d3c9d64aee2ec7ca6fe3d7dd3b5120bf74c57ef325804fd0dfe7b0d7ec1cc8a |
|
MD5 | d8a82dce2f802eb07b3be63182ecb91d |
|
BLAKE2b-256 | 901a892de42437fba2e3ab3522954d04f1010dd8ebae671334d510c8e57a6843 |