[ENG-6830] add timestamps to debug logs#5618
Conversation
There was a problem hiding this comment.
Greptile Summary
This PR adds timestamps to debug logs by modifying the print_to_log_file function in reflex/utils/console.py. The change imports the datetime module and prepends a timestamp in square brackets to all log file messages using datetime.datetime.now().
The modification only affects file-based logging - messages written to log files now include timestamps, while console output remains unchanged. This enhancement improves debugging capabilities by providing temporal context for log entries, which is particularly valuable for troubleshooting long-running processes or analyzing system behavior over time.
The change integrates well with the existing logging infrastructure in Reflex, which already separates console display from file logging functionality. The print_to_log_file function is used throughout the codebase by various logging methods (debug, info, warn, error, etc.) when file logging is enabled, so this single change adds timestamps to all file-based log messages uniformly.
Confidence score: 3/5
- This PR is generally safe to merge but has some considerations around timestamp format and timezone handling
- The score reflects potential issues with timestamp format (no timezone info) and lack of configurability, though the core functionality is sound
- The
print_to_log_filefunction inreflex/utils/console.pyneeds attention for timestamp format considerations
1 file reviewed, 2 comments
| kwargs: Keyword arguments to pass to the print function. | ||
| """ | ||
| log_file_console().print(msg, **kwargs) | ||
| log_file_console().print(f"[{datetime.datetime.now()}] {msg}", **kwargs) |
There was a problem hiding this comment.
style: Consider using a more consistent timestamp format like ISO 8601 or match the existing timestamp format used in log_file_console() (lines 108-109) for consistency
| kwargs: Keyword arguments to pass to the print function. | ||
| """ | ||
| log_file_console().print(msg, **kwargs) | ||
| log_file_console().print(f"[{datetime.datetime.now()}] {msg}", **kwargs) |
There was a problem hiding this comment.
style: datetime.datetime.now() uses local timezone. Consider using datetime.datetime.now(datetime.timezone.utc) for UTC timestamps to avoid timezone ambiguity in logs
CodSpeed Performance ReportMerging #5618 will not alter performanceComparing Summary
|
No description provided.