Skip to content

Commit fd636bd

Browse files
Merge pull request #21 from gregory-halverson/main
suppressing INFO level log statements on login
2 parents 43bdcc8 + d417a7c commit fd636bd

File tree

8 files changed

+48
-11
lines changed

8 files changed

+48
-11
lines changed

harmonized_landsat_sentinel/HLS1_CMR_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def __init__(
5353
working_directory = abspath(".")
5454

5555
working_directory = expanduser(working_directory)
56-
logger.info(f"HLS 2.0 working directory: {cl.dir(working_directory)}")
56+
logger.debug(f"HLS 1.0 working directory: {cl.dir(working_directory)}")
5757

5858
if download_directory is None:
5959
download_directory = join(working_directory, DOWNLOAD_DIRECTORY)
6060

61-
logger.info(f"HLS 2.0 download directory: {cl.dir(download_directory)}")
61+
logger.debug(f"HLS 1.0 download directory: {cl.dir(download_directory)}")
6262

6363
self.auth = login()
6464

harmonized_landsat_sentinel/HLS2_CMR_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def __init__(
4848
working_directory = abspath(".")
4949

5050
working_directory = expanduser(working_directory)
51-
logger.info(f"HLS 2.0 working directory: {cl.dir(working_directory)}")
51+
logger.debug(f"HLS 2.0 working directory: {cl.dir(working_directory)}")
5252

5353
if download_directory is None:
5454
download_directory = join(working_directory, DOWNLOAD_DIRECTORY)
5555

56-
logger.info(f"HLS 2.0 download directory: {cl.dir(download_directory)}")
56+
logger.debug(f"HLS 2.0 download directory: {cl.dir(download_directory)}")
5757

5858
self.auth = login()
5959

harmonized_landsat_sentinel/HLS2_earthaccess_connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ def __init__(
5454
if working_directory is None:
5555
working_directory = abspath(".")
5656

57-
# working_directory = expanduser(working_directory)
58-
logger.info(f"HLS 2.0 working directory: {cl.dir(working_directory)}")
59-
logger.info(f"HLS 2.0 download directory: {cl.dir(download_directory)}")
57+
logger.debug(f"HLS 2.0 working directory: {cl.dir(working_directory)}")
58+
logger.debug(f"HLS 2.0 download directory: {cl.dir(download_directory)}")
6059

6160
self.auth = login()
6261

harmonized_landsat_sentinel/login.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
import netrc
23
import os
34

@@ -27,6 +28,11 @@ def __init__(self):
2728
_AUTH = MockAuth()
2829
return _AUTH
2930

31+
# Temporarily suppress INFO logs from earthaccess during login
32+
earthaccess_logger = logging.getLogger('earthaccess')
33+
original_level = earthaccess_logger.level
34+
earthaccess_logger.setLevel(logging.WARNING)
35+
3036
try:
3137
# First priority: environment variables
3238
if "EARTHDATA_USERNAME" in os.environ and "EARTHDATA_PASSWORD" in os.environ:
@@ -50,3 +56,6 @@ def __init__(self):
5056

5157
except Exception as e:
5258
raise CMRServerUnreachable(e)
59+
finally:
60+
# Restore original logging level
61+
earthaccess_logger.setLevel(original_level)

harmonized_landsat_sentinel/timer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ def __exit__(self, *args, **kwargs):
2525
self.end()
2626

2727
def __repr__(self):
28-
# print("Timer.__repr__")
2928
return self.__format__(format_string=DEFAULT_FORMAT)
3029

3130
def __str__(self):
32-
# print("Timer.__str__")
3331
return self.__repr__()
3432

3533
def __format__(self, format_string=DEFAULT_FORMAT):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.0
1+
1.4.1

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "harmonized-landsat-sentinel"
7-
version = "1.4.0"
7+
version = "1.4.1"
88
description = "Harmonized Landsat Sentinel (HLS) search and download utility"
99
readme = "README.md"
1010
authors = [

test_login_logging.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Test script to demonstrate the suppression of INFO logs during earthaccess login.
4+
"""
5+
6+
import logging
7+
import os
8+
9+
# Configure logging to show INFO level messages
10+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
11+
12+
# Set up test environment variables (you would use your actual credentials)
13+
# os.environ["EARTHDATA_USERNAME"] = "your_username"
14+
# os.environ["EARTHDATA_PASSWORD"] = "your_password"
15+
16+
# Or use the test skip environment variable
17+
os.environ["SKIP_EARTHDATA_LOGIN"] = "true"
18+
19+
try:
20+
# Import your login function
21+
from harmonized_landsat_sentinel.login import login
22+
23+
print("Testing login function with suppressed earthaccess INFO logs...")
24+
auth = login()
25+
print(f"Login successful. Authenticated: {auth.authenticated}")
26+
27+
except ImportError as e:
28+
print(f"Import error: {e}")
29+
print("Make sure harmonized_landsat_sentinel is installed or in the Python path")
30+
except Exception as e:
31+
print(f"Error during login: {e}")

0 commit comments

Comments
 (0)