Skip to content

Commit e91db64

Browse files
authored
Add Utils script
1 parent 5e61373 commit e91db64

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

model_scoring/utils/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ------------------------------------------------------------------------------------------------
2+
# License
3+
# ------------------------------------------------------------------------------------------------
4+
5+
# Copyright (c) 2025 LSeu-Open
6+
#
7+
# This code is licensed under the MIT License.
8+
# See LICENSE file in the root directory
9+
10+
# ------------------------------------------------------------------------------------------------
11+
# Description
12+
# ------------------------------------------------------------------------------------------------
13+
14+
"""Utility functions for the model scoring system."""

model_scoring/utils/logging.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# ------------------------------------------------------------------------------------------------
2+
# License
3+
# ------------------------------------------------------------------------------------------------
4+
5+
# Copyright (c) 2025 LSeu-Open
6+
#
7+
# This code is licensed under the MIT License.
8+
# See LICENSE file in the root directory
9+
10+
# ------------------------------------------------------------------------------------------------
11+
# Description
12+
# ------------------------------------------------------------------------------------------------
13+
14+
"""
15+
Logging configuration for the model scoring system.
16+
17+
This module provides utilities for setting up logging with standard formatting
18+
and handlers for both file and console output.
19+
"""
20+
21+
import logging
22+
from ..core.constants import LOG_FILE
23+
24+
def configure_logging(level=logging.INFO, log_file=LOG_FILE, console_output=True):
25+
"""
26+
Configure logging with both file and console output.
27+
28+
Args:
29+
level (int): Logging level (default: logging.INFO)
30+
log_file (str): Path to log file (default: from LOG_FILE constant)
31+
console_output (bool): Whether to include console output (default: True)
32+
33+
Returns:
34+
logging.Logger: Configured logger instance
35+
"""
36+
# Reset any existing handlers
37+
for handler in logging.root.handlers[:]:
38+
logging.root.removeHandler(handler)
39+
40+
# Create formatter
41+
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
42+
43+
# Create handlers
44+
handlers = []
45+
46+
# File handler
47+
file_handler = logging.FileHandler(log_file)
48+
file_handler.setFormatter(formatter)
49+
handlers.append(file_handler)
50+
51+
# Console handler (optional)
52+
if console_output:
53+
console_handler = logging.StreamHandler()
54+
console_handler.setFormatter(formatter)
55+
handlers.append(console_handler)
56+
57+
# Configure basic logging
58+
logging.basicConfig(
59+
level=level,
60+
handlers=handlers,
61+
force=True # Force override any existing configuration
62+
)
63+
64+
# Get and return logger
65+
logger = logging.getLogger(__name__)
66+
return logger
67+
68+
def configure_console_only_logging(level=logging.INFO):
69+
"""
70+
Configure logging with only console output and simplified formatting.
71+
72+
Useful for CLI applications where only immediate terminal output is needed.
73+
74+
Args:
75+
level (int): Logging level (default: logging.INFO)
76+
77+
Returns:
78+
logging.Logger: Configured logger instance
79+
"""
80+
# Reset any existing handlers
81+
for handler in logging.root.handlers[:]:
82+
logging.root.removeHandler(handler)
83+
84+
# Configure basic logging with simplified format
85+
logging.basicConfig(
86+
level=level,
87+
format='%(message)s',
88+
force=True # Force override any existing configuration
89+
)
90+
91+
# Get and return logger
92+
logger = logging.getLogger(__name__)
93+
return logger

0 commit comments

Comments
 (0)