Skip to content

Commit 6f9a8a3

Browse files
committed
chore: setting default logging as json format
Signed-off-by: Caleb Siebach <caleb@indicio.tech>
1 parent 595d85d commit 6f9a8a3

3 files changed

Lines changed: 19 additions & 50 deletions

File tree

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ COPY --from=base /usr/src/app/.venv /usr/src/app/.venv
1919
ENV PATH="/usr/src/app/.venv/bin:$PATH"
2020

2121
COPY socketdock socketdock
22+
COPY socketdock/config/jsonLog.py /usr/local/lib/python3.9/jsonLog.py
2223

2324
ENTRYPOINT ["python", "-m", "socketdock" ]

socketdock/__main__.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ def configure_logging(args):
1212
# Set up logging
1313
log_config = args.log_config
1414
log_level = args.log_level
15-
log_file = args.log_file
16-
LoggingConfigurator.configure(
17-
log_config_path=log_config,
18-
log_level=log_level,
19-
log_file=log_file,
20-
)
15+
16+
try:
17+
LoggingConfigurator.configure(
18+
log_config_path=log_config,
19+
log_level=log_level,
20+
)
21+
22+
except Exception as e:
23+
raise Exception("Logger configuration failed: ", e)
2124

2225

2326
def config() -> argparse.Namespace:
@@ -38,20 +41,10 @@ def config() -> argparse.Namespace:
3841
default="INFO",
3942
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
4043
)
41-
parser.add_argument(
42-
"--log-file",
43-
dest="log_file",
44-
default=None,
45-
help=(
46-
"--log-file enables writing of logs to file, if a value is "
47-
"provided then it uses that as log file location, otherwise "
48-
"the default location in log config file is used."
49-
),
50-
)
5144
parser.add_argument(
5245
"--log-config",
5346
dest="log_config",
54-
default=None,
47+
default="/usr/src/app/socketdock/config/logging-config.yml",
5548
help="Specifies a custom logging configuration file",
5649
)
5750

socketdock/loadlogger.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
"""Logging Configurator for aca-py agent."""
1+
"""Logging Configurator for tails server."""
22

33
import io
44
import logging
55
from importlib import resources
6-
from logging.config import (
7-
dictConfigClass,
8-
)
6+
from logging.config import dictConfigClass
97
from typing import Optional
108

119
import yaml
@@ -53,60 +51,37 @@ class LoggingConfigurator:
5351

5452
@classmethod
5553
def configure(
56-
cls,
57-
log_config_path: Optional[str] = None,
58-
log_level: Optional[str] = None,
59-
log_file: Optional[str] = None,
54+
cls, log_config_path: Optional[str] = None, log_level: Optional[str] = None
6055
):
6156
"""Configure logger.
6257
6358
:param logging_config_path: str: (Default value = None) Optional path to
6459
custom logging config
6560
6661
:param log_level: str: (Default value = None)
67-
68-
:param log_file: str: (Default value = None) Optional file name to write logs to
6962
"""
7063

71-
write_to_log_file = log_file is not None or log_file == ""
72-
73-
# This is a check that requires a log file path to be provided if
74-
# --log-file is specified on startup and a config file is not.
75-
if not log_config_path and write_to_log_file and not log_file:
76-
raise ValueError(
77-
"log_file (--log-file) must be provided in single-tenant mode "
78-
"using the default config since a log file path is not set."
79-
)
80-
81-
cls._configure_logging(
82-
log_config_path=log_config_path,
83-
log_level=log_level,
84-
log_file=log_file,
85-
)
64+
cls._configure_logging(log_config_path=log_config_path, log_level=log_level)
8665

8766
@classmethod
88-
def _configure_logging(cls, log_config_path, log_level, log_file):
67+
def _configure_logging(cls, log_config_path, log_level):
8968
# Setup log config and log file if provided
90-
cls._setup_log_config_file(log_config_path, log_file)
91-
92-
# Set custom file handler
93-
if log_file:
94-
logging.root.handlers.append(logging.FileHandler(log_file, encoding="utf-8"))
69+
cls._setup_log_config_file(log_config_path)
9570

9671
# Set custom log level
9772
if log_level:
9873
logging.root.setLevel(log_level.upper())
9974

10075
@classmethod
101-
def _setup_log_config_file(cls, log_config_path, log_file):
76+
def _setup_log_config_file(cls, log_config_path):
10277
log_config, is_dict_config = cls._load_log_config(log_config_path)
10378

10479
# Setup config
10580
if not log_config:
10681
logging.basicConfig(level=logging.WARNING)
10782
logging.root.warning(f"Logging config file not found: {log_config_path}")
10883
elif is_dict_config:
109-
dictConfig(log_config, new_file_path=log_file or None)
84+
dictConfig(log_config)
11085

11186
@classmethod
11287
def _load_log_config(cls, log_config_path):

0 commit comments

Comments
 (0)