Skip to content

Commit 5be5434

Browse files
author
nightcityblade
committed
fix: replace print() statements with structured logging
Replace bare print() calls in production code with appropriate logging.getLogger(__name__) calls using proper log levels (info, error, debug). Fixes topoteretes#2300
1 parent c9370a8 commit 5be5434

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)