超简单的日志模块,导入即用
Project description
ilogger
超简单的日志模块,导入即用
如何使用它?
>>> pip install ilogger
简单使用,默认级别为 INFO
from ilogger import logger
logger.debug('this is debug message')
logger.info('this is info message')
[2019-09-24 19:54:23,544] INFO: this is info message
设置 logger 级别
from ilogger import logger
logger.setLevel(logger.DEBUG)
logger.debug('this is debug message')
logger.info('this is info message')
logger.warning('this is warning message')
logger.warn('this is warning message')
logger.error('this is error message')
logger.critical('this is critical message')
[2019-09-24 19:54:23,544] DEBUG: this is debug message
[2019-09-24 19:54:23,544] INFO: this is info message
[2019-09-24 19:54:23,544]WARNING: this is warning message
[2019-09-24 19:54:23,544]WARNING: this is warning message
[2019-09-24 19:54:23,544] ERROR: this is error message
[2019-09-24 19:54:23,544]CRITICAL: this is critical message
设置 logger 格式
from ilogger import logger
logger.setFormatter(fmt='[%(asctime)s]%(levelname)7s[%(filename)s:%(lineno)s]: %(message)s')
logger.debug('this is debug message')
logger.info('this is info message')
[2019-09-24 19:54:23,544] DEBUG[demo.py:21]: this is debug message
[2019-09-24 19:54:23,544] INFO[demo.py:22]: this is info message
将日志写入到文件
from ilogger import logger
# 设置 logger 格式
logger.setFormatter(fmt='[%(asctime)s]%(levelname)7s[%(filename)s:%(lineno)s]: %(message)s')
logger.setFileHandler('mylog.log')
logger.debug('this is debug message')
logger.info('this is info message')
logger.warning('this is warning message')
./mylog.log
[2020-02-28 20:57:17,199] INFO[demo.py:35]: this is info message
[2020-02-28 20:57:17,199]WARNING[demo.py:36]: this is warning message
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
ilogger-0.0.3.tar.gz
(2.5 kB
view details)
File details
Details for the file ilogger-0.0.3.tar.gz
.
File metadata
- Download URL: ilogger-0.0.3.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 567e02bc1246e00f62a601b1c2976b312bae07d0903beb8bbc1c3239a8b5faba |
|
MD5 | 2c40026fe2200e3d9358342cef5fab03 |
|
BLAKE2b-256 | 1e6f859783f45da1f54f404c4d8b3e9227570704e07d6d877f5e31df98081e37 |