forked from hkc/mastoposter
Added configurable logging level
This commit is contained in:
parent
bfa0534f6d
commit
94f477bc45
|
@ -104,6 +104,10 @@ connection error!!!)
|
|||
#### modules
|
||||
More about them later
|
||||
|
||||
#### loglevel
|
||||
Self-explanatory, logging level. Can be either `DEBUG`, `INFO`, `WARNING` or
|
||||
`ERROR`. Defaults to `INFO`
|
||||
|
||||
### Modules
|
||||
There's two types of modules supported at this point: `telegram` and `discord`.
|
||||
Both of them are self-explanatory, but we'll go over them real quick.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
from asyncio import run
|
||||
from configparser import ConfigParser, ExtendedInterpolation
|
||||
from logging import INFO, Formatter, StreamHandler, getLogger
|
||||
from logging import INFO, Formatter, StreamHandler, getLevelName, getLogger
|
||||
from sys import stdout
|
||||
from mastoposter import execute_integrations, load_integrations_from
|
||||
from mastoposter.integrations import FilteredIntegration
|
||||
|
@ -72,10 +72,10 @@ async def listen(
|
|||
|
||||
|
||||
def main(config_path: str):
|
||||
init_logger()
|
||||
conf = ConfigParser(interpolation=ExtendedInterpolation())
|
||||
conf.read(config_path)
|
||||
|
||||
init_logger(getLevelName(conf["main"].get("loglevel", "INFO")))
|
||||
normalize_config(conf)
|
||||
|
||||
modules: List[FilteredIntegration] = load_integrations_from(conf)
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
from asyncio import exceptions
|
||||
from json import loads
|
||||
from logging import getLogger
|
||||
from typing import AsyncGenerator
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from mastoposter.types import Status
|
||||
|
||||
logger = getLogger("sources")
|
||||
|
||||
|
||||
async def websocket_source(
|
||||
url: str, reconnect: bool = False, **params
|
||||
|
@ -22,6 +25,20 @@ async def websocket_source(
|
|||
raise Exception(event["error"])
|
||||
if event["event"] == "update":
|
||||
yield Status.from_dict(loads(event["payload"]))
|
||||
except (WebSocketException, TimeoutError, exceptions.TimeoutError):
|
||||
else:
|
||||
logger.warn("unknown event type %r", event["event"])
|
||||
logger.debug("data: %r", event)
|
||||
except (
|
||||
WebSocketException,
|
||||
TimeoutError,
|
||||
exceptions.TimeoutError,
|
||||
) as e:
|
||||
if not reconnect:
|
||||
raise
|
||||
else:
|
||||
logger.warn("%r caught, reconnecting", e)
|
||||
else:
|
||||
logger.info(
|
||||
"WebSocket closed connection without any errors, "
|
||||
"but we're not done yet"
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue