Skip to content

Commit

Permalink
Merge pull request #6 from alkem-io/develop
Browse files Browse the repository at this point in the history
Release v0.0.3
  • Loading branch information
valeksiev authored Dec 18, 2024
2 parents 1c886d6 + e2afe34 commit 17322cd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
3 changes: 1 addition & 2 deletions alkemio_virtual_contributor_engine/alkemio_vc_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from aio_pika.abc import AbstractIncomingMessage

from alkemio_virtual_contributor_engine.config import env
from alkemio_virtual_contributor_engine.events.input import Input
from alkemio_virtual_contributor_engine.events.response import Response
from alkemio_virtual_contributor_engine.rabbitmq import RabbitMQ
from logger import setup_logger
from alkemio_virtual_contributor_engine.setup_logger import setup_logger


logger = setup_logger(__name__)
Expand Down
7 changes: 7 additions & 0 deletions alkemio_virtual_contributor_engine/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Env:
rabbitmq_exchange: str
rabbitmq_result_routing_key: str

log_level: str
local_path: str

def __init__(self):

# Required configurations
Expand Down Expand Up @@ -55,5 +58,9 @@ def __init__(self):
self.rabbitmq_exchange = os.getenv("RABBITMQ_EVENT_BUS_EXCHANGE", "")
self.rabbitmq_result_routing_key = os.getenv("RABBITMQ_RESULT_ROUTING_KEY", "")

self.local_path = os.getenv("LOCAL_PATH", "./")
self.log_level = os.getenv("LOG_LEVEL", "INFO")
assert self.log_level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]


env = Env()
2 changes: 1 addition & 1 deletion alkemio_virtual_contributor_engine/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import aiormq

from alkemio_virtual_contributor_engine.config import env
from logger import setup_logger
from alkemio_virtual_contributor_engine.setup_logger import setup_logger

logger = setup_logger(__name__)

Expand Down
39 changes: 39 additions & 0 deletions alkemio_virtual_contributor_engine/setup_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import sys
import io
import os
from config import env


def setup_logger(name):
logger = logging.getLogger(name)
logger.setLevel(env.log_level)

c_handler = logging.StreamHandler(
io.TextIOWrapper(sys.stdout.buffer, line_buffering=True)
)
f_handler = logging.FileHandler(
os.path.join(os.path.expanduser(env.local_path), "app.log")
)

c_handler.setLevel(env.log_level)
f_handler.setLevel(logging.WARNING)

c_format = logging.Formatter(
'{"time": "%(asctime)s", "name": %(name)r, "level": "%(levelname)s", "message": %(message)r}',
"%m-%d %H:%M:%S",
)
f_format = logging.Formatter(
'{"time": "%(asctime)s", "name": %(name)r, "level": "%(levelname)s", "message": %(message)r}',
"%m-%d %H:%M:%S",
)

c_handler.setFormatter(c_format)
f_handler.setFormatter(f_format)

logger.addHandler(c_handler)
logger.addHandler(f_handler)

logger.info(f"log level {os.path.basename(__file__)}: {env.log_level}")

return logger
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "alkemio-virtual-contributor-engine"
version = "0.0.2"
version = "0.0.3"
description = "Alkemio's generic Virtual Contributor engine"
authors = ["Vladimir Aleksiev <vladimir@alkem.io>"]
readme = "README.md"
Expand Down

0 comments on commit 17322cd

Please sign in to comment.