Skip to content

Commit d8c5ba1

Browse files
merge milestone/fix-logging-clutter into dev
2 parents 3a58908 + 5aa2e9d commit d8c5ba1

10 files changed

Lines changed: 27 additions & 15 deletions

docs/articles/users/CLIReference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ These flags are accepted by the top-level parser and apply to all commands unles
5050
| `--envs-dir` | path | Directory to store environments | `~/.hatch/envs` |
5151
| `--cache-ttl` | int | Cache time-to-live in seconds | `86400` (1 day) |
5252
| `--cache-dir` | path | Directory to store cached packages | `~/.hatch/cache` |
53+
| `--log-level` | choice | Log verbosity: `DEBUG`, `INFO`, `WARNING`, `ERROR` | `WARNING` |
5354

5455
Example:
5556

hatch/cli/__main__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def main() -> int:
972972
"""
973973
# Configure logging
974974
logging.basicConfig(
975-
level=logging.INFO,
975+
level=logging.WARNING,
976976
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
977977
)
978978

@@ -1010,8 +1010,15 @@ def main() -> int:
10101010
default=Path.home() / ".hatch" / "cache",
10111011
help="Directory to store cached packages",
10121012
)
1013+
parser.add_argument(
1014+
"--log-level",
1015+
default="WARNING",
1016+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
1017+
help="Log verbosity level (default: WARNING)",
1018+
)
10131019

10141020
args = parser.parse_args()
1021+
logging.getLogger().setLevel(getattr(logging, args.log_level))
10151022

10161023
# Initialize managers (lazy - only when needed)
10171024
from hatch.environment_manager import HatchEnvironmentManager

hatch/environment_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def __init__(
6262
"""
6363

6464
self.logger = logging.getLogger("hatch.environment_manager")
65-
self.logger.setLevel(logging.INFO)
6665
# Set up environment directories
6766
self.environments_dir = environments_dir or (Path.home() / ".hatch" / "envs")
6867
self.environments_dir.mkdir(exist_ok=True)

