Rust simplelog: Straightforward Logging for Rust Applications

The simplelog crate lives up to its name by providing Rust developers with a straightforward, easy-to-implement logging solution. As an implementation of the standard log facade, simplelog focuses on getting developers up and running quickly with minimal configuration while still offering the essential features needed for effective application logging. For projects where simplicity and quick implementation are priorities, simplelog stands out as an ideal choice.

Why simplelog Is Perfect for Many Rust Projects

The simplelog framework has gained popularity in the Rust community for several compelling reasons:

  • Truly simple setup: Get logging working with just a few lines of code
  • Multiple logger types: Choose from console, file, combined, and other logger implementations
  • Reasonable defaults: Start with sensible configurations out of the box
  • Minimal dependencies: Lightweight implementation with few external requirements
  • Standard compatibility: Works seamlessly with the log crate facade
  • Configurable when needed: Offers customization options when defaults aren't sufficient

Getting Started with simplelog

Implementing simplelog in your Rust application is exceptionally straightforward. Begin by adding the necessary dependencies to your Cargo.toml:

rust
123
[dependencies]
log = "0.4"
simplelog = "0.12"

Then set up a basic logger in your application:

rust
123567891011121314151617181920212223242526272829303132333435
use log::{error, info, debug, LevelFilter};
use simplelog::{Config, SimpleLogger, WriteLogger};
use std::fs::File;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize a simple console logger
SimpleLogger::init(LevelFilter::Info, Config::default())?;
info!("Console logging initialized");
// Or initialize a file logger
WriteLogger::init(
LevelFilter::Debug,
Config::default(),
File::create("application.log")?
)?;
// Or use CombinedLogger for multiple outputs
use simplelog::CombinedLogger;
CombinedLogger::init(vec![
SimpleLogger::new(LevelFilter::Info, Config::default()),
WriteLogger::new(
LevelFilter::Debug,
Config::default(),
File::create("application.log")?
),
])?;
// Your application code with logging
info!("Application started successfully");
debug!("Loading configuration from: config.toml");
error!("Failed to connect to database");
Ok(())
}

Enhancing simplelog with OpenTelemetry Integration

While simplelog provides the essential logging capabilities many applications need, integrating it with an OpenTelemetry native observability solution opens up powerful new possibilities for monitoring and troubleshooting. This integration transforms your simple logs into standardized telemetry data that can be collected, processed, and analyzed alongside metrics and traces.

The benefits of connecting simplelog with OpenTelemetry include:

  • Comprehensive visibility: View logs in context with other telemetry data
  • Distributed tracing integration: Correlate logs with traces across service boundaries
  • Centralized log management: Collect and analyze logs from all your applications
  • Advanced search and filtering: Quickly find relevant log entries in production
  • Alerting capabilities: Create notifications based on log patterns and anomalies

Implementing OpenTelemetry with simplelog

To integrate simplelog with OpenTelemetry, you'll need to create a custom logger that forwards log records to your OpenTelemetry collector:

rust
12356789101112131415161718192021222324
use log::{info, debug, LevelFilter};
use simplelog::{Config, SimpleLogger, SharedLogger};
use opentelemetry_log::OpenTelemetryLogger;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a standard console logger
let console_logger = SimpleLogger::new(LevelFilter::Info, Config::default());
// Create an OpenTelemetry logger
let otel_logger = OpenTelemetryLogger::new();
// Combine both loggers
use simplelog::CombinedLogger;
CombinedLogger::init(vec![
Box::new(console_logger) as Box<dyn SharedLogger>,
Box::new(otel_logger) as Box<dyn SharedLogger>,
])?;
// Logs will now flow to both the console and your OpenTelemetry platform
info!("Application started with OpenTelemetry integration");
debug!("Debug information visible in your observability platform");
Ok(())
}

Analyzing Rust simplelog OpenTelemetry Logs in Dash0

Logs can be directly routed into Dash0. Dash0 with OpenTelemetry provides the ability to filter, search, group, and triage within a simple user interface, with full keyboard support. Dash0 also gives full log context by showing trace context, the call and resource that created the log - including details like the Kubernetes Pod, server, and cloud environment.

Log AI also enhanced the logs with more semantical metadata and structure without any manual pattern declaration.

Conclusion: Simplicity Meets Modern Observability

The simplelog crate offers an ideal entry point for Rust developers seeking a no-fuss logging implementation. Its focus on simplicity and ease of use makes it particularly well-suited for smaller projects, prototypes, and applications where developer time is at a premium.

When combined with an OpenTelemetry native observability solution, simplelog becomes part of a comprehensive monitoring strategy, allowing you to maintain the simplicity you love while gaining the sophisticated observability capabilities modern operations teams demand. This combination provides both the frictionless developer experience of simplelog and the powerful insights of a complete observability platform—truly offering the best of both worlds.

Last updated: March 28, 2025