python的日志配置
yaml 示例
version: 1
disable_existing_loggers: False
formatters:
simple:
format: '%(asctime)s - %(filename)s - %(lineno)d - [%(levelname)s] %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
logfile:
class: logging.handlers.RotatingFileHandler
level: INFO
formatter: simple
filename: LOG
maxBytes: 10485760
backupCount: 3
loggers:
module:
level: INFO
handlers: [console, logfile]
propagate: 0
root:
level: DEBUG
handlers: [logfile]
ini 配置文件
[base] admin=423453012 admin_room=-1001238951919 bot_token=321305199:AAFKD4JcwYZuqH6yTyH5kII6hWKUeo0xH_I [webhook] local_host=127.0.0.1 local_path=bottoken local_port=5000 remote_url=https://telegram.lemo.site/bottoken remote_timeout=40 [file] chunk_size=5242880 tmp_path=/home/lg/.local/share/tamakosbot/cache cookie_path=/home/lg/.local/share/tamakosbot/cookie [other] log_file =LOG transfer_timeout=500 [api] netease_username=xxxxx netease_password= anime_token=f7059ee0b05b9c59e15cd5c1e49955444420f596z
json 配置
{
"logging": {
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"brief": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}; {name:<15s}; {message:s}"
},
"simple": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}; {asctime:s}; {name:<15s} {lineno:4d}; {message:s}"
},
"multi-process": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}; {process:5d}; {asctime:s}; {name:<15s} {lineno:4d}; {message:s}"
},
"multi-thread": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}; {threadName:5d}; {asctime:s}; {name:<15s} {lineno:4d}; {message:s}"
},
"verbose": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}; {process:5d}; {threadName:8s}; {asctime:s}; {name:<15s} {lineno:4d}; {message:s}"
},
"multiline": {
"class": "logging.Formatter",
"style": "{",
"datefmt": "%I:%M:%S",
"format": "{levelname:8s}\n{process:5d}\n{threadName:8s}\n{asctime:s}\n{name:<15s}{lineno:4d}\n{message:s}\n"
}
},
"handlers": {
"console":{
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "multiline",
"stream" : "ext://sys.stdout"
},
"file_handler": {
"level": "INFO",
"class": "logging.handlers.WatchedFileHandler",
"formatter": "verbose",
"filename": "/tmp/file_handler.log",
"mode": "a",
"encoding": "utf-8"
},
"smtp": {
"level": "ERROR",
"class": "logging.handlers.SMTPHandler",
"formatter": "multiline",
"mailhost": ["127.0.0.1", 25],
"fromaddr": "sender@example.com",
"toaddrs": ["recipient@example.com"],
"subject": "Something went wrong"
}
},
"loggers": { },
"root": {
"handlers": ["console"],
"level": "DEBUG"
}
}
}
end
浙公网安备 33010602011771号