Skip to content

Commit 27be54a

Browse files
Add more logging messages for package (#16)
* chores: include more logging messsages for this package. * fix: fix formatting errors detected by Ruff.
1 parent e5eeae1 commit 27be54a

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

src/pkg_infra/config.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,22 @@ def load_config(config_path: str | Path | None = None) -> OmegaConf:
4949
"""
5050
logger.info('Starting configuration load')
5151
paths = resolve_config_paths()
52+
logger.debug('Resolved config paths: %s', paths)
5253
parts = [
5354
load_existing(paths['ecosystem']),
5455
read_package_default(),
5556
load_existing(paths['user']),
5657
load_existing(paths['cwd']),
5758
load_existing(paths['env']),
5859
]
60+
logger.info(
61+
'Merging configuration sources: ecosystem=%s, package=%s, user=%s, cwd=%s, env=%s',
62+
bool(paths['ecosystem'] and paths['ecosystem'].exists()),
63+
True,
64+
bool(paths['user'] and paths['user'].exists()),
65+
bool(paths['cwd'] and paths['cwd'].exists()),
66+
bool(paths['env'] and paths['env'].exists()),
67+
)
5968

6069
if config_path:
6170
custom_path = Path(config_path)
@@ -66,6 +75,8 @@ def load_config(config_path: str | Path | None = None) -> OmegaConf:
6675
logger.warning(
6776
'Custom config path does not exist: %s', custom_path
6877
)
78+
else:
79+
logger.debug('No custom config path provided')
6980

7081
config = merge_configs([p for p in parts if p is not None])
7182

@@ -88,6 +99,11 @@ def resolve_config_paths() -> dict[str, Path | None]:
8899
ecosystem_dir = Path(platformdirs.site_config_dir('pkg_infra'))
89100
user_dir = Path(platformdirs.user_config_dir('pkg_infra'))
90101
env_value = os.environ.get(ENV_VARIABLE_DEFAULT_CONFIG)
102+
if env_value is None:
103+
logger.debug(
104+
'Env var %s not set; skipping env config',
105+
ENV_VARIABLE_DEFAULT_CONFIG,
106+
)
91107

92108
paths = {
93109
'ecosystem': ecosystem_dir / ECOSYSTEM_CONFIG_FILENAME,
@@ -97,7 +113,6 @@ def resolve_config_paths() -> dict[str, Path | None]:
97113
'env': Path(env_value) if env_value else None,
98114
'custom_path': None,
99115
}
100-
logger.debug('Resolved config paths: %s', paths)
101116
return paths
102117

103118

@@ -138,6 +153,8 @@ def load_existing(path: Path | None) -> OmegaConf | None:
138153
if path and path.exists():
139154
logger.debug('Loading config file: %s', path)
140155
return OmegaConf.load(path)
156+
if path:
157+
logger.debug('Config file not found at %s; skipping', path)
141158
return None
142159

143160

@@ -150,4 +167,6 @@ def merge_configs(parts: list[OmegaConf]) -> OmegaConf:
150167
Returns:
151168
OmegaConf: The merged configuration object.
152169
"""
170+
if not parts:
171+
logger.warning('No config parts found; using empty config')
153172
return OmegaConf.merge(*parts) if parts else OmegaConf.create({})

src/pkg_infra/logger.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ def update_log_filenames_with_timestamp(
4343
"""
4444
if timestamp is None:
4545
timestamp = datetime.datetime.utcnow().strftime('%Y%m%d%H%M%S')
46+
logger.debug('Updating log filenames with timestamp: %s', timestamp)
4647

4748
def update_filename(filename: str) -> str:
4849
base, ext = os.path.splitext(filename)
49-
return f'{base}_{timestamp}{ext}'
50+
updated = f'{base}_{timestamp}{ext}'
51+
logger.debug('Updated log filename: %s -> %s', filename, updated)
52+
return updated
5053

5154
def recursive_update(d: object) -> None:
5255
if isinstance(d, dict):
@@ -78,8 +81,10 @@ def configure_loggers_from_omegaconf(
7881
return
7982

8083
if 'logging' not in merged_config:
84+
logger.error("No 'logging' section found in config.")
8185
raise ValueError("No 'logging' section found in config.")
8286

87+
logger.info('Configuring logging from merged configuration')
8388
# Always convert to a pure dict (resolves all OmegaConf nodes)
8489
log_cfg = OmegaConf.to_container(
8590
merged_config['logging'], resolve=True, structured_config_mode='dict'
@@ -107,6 +112,9 @@ def configure_loggers_from_omegaconf(
107112
filename = handler.get('filename')
108113
if filename:
109114
Path(filename).parent.mkdir(parents=True, exist_ok=True)
115+
logger.debug(
116+
'Ensured log directory exists: %s', Path(filename).parent
117+
)
110118

111119
# Create the loggers listed in the config file
112120
dictConfig(log_cfg)

src/pkg_infra/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ def validate_settings(
7373
Returns True when valid. Raises ValidationError if invalid.
7474
"""
7575
data = config
76+
_logger.debug('Validating settings schema')
7677
if OmegaConf is not None and OmegaConf.is_config(config):
7778
data = OmegaConf.to_container(config, resolve=True)
7879

7980
try:
8081
validated = Settings.model_validate(data)
81-
_logger.info('Valid schema: True')
82+
_logger.debug('Valid schema: True')
8283
if show:
8384
_logger.info(validated)
8485
return True

src/pkg_infra/session.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ def _get_location(timeout: float = 3.0) -> str | None:
177177

178178
def _get_configuration() -> object:
179179
"""Load and return the merged configuration using ConfigLoader."""
180+
logger.debug('Loading configuration via ConfigLoader')
180181
return ConfigLoader.load_config()
181182

182183

183184
def _get_app_logger(merged_config: object) -> logging.Logger:
184185
"""Get the application logger from the merged configuration object."""
186+
logger.debug('Using app logger: %s', merged_config.app.logger)
185187
return logging.getLogger(merged_config.app.logger)
186188

187189

@@ -198,6 +200,11 @@ def get_session(
198200
A Session object representing the current session.
199201
"""
200202
global _current_session
203+
logger.debug(
204+
'get_session called with workspace=%s, include_location=%s',
205+
workspace,
206+
include_location,
207+
)
201208
logger.info('Initialization of a session:')
202209
if _current_session is not None:
203210
logger.info('Reusing existing session')
@@ -219,7 +226,17 @@ def get_session(
219226
process_id = _get_process_id()
220227
now_utc, now_local = _get_time()
221228
timezone = _get_timezone(now_local)
222-
location = _get_location() if include_location else None
229+
logger.debug(
230+
'Session time initialized: utc=%s, local=%s, timezone=%s',
231+
now_utc,
232+
now_local,
233+
timezone,
234+
)
235+
if include_location:
236+
location = _get_location()
237+
else:
238+
logger.debug('Location lookup skipped')
239+
location = None
223240

224241
logger.info('Creating new session...')
225242

0 commit comments

Comments
 (0)