add basic filebased logging configuration
This commit is contained in:
parent
b40be62cb1
commit
de96c3de06
1
Pipfile
1
Pipfile
|
@ -15,6 +15,7 @@ requests = "*"
|
|||
igramscraper = "*"
|
||||
twitterscraper = "*"
|
||||
httpx = "*"
|
||||
pyyaml = "==5.3"
|
||||
|
||||
[dev-packages]
|
||||
pylint = "*"
|
||||
|
|
17
bot.py
17
bot.py
|
@ -3,13 +3,14 @@
|
|||
import asyncio
|
||||
import glob
|
||||
import importlib
|
||||
import json
|
||||
import yaml
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import traceback
|
||||
import urllib.parse
|
||||
import logging
|
||||
import logging.config
|
||||
from importlib import reload
|
||||
|
||||
import requests
|
||||
|
@ -46,14 +47,20 @@ class Bot:
|
|||
self.logger.debug("Initialized")
|
||||
|
||||
def initializeLogger(self):
|
||||
log_format = '%(levelname)s - %(name)s - %(message)s'
|
||||
|
||||
if os.path.exists('config/logging.yml'):
|
||||
with open('config/logging.yml') as f:
|
||||
config = yaml.load(f, Loader=yaml.Loader)
|
||||
logging.config.dictConfig(config)
|
||||
else:
|
||||
log_format = '%(levelname)s - %(name)s - %(message)s'
|
||||
logging.basicConfig(format=log_format)
|
||||
|
||||
if self.debug:
|
||||
logging.root.setLevel(logging.DEBUG)
|
||||
else:
|
||||
logging.root.setLevel(logging.INFO)
|
||||
|
||||
logging.basicConfig(format=log_format)
|
||||
|
||||
async def send_text(self, room, body):
|
||||
msg = {
|
||||
"body": body,
|
||||
|
@ -73,7 +80,7 @@ class Bot:
|
|||
def remove_callback(self, callback):
|
||||
for cb_object in bot.client.event_callbacks:
|
||||
if cb_object.func == callback:
|
||||
print("remove callback")
|
||||
self.logger.info("remove callback")
|
||||
bot.client.event_callbacks.remove(cb_object)
|
||||
|
||||
def get_room_by_id(self, room_id):
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
version: 1
|
||||
formatters:
|
||||
hemppa:
|
||||
format: '%(levelname)s - %(name)s - %(message)s'
|
||||
handlers:
|
||||
console:
|
||||
class: logging.StreamHandler
|
||||
level: INFO
|
||||
formatter: hemppa
|
||||
stream: ext://sys.stdout
|
||||
loggers:
|
||||
hemppa:
|
||||
level: INFO
|
||||
handlers: [console]
|
||||
propagate: no
|
||||
root:
|
||||
level: DEBUG
|
||||
handlers: [console]
|
Loading…
Reference in New Issue