feat: added util logger OS (#841)
<!-- .github/pull_request_template.md --> ## Description <!-- Provide a clear description of the changes in this PR --> ## 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. --------- Co-authored-by: Igor Ilic <igorilic03@gmail.com> Co-authored-by: Igor Ilic <30923996+dexters1@users.noreply.github.com>
This commit is contained in:
parent
9d9ea63236
commit
4c52ef62aa
3 changed files with 53 additions and 2 deletions
|
|
@ -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.add import add
|
||||||
from .api.v1.delete import delete
|
from .api.v1.delete import delete
|
||||||
from .api.v1.cognify import cognify
|
from .api.v1.cognify import cognify
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,12 @@ import threading
|
||||||
import logging
|
import logging
|
||||||
import structlog
|
import structlog
|
||||||
import traceback
|
import traceback
|
||||||
|
import platform
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import importlib.metadata
|
||||||
|
|
||||||
|
from cognee import __version__ as cognee_version
|
||||||
|
|
||||||
# Export common log levels
|
# Export common log levels
|
||||||
DEBUG = logging.DEBUG
|
DEBUG = logging.DEBUG
|
||||||
|
|
@ -36,6 +40,13 @@ LOGS_DIR.mkdir(exist_ok=True) # Create logs dir if it doesn't exist
|
||||||
# Maximum number of log files to keep
|
# Maximum number of log files to keep
|
||||||
MAX_LOG_FILES = 10
|
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):
|
class PlainFileHandler(logging.FileHandler):
|
||||||
"""A custom file handler that writes simpler plain text log entries."""
|
"""A custom file handler that writes simpler plain text log entries."""
|
||||||
|
|
@ -326,8 +337,18 @@ def setup_logging(log_level=None, name=None):
|
||||||
# Clean up old log files, keeping only the most recent ones
|
# Clean up old log files, keeping only the most recent ones
|
||||||
cleanup_old_logs(LOGS_DIR, MAX_LOG_FILES)
|
cleanup_old_logs(LOGS_DIR, MAX_LOG_FILES)
|
||||||
|
|
||||||
# Return a configured logger
|
# Get a configured logger and log system information
|
||||||
return structlog.get_logger(name if name else __name__)
|
logger = structlog.get_logger(name if name else __name__)
|
||||||
|
logger.info(
|
||||||
|
"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():
|
def get_log_file_location():
|
||||||
|
|
|
||||||
24
cognee/version.py
Normal file
24
cognee/version.py
Normal file
|
|
@ -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…
Add table
Reference in a new issue