hatch/installers/dependency_installation_orchestrator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def __init__(
6767
registry_data (Dict[str, Any]): Registry data for dependency resolution.
6868
"""
6969
self.logger = logging.getLogger("hatch.dependency_orchestrator")
70-
self.logger.setLevel(logging.INFO)
7170
self.package_loader = package_loader
7271
self.registry_service = registry_service
7372
self.registry_data = registry_data

hatch/installers/docker_installer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from .registry import installer_registry
2121

2222
logger = logging.getLogger("hatch.installers.docker_installer")
23-
logger.setLevel(logging.INFO)
2423

2524
# Handle docker-py import with graceful fallback
2625
DOCKER_AVAILABLE = False

hatch/installers/python_installer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class PythonInstaller(DependencyInstaller):
3131
def __init__(self):
3232
"""Initialize the PythonInstaller."""
3333
self.logger = logging.getLogger("hatch.installers.python_installer")
34-
self.logger.setLevel(logging.INFO)
3534

3635
@property
3736
def installer_type(self) -> str:

hatch/installers/system_installer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class SystemInstaller(DependencyInstaller):
3333
def __init__(self):
3434
"""Initialize the SystemInstaller."""
3535
self.logger = logging.getLogger("hatch.installers.system_installer")
36-
self.logger.setLevel(logging.INFO)
3736

3837
@property
3938
def installer_type(self) -> str:

hatch/package_loader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def __init__(self, cache_dir: Optional[Path] = None):
3131
Defaults to ~/.hatch/packages.
3232
"""
3333
self.logger = logging.getLogger("hatch.package_loader")
34-
self.logger.setLevel(logging.INFO)
3534

3635
# Set up cache directory
3736
if cache_dir is None:

hatch/python_environment_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def __init__(self, environments_dir: Optional[Path] = None):
4141
Defaults to ~/.hatch/envs.
4242
"""
4343
self.logger = logging.getLogger("hatch.python_environment_manager")
44-
self.logger.setLevel(logging.INFO)
4544

4645
# Set up environment directories
4746
self.environments_dir = environments_dir or (Path.home() / ".hatch" / "envs")

hatch/registry_retriever.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@
66

77
import json
88
import logging
9+
import sys
910
import requests
1011
import datetime
1112
from pathlib import Path
1213
from typing import Dict, Any, Optional
1314

1415

16+
def _print_registry_status(msg: str) -> None:
17+
if sys.stderr.isatty():
18+
print(f"\033[2m{msg}\033[0m", end="\r", file=sys.stderr, flush=True)
19+
20+
21+
def _clear_registry_status() -> None:
22+
if sys.stderr.isatty():
23+
print(" " * 60, end="\r", file=sys.stderr, flush=True)
24+
25+
1526
class RegistryRetriever:
1627
"""Manages the retrieval and caching of the Hatch package registry.
1728
@@ -37,7 +48,6 @@ def __init__(
3748
local_registry_cache_path (Path, optional): Path to local registry file. Defaults to None.
3849
"""
3950
self.logger = logging.getLogger("hatch.registry_retriever")
40-
self.logger.setLevel(logging.INFO)
4151

4252
self.cache_ttl = cache_ttl
4353
self.simulation_mode = simulation_mode
@@ -59,7 +69,7 @@ def __init__(
5969

6070
# Use file:// URL format for local files
6171
self.registry_url = f"file://{str(self.registry_cache_path.absolute())}"
62-
self.logger.info(
72+
self.logger.debug(
6373
f"Operating in simulation mode with registry at: {self.registry_cache_path}"
6474
)
6575
else:
@@ -69,7 +79,7 @@ def __init__(
6979

7080
# We'll set the initial URL to today, but might fall back to yesterday
7181
self.registry_url = f"https://github.com/CrackingShells/Hatch-Registry/releases/download/{self.today_str}/hatch_packages_registry.json"
72-
self.logger.info(
82+
self.logger.debug(
7383
f"Operating in online mode with registry at: {self.registry_url}"
7484
)
7585

@@ -180,7 +190,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
180190
"""
181191
if self.simulation_mode:
182192
try:
183-
self.logger.info(f"Fetching registry from {self.registry_url}")
193+
self.logger.debug(f"Fetching registry from {self.registry_url}")
184194
with open(self.registry_cache_path, "r") as f:
185195
return json.load(f)
186196
except Exception as e:
@@ -193,7 +203,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
193203
self.registry_url = f"https://github.com/CrackingShells/Hatch-Registry/releases/download/{date}/hatch_packages_registry.json"
194204
self.is_delayed = False # Reset delayed flag for today's registry
195205
else:
196-
self.logger.info(
206+
self.logger.warning(
197207
f"Today's registry ({date}) not found, falling back to yesterday's"
198208
)
199209
# Fall back to yesterday's registry
@@ -211,7 +221,7 @@ def _fetch_remote_registry(self) -> Dict[str, Any]:
211221
self.is_delayed = True # Set delayed flag for yesterday's registry
212222

213223
try:
214-
self.logger.info(f"Fetching registry from {self.registry_url}")
224+
self.logger.debug(f"Fetching registry from {self.registry_url}")
215225
response = requests.get(self.registry_url, timeout=30)
216226
response.raise_for_status()
217227
return response.json()
@@ -298,8 +308,9 @@ def get_registry(self, force_refresh: bool = False) -> Dict[str, Any]:
298308
# In simulation mode, we must have a local registry file
299309
registry_data = self._read_local_cache()
300310
else:
301-
# In online mode, fetch from remote URL
311+
_print_registry_status(" Refreshing registry cache...")
302312
registry_data = self._fetch_remote_registry()
313+
_clear_registry_status()
303314

304315
# Update local cache
305316
# Note that in case of simulation mode AND default cache path,

0 commit comments

Comments
 (0)