Skip to content

Commit

Permalink
moving setup_logging to logging module
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandan committed Feb 20, 2024
1 parent d671dae commit 1c8cff9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
15 changes: 15 additions & 0 deletions STACpopulator/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
}


def setup_logging(logfname: str, log_level: str) -> None:
"""Setup the logger for the app.
:param logfname: name of the file to which to write log outputs
:type logfname: str
:param log_level: base logging level (e.g. "INFO")
:type log_level: str
"""
config = logconfig
config["handlers"]["file"]["filename"] = logfname
for handler in config["handlers"]:
config["handlers"][handler]["level"] = log_level
logging.config.dictConfig(config)


class JSONLogFormatter(logging.Formatter):
# From: https://github.com/mCodingLLC/VideosSampleCode/tree/master/videos/135_modern_logging
def __init__(
Expand Down
3 changes: 2 additions & 1 deletion STACpopulator/populator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
stac_host_reachable,
)
from STACpopulator.input import GenericLoader
from STACpopulator.logging import setup_logging
from STACpopulator.models import AnyGeometry
from STACpopulator.stac_utils import load_config, setup_logging, url_validate
from STACpopulator.stac_utils import load_config, url_validate

LOGGER = logging.getLogger(__name__)

Expand Down
18 changes: 0 additions & 18 deletions STACpopulator/stac_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,6 @@
import pystac
import yaml

from STACpopulator.logging import logconfig


def setup_logging(logfname: str, log_level: str) -> None:
"""Setup the logger for the app.
:param logfname: name of the file to which to write log outputs
:type logfname: str
:param log_level: base logging level (e.g. "INFO")
:type log_level: str
"""
config = logconfig
config["handlers"]["file"]["filename"] = logfname
for handler in config["handlers"]:
config["handlers"][handler]["level"] = log_level
logging.config.dictConfig(config)


LOGGER = logging.getLogger(__name__)


Expand Down

0 comments on commit 1c8cff9

Please sign in to comment.