Logging levels
Runpod supports standard logging levels to help you control the verbosity and importance of log messages. Using appropriate logging levels makes it easier to filter and analyze logs. The logging levels available are:- DEBUG: Detailed information, typically of interest only when diagnosing problems.
- INFO: Confirmation that things are working as expected.
- WARNING: Used for unexpected events or warnings of problems in the near future (e.g.,
disk space low). - ERROR: Used for more serious problems, where the application has not been able to perform some function.
- FATAL: Used for very serious errors, indicating that the program itself may be unable to continue running.
Writing logs to the console
The easiest way to write logs is using Python’slogging library. Logs written to stdout or stderr are automatically captured by Runpod and displayed in the console.
Persistent log storage
Endpoint logs are retained for 90 days, after which they are automatically removed. Worker logs are removed when a worker terminates. If you need to retain logs beyond these periods, you can write logs to a network volume or an external service like Elasticsearch or Datadog.Writing logs to a network volume
Write logs to a network volume attached to your endpoint for long-term retention.Accessing stored logs
To access logs stored in network volumes:- Use the S3-compatible API to programmatically access log files.
- Connect to a Pod with the same network volume attached using SSH.
Structured logging
Structured logging outputs logs in a machine-readable format (typically JSON) that makes it easier to parse, search, and analyze logs programmatically. This is especially useful when exporting logs to external services or analyzing large volumes of logs.Benefits of structured logging
Structured logging provides several advantages:- Easier parsing: JSON logs can be easily parsed by log aggregation tools.
- Better search: Search for specific fields like
request_idorerror_type. - Analytics: Analyze trends, patterns, and metrics from log data.
- Integration: Export to external services like Datadog, Splunk, or Elasticsearch.
Best practices
Follow these best practices when writing logs:- Use request IDs: Include the job ID or request ID in log entries for traceability.
- Choose appropriate levels: Use DEBUG for diagnostics, INFO for normal operations, WARNING for potential issues, and ERROR for failures.
- Structure your logs: Use JSON format for easier parsing and analysis.
- Implement log rotation: Rotate log files to prevent disk space issues when using persistent storage.
- Avoid excessive logging: Excessive console logging may trigger throttling. Use persistent storage for detailed logs.