forked from letta-ai/letta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: debug logs in server (letta-ai#1452) (letta-ai#1457)
Co-authored-by: Ethan Knox <[email protected]>
- Loading branch information
1 parent
78a27ed
commit 09f2e41
Showing
15 changed files
with
94 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1016,3 +1016,4 @@ pgdata/ | |
## pytest mirrors | ||
memgpt/.pytest_cache/ | ||
memgpy/pytest.ini | ||
**/**/pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ services: | |
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
target: runtime | ||
depends_on: | ||
- memgpt_db | ||
ports: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,77 @@ | ||
import logging | ||
import os | ||
import os.path | ||
from logging.config import dictConfig | ||
from logging.handlers import RotatingFileHandler | ||
from pathlib import Path | ||
from sys import stdout | ||
from typing import Optional | ||
|
||
from memgpt.constants import ( | ||
LOGGER_DEFAULT_LEVEL, | ||
LOGGER_DIR, | ||
LOGGER_FILE_BACKUP_COUNT, | ||
LOGGER_FILENAME, | ||
LOGGER_MAX_FILE_SIZE, | ||
LOGGER_NAME, | ||
) | ||
from memgpt.settings import settings | ||
|
||
# Checking if log directory exists | ||
if not os.path.exists(LOGGER_DIR): | ||
os.makedirs(LOGGER_DIR, exist_ok=True) | ||
selected_log_level = logging.DEBUG if settings.debug else logging.INFO | ||
|
||
# Create logger for MemGPT | ||
logger = logging.getLogger(LOGGER_NAME) | ||
logger.setLevel(LOGGER_DEFAULT_LEVEL) | ||
|
||
# create console handler and set level to debug | ||
console_handler = logging.StreamHandler() | ||
def _setup_logfile() -> "Path": | ||
"""ensure the logger filepath is in place | ||
# create rotatating file handler | ||
file_handler = RotatingFileHandler( | ||
os.path.join(LOGGER_DIR, LOGGER_FILENAME), maxBytes=LOGGER_MAX_FILE_SIZE, backupCount=LOGGER_FILE_BACKUP_COUNT | ||
) | ||
Returns: the logfile Path | ||
""" | ||
logfile = Path(settings.memgpt_dir / "logs" / "MemGPT.log") | ||
logfile.parent.mkdir(parents=True, exist_ok=True) | ||
logfile.touch(exist_ok=True) | ||
return logfile | ||
|
||
# create formatters | ||
console_formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s") # not datetime | ||
file_formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
|
||
# add formatter to console handler | ||
console_handler.setFormatter(console_formatter) | ||
# TODO: production logging should be much less invasive | ||
DEVELOPMENT_LOGGING = { | ||
"version": 1, | ||
"disable_existing_loggers": True, | ||
"formatters": { | ||
"standard": {"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"}, | ||
"no_datetime": { | ||
"format": "%(name)s - %(levelname)s - %(message)s", | ||
}, | ||
}, | ||
"handlers": { | ||
"console": { | ||
"level": selected_log_level, | ||
"class": "logging.StreamHandler", | ||
"stream": stdout, | ||
"formatter": "no_datetime", | ||
}, | ||
"file": { | ||
"level": "DEBUG", | ||
"class": "logging.handlers.RotatingFileHandler", | ||
"filename": _setup_logfile(), | ||
"maxBytes": 1024**2 * 10, | ||
"backupCount": 3, | ||
"formatter": "standard", | ||
}, | ||
}, | ||
"loggers": { | ||
"MemGPT": { | ||
"level": logging.DEBUG if settings.debug else logging.INFO, | ||
"handlers": [ | ||
"console", | ||
"file", | ||
], | ||
"propagate": False, | ||
}, | ||
"uvicorn": { | ||
"level": "INFO", | ||
"handlers": ["console"], | ||
"propagate": False, | ||
}, | ||
}, | ||
} | ||
|
||
# add formatter for file handler | ||
file_handler.setFormatter(file_formatter) | ||
|
||
# add ch to logger | ||
logger.addHandler(console_handler) | ||
logger.addHandler(file_handler) | ||
def get_logger(name: Optional[str] = None) -> "logging.Logger": | ||
"""returns the project logger, scoped to a child name if provided | ||
Args: | ||
name: will define a child logger | ||
""" | ||
dictConfig(DEVELOPMENT_LOGGING) | ||
parent_logger = logging.getLogger("MemGPT") | ||
if name: | ||
return parent_logger.getChild(name) | ||
return parent_logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.