How to Log From Your Container
When running a container on SaladCloud, you can log to the standard output and standard error streams. These logs are collected and stored by SaladCloud, and exported to any configured external logging source.General Best Practices
- Use Structured Logging: Whenever possible, use structured logging (JSON format) instead of unstructured logging (plain text). This makes it easier to query and analyze your logs. This is supported by all major logging frameworks, and enables additional features when used with SaladCloud.
- Include Contextual Information: Include relevant metadata in your logs, such as user IDs, request IDs, and timestamps. This information can be invaluable for troubleshooting issues.
- Log at the Appropriate Level: Use the appropriate log level (e.g., DEBUG, INFO, WARN, ERROR) for each log message. This helps to filter and prioritize logs during analysis.
- Avoid Logging Sensitive Information: Be mindful of the data you log. Avoid logging sensitive information, such as passwords or personal data, to protect user privacy and comply with regulations.
Querying Logs
- Familiarize Yourself with the Query Language: Take the time to learn the query language used for searching logs. Understanding the syntax and available operators will help you craft effective queries.
- Use Filters Wisely: Use filters to narrow down your search results. This can include filtering by time range, log level, or specific metadata fields.
Logging Libraries
When implementing logging in your applications, consider using established logging libraries that support structured logging and can easily integrate with SaladCloud’s logging infrastructure. Some popular logging libraries include:- Winston (Node.js): A versatile logging library for Node.js applications that supports multiple transports and structured logging.
- structlog (Python): A structured logging library for Python that makes it easy to log contextual information.
severity
to indicate log level, rather
than level
. This will cause the field to get indexed more efficiently by Salad’s logging backend.