1
0
Fork 0
mirror of https://github.com/imjasonh/gcplog-rs synced 2026-07-07 00:32:41 +00:00
No description
Find a file
2025-10-16 09:09:32 -04:00
.cargo initial commit 2025-10-15 20:26:49 -04:00
.github/workflows add release workflow 2025-10-15 20:29:58 -04:00
examples initial commit 2025-10-15 20:26:49 -04:00
src Implement graceful fallback when not running on GCP 2025-10-16 12:55:58 +00:00
.gitignore initial commit 2025-10-15 20:26:49 -04:00
Cargo.toml add repository to cargo toml 2025-10-15 20:37:08 -04:00
LICENSE initial commit 2025-10-15 20:26:49 -04:00
README.md Update README.md 2025-10-15 20:39:10 -04:00

gcplog-rs

Crates.io

A Rust tracing subscriber that emits logs to stderr as newline-delimited JSON in the format expected by Google Cloud Logging.

Inspired by clog/gcp in Go

Usage

use tracing::info;

fn main() {
    // Auto-detect project ID from metadata service
    gcplog_rs::init(gcplog_rs::Config::new());

    info!("Application started");
}

With explicit project ID:

gcplog_rs::init(gcplog_rs::Config::with_project_id("my-project-123"));

With custom log level:

use tracing_subscriber::filter::LevelFilter;

gcplog_rs::init(
    gcplog_rs::Config::with_project_id("my-project-123")
        .with_level(LevelFilter::DEBUG)
);

Trace Correlation

To correlate logs with traces, create spans with a trace_id field:

use tracing::info_span;

let span = info_span!("trace_id", trace_id = %"abc123");
let _guard = span.enter();

info!("This log will include the trace ID");

Output Format

Logs are emitted as JSON:

{
  "severity": "INFO",
  "message": "Application started",
  "time": "2025-10-15T21:05:13.661Z",
  "logging.googleapis.com/sourceLocation": {
    "file": "src/main.rs",
    "line": "10",
    "function": "my_app"
  },
  "logging.googleapis.com/trace": "projects/my-project/traces/abc123"
}