Functional description
Py_log is a simple logging tool (support log file writing, email, pinning, enterprise wechat), multi-threading and process security
Version described
- Support for Pyton: Python 3.0+
PIP install
pip install py-log
Copy the code
example
# log console
from py_log import get_logger
log = get_logger('test')
log.info('123')
Copy the code
Write log to file
from py_log import get_logger
logger = get_logger('test1', log_filename='test1.log')
logger.info('aaaa')
Copy the code
Send a pin log
from py_log import get_logger
ding_talk_token = 'xxxxxxxx'
logger = get_logger('ding_talk_test',ding_talk_token=ding_talk_token, at_mobiles=('13790000000'.'13790000001'))
logger.info('Nail notification')
Copy the code
# Send enterprise wechat logs
from py_log import get_logger
logger = get_logger('weichat_test', agentid='xxx', at_users='aa|bb', corpid='yyy', corpsecret='zzz')
logger.info('Enterprise wechat Notification')
Copy the code
Send a mail log
from py_log import LogManager
from py_log.log_manager import MailHandlerConfig
mail_config = MailHandlerConfig()
mail_config.mailhost = ('smtp.sohu.com'.465)
mail_config.fromaddr = '[email protected]'
mail_config.toaddrs = '[email protected]'
mail_config.credentials = ('mail_username'.'mail_password')
logger_mail = LogManager('log_mail_test').get_logger_and_add_handlers(mail_handler_config=mail_config,
is_add_mail_handler=True)
logger_mail.info('test send mail content')
Copy the code