Skip to main content

超简单的日志模块,导入即用

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


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 hashes)

Uploaded Source

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