langchain-ai / opengpts

MIT License
6.44k stars 851 forks source link

Use structlog and enable persisting logs in JSONL format #332

Closed bakar-io closed 4 months ago

bakar-io commented 4 months ago

In addition to streaming logs to the console (as it was happening before), logs are now also saved to a rotated file locally. These logs are in JSONL format.

Both of the following are valid and work as expected.

import structlog

logger = structlog.get_logger(__name__)
logger.info("Hello", foo="bar")
import logging

logger = logging.getLogger(__name__)
logger.info("Hello", extra={"foo": "bar"})

Here's what gets stored in a log file: {"message": "Hello", "foo": "bar", "logger": "app.api.assistants", "level": "info", "timestamp": "2024-05-06T10:58:05.144324Z"}. Console simply displays Hello (as it would have done before this PR).