litellm - ✅(Solved) Fix [Bug]: LITELLM_LOG_FILE doesn't work [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23319Fetched 2026-04-08 00:37:33
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1referenced ×1

Fix Action

Fixed

PR fix notes

PR #23368: fix: implement LITELLM_LOG_FILE env var to write logs to a file

Description (problem / solution / changelog)

Problem

LITELLM_LOG_FILE is referenced in docs/discussions but never implemented — no code reads the variable, so setting it has no effect (fixes #23319).

Fix

After the StreamHandler is created in _logging.py, check for LITELLM_LOG_FILE and attach a FileHandler with the same log level and formatter to verbose_logger, verbose_router_logger, and verbose_proxy_logger:

_log_file_path = os.getenv("LITELLM_LOG_FILE")
if _log_file_path:
    _file_handler = logging.FileHandler(_log_file_path, encoding="utf-8")
    _file_handler.setLevel(numeric_level)
    ...
    verbose_logger.addHandler(_file_handler)
    ...

Errors opening the file are caught and emitted as a warning so a misconfigured path doesn't crash startup.

Fixes #23319

Changed files

  • litellm/_logging.py (modified, +16/-0)
  • litellm/model_prices_and_context_window_backup.json (modified, +30/-0)
  • model_prices_and_context_window.json (modified, +30/-0)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

This env is not implemented anywhere in code

Steps to Reproduce

  1. Set LITELLM_LOG_FILE
  2. Check output log
  3. Nothing is being produced

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

latest

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves implementing the LITELLM_LOG_FILE environment variable in the code to enable logging.

Steps to Implement the Fix

  • Set the LITELLM_LOG_FILE environment variable in your operating system or in your code before running the application.
  • Modify the logging configuration in your code to use the LITELLM_LOG_FILE environment variable.

Example code snippet in Python:

import logging
import os

# Get the log file from the environment variable
log_file = os.environ.get('LITELLM_LOG_FILE')

# Configure logging to use the log file
logging.basicConfig(filename=log_file, level=logging.INFO)

# Example log message
logging.info('This is a log message')

Verification

To verify that the fix worked, check the log file specified in the LITELLM_LOG_FILE environment variable for log messages.

Extra Tips

  • Make sure to set the LITELLM_LOG_FILE environment variable before running the application.
  • Check the log file permissions to ensure that the application has write access to the file.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING