Skip to content

Commit de7afaf

Browse files
Copilotjgbradley1
andcommitted
Replace custom get_logger with standard Python logging
Co-authored-by: jgbradley1 <654554+jgbradley1@users.noreply.github.com>
1 parent 948c7d1 commit de7afaf

File tree

12 files changed

+40
-56
lines changed

12 files changed

+40
-56
lines changed

docs/examples_notebooks/index_migration_to_v1.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@
202202
"metadata": {},
203203
"outputs": [],
204204
"source": [
205+
"from graphrag.index.flows.generate_text_embeddings import generate_text_embeddings\n",
206+
"\n",
205207
"from graphrag.cache.factory import CacheFactory\n",
206208
"from graphrag.callbacks.noop_workflow_callbacks import NoopWorkflowCallbacks\n",
207209
"from graphrag.config.embeddings import get_embedded_fields, get_embedding_settings\n",
208-
"from graphrag.index.flows.generate_text_embeddings import generate_text_embeddings\n",
209210
"\n",
210211
"# We only need to re-run the embeddings workflow, to ensure that embeddings for all required search fields are in place\n",
211212
"# We'll construct the context and run this function flow directly to avoid everything else\n",

examples_notebooks/community_contrib/yfiles-jupyter-graphs/graph-visualization.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"\n",
3030
"import pandas as pd\n",
3131
"import tiktoken\n",
32+
"from graphrag.query.llm.oai.chat_openai import ChatOpenAI\n",
33+
"from graphrag.query.llm.oai.embedding import OpenAIEmbedding\n",
34+
"from graphrag.query.llm.oai.typing import OpenaiApiType\n",
3235
"\n",
3336
"from graphrag.query.context_builder.entity_extraction import EntityVectorStoreKey\n",
3437
"from graphrag.query.indexer_adapters import (\n",
@@ -38,9 +41,6 @@
3841
" read_indexer_reports,\n",
3942
" read_indexer_text_units,\n",
4043
")\n",
41-
"from graphrag.query.llm.oai.chat_openai import ChatOpenAI\n",
42-
"from graphrag.query.llm.oai.embedding import OpenAIEmbedding\n",
43-
"from graphrag.query.llm.oai.typing import OpenaiApiType\n",
4444
"from graphrag.query.structured_search.local_search.mixed_context import (\n",
4545
" LocalSearchMixedContext,\n",
4646
")\n",

graphrag/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@
22
# Licensed under the MIT License
33

44
"""The GraphRAG package."""
5+
6+
import logging
7+
8+
# Configure the graphrag root logger with a default handler
9+
# This ensures that the logger hierarchy is set up correctly
10+
_root_logger = logging.getLogger("graphrag")
11+
if not _root_logger.handlers:
12+
# Add a NullHandler to prevent unconfigured logger warnings
13+
_root_logger.addHandler(logging.NullHandler())

graphrag/api/index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
from graphrag.index.typing.pipeline_run_result import PipelineRunResult
2020
from graphrag.index.typing.workflow import WorkflowFunction
2121
from graphrag.index.workflows.factory import PipelineFactory
22-
from graphrag.logger.standard_logging import get_logger
2322

2423
log = logging.getLogger(__name__)
25-
logger = get_logger("graphrag.indexing")
24+
logger = logging.getLogger("graphrag.indexing")
2625

2726

2827
async def build_index(

graphrag/api/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Backwards compatibility is not guaranteed at this time.
1818
"""
1919

20+
import logging
2021
from collections.abc import AsyncGenerator
2122
from typing import Any
2223

@@ -31,7 +32,6 @@
3132
text_unit_text_embedding,
3233
)
3334
from graphrag.config.models.graph_rag_config import GraphRagConfig
34-
from graphrag.logger.standard_logging import get_logger
3535
from graphrag.query.factory import (
3636
get_basic_search_engine,
3737
get_drift_search_engine,
@@ -55,8 +55,8 @@
5555
from graphrag.utils.cli import redact
5656

5757
# Initialize standard logger
58-
log = get_logger(__name__)
59-
logger = get_logger("graphrag.query")
58+
log = logging.getLogger(__name__)
59+
logger = logging.getLogger("graphrag.query")
6060

6161

6262
@validate_call(config={"arbitrary_types_allowed": True})

graphrag/cli/index.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from graphrag.config.load_config import load_config
1515
from graphrag.config.logging import enable_logging_with_config
1616
from graphrag.index.validate_config import validate_config_names
17-
from graphrag.logger.standard_logging import get_logger
1817
from graphrag.logger.types import LoggerType
1918
from graphrag.utils.cli import redact
2019

@@ -139,7 +138,7 @@ def _run_index(
139138
):
140139
# logger parameter is kept for CLI compatibility but unused now (uses standard logging)
141140
_ = logger # Suppress unused variable warning
142-
progress_logger = get_logger("graphrag.cli.progress")
141+
progress_logger = logging.getLogger("graphrag.cli.progress")
143142
info, error, success = _logger_helper(progress_logger)
144143

145144
if not cache:

graphrag/cli/initialize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
"""CLI implementation of the initialization subcommand."""
55

6+
import logging
67
from pathlib import Path
78

89
from graphrag.config.init_content import INIT_DOTENV, INIT_YAML
9-
from graphrag.logger.standard_logging import get_logger
1010
from graphrag.prompts.index.community_report import (
1111
COMMUNITY_REPORT_PROMPT,
1212
)
@@ -48,7 +48,7 @@ def initialize_project_at(path: Path, force: bool) -> None:
4848
ValueError
4949
If the project already exists and force is False.
5050
"""
51-
progress_logger = get_logger("graphrag.cli.initialize")
51+
progress_logger = logging.getLogger("graphrag.cli.initialize")
5252
progress_logger.info(f"Initializing project at {path}") # noqa: G004
5353
root = Path(path)
5454
if not root.exists():

graphrag/cli/prompt_tune.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44
"""CLI implementation of the prompt-tune subcommand."""
55

6+
import logging
67
from pathlib import Path
78

89
import graphrag.api as api
910
from graphrag.cli.index import _logger_helper
1011
from graphrag.config.load_config import load_config
1112
from graphrag.config.logging import enable_logging_with_config
12-
from graphrag.logger.standard_logging import get_logger
1313
from graphrag.logger.types import LoggerType
1414
from graphrag.prompt_tune.generator.community_report_summarization import (
1515
COMMUNITY_SUMMARIZATION_FILENAME,
@@ -73,7 +73,7 @@ async def prompt_tune(
7373

7474
# logger parameter is kept for CLI compatibility but unused now (uses standard logging)
7575
_ = logger # Suppress unused variable warning
76-
progress_logger = get_logger("graphrag.cli.prompt_tune")
76+
progress_logger = logging.getLogger("graphrag.cli.prompt_tune")
7777
info, error, success = _logger_helper(progress_logger)
7878

7979
enabled_logging, log_path = enable_logging_with_config(

graphrag/cli/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""CLI implementation of the query subcommand."""
55

66
import asyncio
7+
import logging
78
import sys
89
from pathlib import Path
910
from typing import TYPE_CHECKING, Any
@@ -12,16 +13,15 @@
1213
from graphrag.callbacks.noop_query_callbacks import NoopQueryCallbacks
1314
from graphrag.config.load_config import load_config
1415
from graphrag.config.models.graph_rag_config import GraphRagConfig
15-
from graphrag.logger.standard_logging import get_logger
1616
from graphrag.utils.api import create_storage_from_config
1717
from graphrag.utils.storage import load_table_from_storage, storage_has_table
1818

1919
if TYPE_CHECKING:
2020
import pandas as pd
2121

2222
# Initialize standard logger
23-
log = get_logger(__name__)
24-
logger = get_logger("graphrag.cli.query")
23+
log = logging.getLogger(__name__)
24+
logger = logging.getLogger("graphrag.cli.query")
2525

2626

2727
def run_global_search(

graphrag/index/input/factory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from graphrag.index.input.csv import load_csv
1616
from graphrag.index.input.json import load_json
1717
from graphrag.index.input.text import load_text
18-
from graphrag.logger.standard_logging import get_logger
1918
from graphrag.storage.blob_pipeline_storage import BlobPipelineStorage
2019
from graphrag.storage.file_pipeline_storage import FilePipelineStorage
2120

@@ -35,7 +34,7 @@ async def create_input(
3534
"""Instantiate input data for a pipeline."""
3635
root_dir = root_dir or ""
3736
log.info("loading input from root_dir=%s", config.base_dir)
38-
progress_reporter = progress_reporter or get_logger("graphrag.input")
37+
progress_reporter = progress_reporter or logging.getLogger("graphrag.input")
3938

4039
match config.type:
4140
case InputType.blob:

0 commit comments

Comments
 (0)