Skip to content

Instantly share code, notes, and snippets.

@iloveitaly
Created March 25, 2024 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iloveitaly/aa616d08d582c20e717ecd047b1c8534 to your computer and use it in GitHub Desktop.
Save iloveitaly/aa616d08d582c20e717ecd047b1c8534 to your computer and use it in GitHub Desktop.
funnel all the OpenAI logs to a specific file.
def setup():
"""
Config below is subject to change
https://stackoverflow.com/questions/76256249/logging-in-the-open-ai-python-library/78214464#78214464
https://github.com/openai/openai-python/blob/de7c0e2d9375d042a42e3db6c17e5af9a5701a99/src/openai/_utils/_logs.py#L16
"""
openai_log_path = taxdocs.root / "openai.log"
openai_file_handler = logging.FileHandler(openai_log_path)
openai_logger = logging.getLogger("openai")
openai_logger.addHandler(openai_file_handler)
httpx_logger = logging.getLogger("httpx")
httpx_logger.addHandler(openai_file_handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment