Skip to content

Commit 546a12c

Browse files
authored
fix: replace print() statements with structured logging (topoteretes#2325)
## Description Replace bare `print()` calls in production code with `logging.getLogger(__name__)` using appropriate log levels: - `logger.error()` for migration failures - `logger.info()` for success messages and user events - `logger.debug()` for verbose processing output Fixes topoteretes#2300 ### Changed files: - `cognee/run_migrations.py` — 2 print statements → logger.error / logger.info - `cognee/modules/users/get_user_manager.py` — 3 print statements → logger.info - `cognee/tasks/temporal_awareness/build_graph_with_temporal_awareness.py` — 2 print statements → logger.info / logger.debug ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Code refactoring - [ ] Other (please specify): ## Screenshots N/A ## Pre-submission Checklist - [x] **I have tested my changes thoroughly before submitting this PR** - [x] **This PR contains minimal changes necessary to address the issue/feature** - [x] My code follows the project's coding standards and style guidelines - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added necessary documentation (if applicable) - [x] All new and existing tests pass - [x] I have searched existing PRs to ensure this change hasn't been submitted already - [x] I have linked any relevant issues in the description - [x] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved logging infrastructure by replacing print statements with structured logging throughout the application, enabling better debugging and monitoring capabilities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 8eee87b + 5be5434 commit 546a12c

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

cognee/modules/users/get_user_manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import json
44
import uuid
5+
import logging
56
from typing import Optional
67
from fastapi import Depends, Request, Response
78
from fastapi_users.exceptions import UserNotExists
@@ -13,6 +14,8 @@
1314
from .get_user_db import get_user_db
1415
from .methods.get_user_by_email import get_user_by_email
1516

17+
logger = logging.getLogger(__name__)
18+
1619

1720
class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
1821
reset_password_token_secret = os.getenv(
@@ -59,17 +62,17 @@ async def on_after_login(
5962
response.headers.append("Content-Type", "application/json")
6063

6164
async def on_after_register(self, user: User, request: Optional[Request] = None):
62-
print(f"User {user.id} has registered.")
65+
logger.info("User %s has registered.", user.id)
6366

6467
async def on_after_forgot_password(
6568
self, user: User, token: str, request: Optional[Request] = None
6669
):
67-
print(f"User {user.id} has forgot their password. Reset token: {token}")
70+
logger.info("User %s has forgot their password. Reset token: %s", user.id, token)
6871

6972
async def on_after_request_verify(
7073
self, user: User, token: str, request: Optional[Request] = None
7174
):
72-
print(f"Verification requested for user {user.id}. Verification token: {token}")
75+
logger.info("Verification requested for user %s. Verification token: %s", user.id, token)
7376

7477

7578
async def get_user_manager(user_db: SQLAlchemyUserDatabase = Depends(get_user_db)):

cognee/run_migrations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import os
22
import sys
3+
import logging
34
import subprocess
45
from pathlib import Path
56
import importlib.resources as pkg_resources
67

8+
logger = logging.getLogger(__name__)
9+
710
# Assuming your package is named 'cognee' and the migrations are under 'cognee/alembic'
811
# This is a placeholder for the path logic.
912
MIGRATIONS_PACKAGE = "cognee"
@@ -42,7 +45,7 @@ async def run_migrations():
4245

4346
if migration_result.returncode != 0:
4447
migration_output = migration_result.stderr + migration_result.stdout
45-
print(f"Migration failed with unexpected error: {migration_output}")
48+
logger.error("Migration failed with unexpected error: %s", migration_output)
4649
sys.exit(1)
4750

48-
print("Migration completed successfully.")
51+
logger.info("Migration completed successfully.")

cognee/tasks/temporal_awareness/build_graph_with_temporal_awareness.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import logging
23
from typing import List
34
from datetime import datetime
45

@@ -8,6 +9,8 @@
89
from cognee.infrastructure.files.storage import get_file_storage
910
from cognee.modules.data.models import Data
1011

12+
logger = logging.getLogger(__name__)
13+
1114

1215
async def build_graph_with_temporal_awareness(data: List[Data]):
1316
text_list: List[str] = []
@@ -24,7 +27,7 @@ async def build_graph_with_temporal_awareness(data: List[Data]):
2427
graphiti = Graphiti(url, "neo4j", password)
2528

2629
await graphiti.build_indices_and_constraints()
27-
print("Graph database initialized.")
30+
logger.info("Graph database initialized.")
2831

2932
for i, text in enumerate(text_list):
3033
await graphiti.add_episode(
@@ -34,6 +37,6 @@ async def build_graph_with_temporal_awareness(data: List[Data]):
3437
source_description="input",
3538
reference_time=datetime.now(),
3639
)
37-
print(f"Added text: {text[:35]}...")
40+
logger.debug("Added text: %s...", text[:35])
3841

3942
return graphiti

0 commit comments

Comments
 (0)