Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

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

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.

Files for ilogger, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size ilogger-0.0.3.tar.gz (2.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page