Skip to content

Commit

Permalink
Push logging setup into the apps that *use* dsdk.utils.get_logger
Browse files Browse the repository at this point in the history
  • Loading branch information
jlubken committed Jul 15, 2020
1 parent cd7d837 commit 105bf01
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/dsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from .model import Mixin as ModelMixin
from .mongo import EvidenceMixin as MongoEvidenceMixin
from .mongo import Mixin as MongoMixin
from .mssql import CheckTablePrivileges
from .mssql import Mixin as MssqlMixin
from .service import Batch, Model, Service, Task
from .utils import (
chunks,
df_from_query_by_ids,
dump_json_file,
dump_pickle_file,
get_logger,
get_res_with_values,
load_json_file,
load_pickle_file,
retry,
Expand All @@ -23,12 +26,15 @@
"MongoMixin",
"MongoEvidenceMixin",
"MssqlMixin",
"CheckTablePrivileges",
"Service",
"Task",
"chunks",
"df_from_query_by_ids",
"dump_json_file",
"dump_pickle_file",
"get_logger",
"get_res_with_values",
"load_json_file",
"load_pickle_file",
"retry",
Expand Down
6 changes: 3 additions & 3 deletions src/dsdk/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from __future__ import annotations

from abc import ABC
from logging import INFO
from logging import getLogger
from typing import TYPE_CHECKING, Optional, cast

from configargparse import ArgParser as ArgumentParser

from .service import Model, Service
from .utils import get_logger, load_pickle_file
from .utils import load_pickle_file

logger = get_logger(__name__, INFO)
logger = getLogger(__name__)


if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions src/dsdk/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from abc import ABC
from contextlib import contextmanager
from logging import INFO
from logging import getLogger
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -19,7 +19,7 @@
from configargparse import ArgParser as ArgumentParser

from .service import Batch, Model, Service
from .utils import get_logger, retry
from .utils import retry

try:
# Since not everyone will use mongo
Expand All @@ -34,7 +34,7 @@
Database = None
AutoReconnect = None

logger = get_logger(__name__, INFO)
logger = getLogger(__name__)


if TYPE_CHECKING:
Expand Down
5 changes: 2 additions & 3 deletions src/dsdk/mssql.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

from abc import ABC
from contextlib import contextmanager
from logging import INFO
from logging import getLogger
from typing import TYPE_CHECKING, Generator, Optional, cast

from configargparse import ArgParser as ArgumentParser

from .service import Service, Task
from .utils import get_logger

logger = get_logger(__name__, INFO)
logger = getLogger(__name__)

try:
# Since not everyone will use mssql
Expand Down
6 changes: 2 additions & 4 deletions src/dsdk/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
from collections import OrderedDict
from contextlib import contextmanager
from datetime import datetime, timezone
from logging import INFO
from logging import getLogger
from sys import argv as sys_argv
from typing import Any, Dict, Generator, Optional, Sequence, Tuple, cast

from configargparse import ArgParser as ArgumentParser
from configargparse import Namespace

from .utils import get_logger

logger = get_logger(__name__, INFO)
logger = getLogger(__name__)


class Interval: # pylint: disable=too-few-public-methods
Expand Down
8 changes: 4 additions & 4 deletions src/dsdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from pandas import DataFrame
from pandas import concat as pd_concat

logger = getLogger(__name__)


def get_logger(name, level=INFO):
"""Get logger.
Expand All @@ -27,6 +29,8 @@ def get_logger(name, level=INFO):
Use this function to hide the logger implementation/config for now.
Show that the conventions demonstrated here work for the applications.
"""
result = getLogger(name)
result.setLevel(level)
formatter_string = " - ".join(
(
"%(asctime)-15s",
Expand All @@ -38,14 +42,10 @@ def get_logger(name, level=INFO):
handler = StreamHandler(stdout)
handler.setLevel(level)
handler.setFormatter(Formatter(formatter_string))
result = getLogger(name)
result.addHandler(handler)
return result


logger = get_logger(__name__)


def chunks(sequence: Sequence[Any], n: int):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(sequence), n):
Expand Down

0 comments on commit 105bf01

Please sign in to comment.