Skip to content

Commit 40eeec7

Browse files
Copilotjgbradley1
andcommitted
Update init_loggers to accept GraphRagConfig instead of ReportingConfig
Co-authored-by: jgbradley1 <[email protected]>
1 parent e393874 commit 40eeec7

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

graphrag/api/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def build_index(
5050
# Register pipeline logger with the graphrag logger
5151
from graphrag.logger.standard_logging import init_loggers
5252

53-
init_loggers(config=config.reporting, root_dir=None, enable_console=False)
53+
init_loggers(config=config, root_dir=None, enable_console=False)
5454

5555
# Create a logging-based workflow callbacks for pipeline lifecycle events
5656
workflow_callbacks = LoggingWorkflowCallbacks()

graphrag/cli/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _run_index(
139139

140140
# Initialize loggers with console output enabled (CLI usage) and reporting config
141141
init_loggers(
142-
config=config.reporting,
142+
config=config,
143143
root_dir=str(config.root_dir) if config.root_dir else None,
144144
log_level=log_level,
145145
enable_console=True,

graphrag/cli/prompt_tune.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async def prompt_tune(
7575

7676
# Initialize loggers with console output enabled (CLI usage) and reporting config
7777
init_loggers(
78-
config=graph_config.reporting,
78+
config=graph_config,
7979
root_dir=str(root_path),
8080
log_level=log_level,
8181
enable_console=True,

graphrag/logger/standard_logging.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343

4444
def init_loggers(
45-
config: ReportingConfig | None = None,
45+
config: GraphRagConfig | None = None,
4646
root_dir: str | None = None,
4747
log_level: int | str = logging.INFO,
4848
enable_console: bool = False,
@@ -57,8 +57,8 @@ def init_loggers(
5757
5858
Parameters
5959
----------
60-
config : ReportingConfig | None, default=None
61-
The reporting configuration. If None, defaults to file-based reporting.
60+
config : GraphRagConfig | None, default=None
61+
The GraphRAG configuration. If None, defaults to file-based reporting.
6262
root_dir : str | None, default=None
6363
The root directory for file-based logging.
6464
log_level : Union[int, str], default=logging.INFO
@@ -75,16 +75,21 @@ def init_loggers(
7575
# Import BlobWorkflowLogger here to avoid circular imports
7676
from graphrag.logger.blob_workflow_logger import BlobWorkflowLogger
7777

78-
# If log_file is provided directly, override config to use file-based logging
78+
# Extract reporting config from GraphRagConfig if provided
79+
reporting_config: ReportingConfig
7980
if log_file:
81+
# If log_file is provided directly, override config to use file-based logging
8082
log_path = Path(log_file)
81-
config = ReportingConfig(
83+
reporting_config = ReportingConfig(
8284
type=ReportingType.file,
8385
base_dir=str(log_path.parent),
8486
)
85-
elif config is None:
87+
elif config is not None:
88+
# Use the reporting configuration from GraphRagConfig
89+
reporting_config = config.reporting
90+
else:
8691
# Default to file-based logging if no config provided (maintains backward compatibility)
87-
config = ReportingConfig(base_dir="logs", type=ReportingType.file)
92+
reporting_config = ReportingConfig(base_dir="logs", type=ReportingType.file)
8893

8994
# Convert string log level to numeric value if needed
9095
if isinstance(log_level, str):
@@ -113,7 +118,7 @@ def init_loggers(
113118

114119
# Add handlers based on configuration
115120
handler: logging.Handler
116-
match config.type:
121+
match reporting_config.type:
117122
case ReportingType.file:
118123
if log_file:
119124
# Use the specific log file provided
@@ -122,7 +127,7 @@ def init_loggers(
122127
handler = logging.FileHandler(str(log_file_path), mode="a")
123128
else:
124129
# Use the config-based file path
125-
log_dir = Path(root_dir or "") / (config.base_dir or "")
130+
log_dir = Path(root_dir or "") / (reporting_config.base_dir or "")
126131
log_dir.mkdir(parents=True, exist_ok=True)
127132
log_file_path = log_dir / "logs.txt"
128133
handler = logging.FileHandler(str(log_file_path), mode="a")
@@ -136,10 +141,10 @@ def init_loggers(
136141
logger.addHandler(handler)
137142
case ReportingType.blob:
138143
handler = BlobWorkflowLogger(
139-
config.connection_string,
140-
config.container_name,
141-
base_dir=config.base_dir,
142-
storage_account_blob_url=config.storage_account_blob_url,
144+
reporting_config.connection_string,
145+
reporting_config.container_name,
146+
base_dir=reporting_config.base_dir,
147+
storage_account_blob_url=reporting_config.storage_account_blob_url,
143148
)
144149
logger.addHandler(handler)
145150

tests/unit/logger/test_standard_logging.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99

1010
from graphrag.config.enums import ReportingType
11+
from graphrag.config.models.graph_rag_config import GraphRagConfig
1112
from graphrag.config.models.reporting_config import ReportingConfig
1213
from graphrag.logger.standard_logging import init_loggers
1314

@@ -119,7 +120,10 @@ def test_init_loggers_default_config():
119120
def test_init_loggers_file_config():
120121
"""Test that init_loggers works with file configuration."""
121122
with tempfile.TemporaryDirectory() as temp_dir:
122-
config = ReportingConfig(type=ReportingType.file, base_dir="logs")
123+
config = GraphRagConfig(
124+
root_dir=temp_dir,
125+
reporting=ReportingConfig(type=ReportingType.file, base_dir="logs")
126+
)
123127

124128
# Call init_loggers with file config
125129
init_loggers(config=config, root_dir=temp_dir, log_level="INFO")
@@ -153,7 +157,9 @@ def test_init_loggers_file_config():
153157

154158
def test_init_loggers_console_config():
155159
"""Test that init_loggers works with console configuration."""
156-
config = ReportingConfig(type=ReportingType.console)
160+
config = GraphRagConfig(
161+
reporting=ReportingConfig(type=ReportingType.console)
162+
)
157163

158164
# Call init_loggers with console config but no enable_console
159165
init_loggers(config=config, log_level="INFO", enable_console=False)
@@ -172,7 +178,9 @@ def test_init_loggers_console_config():
172178

173179
def test_init_loggers_both_console():
174180
"""Test that init_loggers doesn't duplicate console handlers."""
175-
config = ReportingConfig(type=ReportingType.console)
181+
config = GraphRagConfig(
182+
reporting=ReportingConfig(type=ReportingType.console)
183+
)
176184

177185
# Call init_loggers with both console config and enable_console=True
178186
init_loggers(config=config, log_level="INFO", enable_console=True)

0 commit comments

Comments
 (0)