Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cognee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from cognee.version import get_cognee_version

# NOTE: __version__ extraction must be at the top of the __init__.py otherwise
# there will be circular import issues
__version__ = get_cognee_version()

from .api.v1.add import add
from .api.v1.delete import delete
from .api.v1.cognify import cognify
Expand Down
25 changes: 23 additions & 2 deletions cognee/shared/logging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
import logging
import structlog
import traceback
import platform
from datetime import datetime
from pathlib import Path
import importlib.metadata

from cognee import __version__ as cognee_version

# Export common log levels
DEBUG = logging.DEBUG
Expand Down Expand Up @@ -36,6 +40,13 @@
# Maximum number of log files to keep
MAX_LOG_FILES = 10

# Version information
PYTHON_VERSION = platform.python_version()
STRUCTLOG_VERSION = structlog.__version__
COGNEE_VERSION = cognee_version

OS_INFO = f"{platform.system()} {platform.release()} ({platform.version()})"


class PlainFileHandler(logging.FileHandler):
"""A custom file handler that writes simpler plain text log entries."""
Expand Down Expand Up @@ -326,8 +337,18 @@ def emit(self, record):
# Clean up old log files, keeping only the most recent ones
cleanup_old_logs(LOGS_DIR, MAX_LOG_FILES)

# Return a configured logger
return structlog.get_logger(name if name else __name__)
# Get a configured logger and log system information
logger = structlog.get_logger(name if name else __name__)
logger.info(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to also log Cognee version here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

"Logging initialized",
python_version=PYTHON_VERSION,
structlog_version=STRUCTLOG_VERSION,
cognee_version=COGNEE_VERSION,
os_info=OS_INFO,
)

# Return the configured logger
return logger


def get_log_file_location():
Expand Down
24 changes: 24 additions & 0 deletions cognee/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os
from contextlib import suppress
import importlib.metadata
from pathlib import Path


def get_cognee_version() -> str:
"""Returns either the version of installed cognee package or the one
found in nearby pyproject.toml"""
with suppress(FileNotFoundError, StopIteration):
with open(
os.path.join(Path(__file__).parent.parent, "pyproject.toml"), encoding="utf-8"
) as pyproject_toml:
version = (
next(line for line in pyproject_toml if line.startswith("version"))
.split("=")[1]
.strip("'\"\n ")
)
# Mark the version as a local Cognee library by appending “-dev”
return f"{version}-dev"
try:
return importlib.metadata.version("cognee")
except importlib.metadata.PackageNotFoundError:
return "unknown"
Loading