Skip to content

Commit ab58444

Browse files
committed
chore: added module and function name to log format
1 parent dc30164 commit ab58444

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

superstac/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

superstac/_logging.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
PACKAGE_NAME = "superstac"
7-
LOGGING_FORMAT = f"{PACKAGE_NAME}:%(asctime)s - %(name)s - %(levelname)s - %(message)s"
7+
LOGGING_FORMAT = f"{PACKAGE_NAME}:%(asctime)s - %(module)s.%(funcName)s - %(levelname)s - %(message)s"
88

99
logger = logging.getLogger(PACKAGE_NAME)
1010

@@ -33,6 +33,12 @@ def add_file_logging(file_path=f"{PACKAGE_NAME}.log"):
3333
# Configure custom file log
3434
add_file_logging("my_log.log")
3535
"""
36+
for h in logger.handlers:
37+
if (
38+
isinstance(h, logging.FileHandler)
39+
and getattr(h, "baseFilename", None) == file_path
40+
):
41+
return
3642
file_handler = logging.FileHandler(file_path)
3743
file_formatter = logging.Formatter(LOGGING_FORMAT)
3844
file_handler.setFormatter(file_formatter)
@@ -54,5 +60,10 @@ def configure_logging(level=logging.WARNING):
5460
configure_logging(logging.INFO)
5561
"""
5662
logger.setLevel(level)
63+
if not any(isinstance(h, logging.StreamHandler) for h in logger.handlers):
64+
console_handler = logging.StreamHandler()
65+
console_handler.setLevel(level)
66+
console_handler.setFormatter(logging.Formatter(LOGGING_FORMAT))
67+
logger.addHandler(console_handler)
5768
for handler in logger.handlers:
5869
handler.setLevel(level)

superstac/catalog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import attr
55
from typing import Any, Dict, Optional, Union
66

7-
from superstac._logging import logger
87
from superstac.enums import CatalogOutputFormat
98
from superstac.exceptions import (
109
CatalogConfigFileNotFound,
@@ -14,12 +13,17 @@
1413
from superstac.models import CatalogEntry, AuthInfo
1514
import yaml
1615

16+
from superstac._logging import logger
17+
1718

1819
@attr.s(auto_attribs=True)
1920
class CatalogManager:
20-
logger.info("Initialized superstac")
21+
2122
catalogs: Dict[str, CatalogEntry] = attr.Factory(dict)
2223

24+
def __attrs_post_init__(self):
25+
logger.info("Initialized superstac")
26+
2327
def register_catalog(
2428
self,
2529
name: str,

0 commit comments

Comments
 (0)