Skip to content

Commit

Permalink
feat: log from file conf
Browse files Browse the repository at this point in the history
Signed-off-by: Avik Basu <ab93@users.noreply.github.com>
  • Loading branch information
ab93 committed Aug 29, 2023
1 parent 62364c9 commit 9914b4c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
27 changes: 27 additions & 0 deletions log.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[loggers]
keys=root, pllogger

[handlers]
keys=consoleHandler

[formatters]
keys=consoleFormatter

[logger_root]
level=INFO
handlers=consoleHandler

[logger_pllogger]
level=ERROR
handlers=consoleHandler
qualname=pytorch_lightning
propagate=0

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=consoleFormatter

[formatter_consoleFormatter]
format=%(asctime)s - %(thread)d - %(levelname)s - %(message)s
class=logging.Formatter
26 changes: 16 additions & 10 deletions numalogic/udfs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import logging
import os

from numalogic._constants import BASE_DIR
from numalogic.udfs._base import NumalogicUDF
from numalogic.udfs._config import StreamConf, PipelineConf, load_pipeline_conf
from numalogic.udfs.factory import UDFFactory, ServerFactory
from numalogic.udfs.inference import InferenceUDF
from numalogic.udfs.trainer import TrainerUDF
from numalogic.udfs.preprocess import PreprocessUDF
from numalogic.udfs.postprocess import PostprocessUDF
from numalogic.udfs.factory import UDFFactory, ServerFactory
from numalogic.udfs._config import StreamConf, PipelineConf, load_pipeline_conf
from numalogic.udfs.preprocess import PreprocessUDF
from numalogic.udfs.trainer import TrainerUDF


def set_logger() -> None:
"""Sets the logger for the UDFs."""
logging.config.fileConfig(

Check warning on line 16 in numalogic/udfs/__init__.py

View check run for this annotation

Codecov / codecov/patch

numalogic/udfs/__init__.py#L16

Added line #L16 was not covered by tests
fname=os.path.join(BASE_DIR, "log.conf"),
disable_existing_loggers=False,
)
if os.getenv("DEBUG", "false").lower() == "true":
logging.getLogger("root").setLevel(logging.DEBUG)

Check warning on line 21 in numalogic/udfs/__init__.py

View check run for this annotation

Codecov / codecov/patch

numalogic/udfs/__init__.py#L21

Added line #L21 was not covered by tests


__all__ = [
Expand All @@ -21,10 +32,5 @@
"PipelineConf",
"load_pipeline_conf",
"ServerFactory",
"set_logger",
]


if os.getenv("DEBUG"):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
3 changes: 2 additions & 1 deletion numalogic/udfs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from numalogic._constants import BASE_CONF_DIR
from numalogic.connectors.redis import get_redis_client_from_conf
from numalogic.udfs import load_pipeline_conf, UDFFactory, ServerFactory
from numalogic.udfs import load_pipeline_conf, UDFFactory, ServerFactory, set_logger

Check warning on line 7 in numalogic/udfs/__main__.py

View check run for this annotation

Codecov / codecov/patch

numalogic/udfs/__main__.py#L5-L7

Added lines #L5 - L7 were not covered by tests

LOGGER = logging.getLogger(__name__)
CONF_FILE_PATH = os.getenv(

Check warning on line 10 in numalogic/udfs/__main__.py

View check run for this annotation

Codecov / codecov/patch

numalogic/udfs/__main__.py#L9-L10

Added lines #L9 - L10 were not covered by tests
Expand All @@ -13,6 +13,7 @@


if __name__ == "__main__":
set_logger()
step = sys.argv[1]

Check warning on line 17 in numalogic/udfs/__main__.py

View check run for this annotation

Codecov / codecov/patch

numalogic/udfs/__main__.py#L16-L17

Added lines #L16 - L17 were not covered by tests

try:
Expand Down
7 changes: 3 additions & 4 deletions tests/udfs/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
from numalogic.udfs import StreamConf, PipelineConf
from numalogic.udfs.trainer import TrainerUDF


logging.basicConfig(level=logging.DEBUG)


REDIS_CLIENT = FakeStrictRedis(server=FakeServer())
KEYS = ["service-mesh", "1", "2"]


logging.basicConfig(level=logging.DEBUG)


def mock_druid_fetch_data(nrows=5000):
"""Mock druid fetch data."""
return pd.read_csv(
Expand Down

0 comments on commit 9914b4c

Please sign in to comment.