Intern the relay
This commit is contained in:
parent
dc888b5958
commit
c0b8db46aa
16 changed files with 2081 additions and 1 deletions
projects/activitypub_relay/src/python/relay
35
projects/activitypub_relay/src/python/relay/logger.py
Normal file
35
projects/activitypub_relay/src/python/relay/logger.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
## Get log level and file from environment if possible
|
||||
env_log_level = os.environ.get("LOG_LEVEL", "INFO").upper()
|
||||
|
||||
try:
|
||||
env_log_file = Path(os.environ.get("LOG_FILE")).expanduser().resolve()
|
||||
|
||||
except TypeError:
|
||||
env_log_file = None
|
||||
|
||||
|
||||
## Make sure the level from the environment is valid
|
||||
try:
|
||||
log_level = getattr(logging, env_log_level)
|
||||
|
||||
except AttributeError:
|
||||
log_level = logging.INFO
|
||||
|
||||
|
||||
## Set logging config
|
||||
handlers = [logging.StreamHandler()]
|
||||
|
||||
if env_log_file:
|
||||
handlers.append(logging.FileHandler(env_log_file))
|
||||
|
||||
logging.basicConfig(
|
||||
level=log_level,
|
||||
format="[%(asctime)s] %(levelname)s: %(message)s",
|
||||
handlers=handlers,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue