Skip to content

tracing_journald does not forward to journald if data is passed as named fields #3326

Open
@s-m-e

Description

@s-m-e

Bug Report

Version

Full tree for the below little example:

tracingtest v0.1.0 (/home/foo/Desktop/RUST/tracingtest)
├── tracing v0.1.41
│   ├── pin-project-lite v0.2.16
│   ├── tracing-attributes v0.1.30 (proc-macro)
│   │   ├── proc-macro2 v1.0.95
│   │   │   └── unicode-ident v1.0.18
│   │   ├── quote v1.0.40
│   │   │   └── proc-macro2 v1.0.95 (*)
│   │   └── syn v2.0.104
│   │       ├── proc-macro2 v1.0.95 (*)
│   │       ├── quote v1.0.40 (*)
│   │       └── unicode-ident v1.0.18
│   └── tracing-core v0.1.34
│       └── once_cell v1.21.3
├── tracing-journald v0.3.1
│   ├── libc v0.2.174
│   ├── tracing-core v0.1.34 (*)
│   └── tracing-subscriber v0.3.19
│       ├── nu-ansi-term v0.46.0
│       │   └── overload v0.1.1
│       ├── serde v1.0.219
│       ├── serde_json v1.0.140
│       │   ├── itoa v1.0.15
│       │   ├── memchr v2.7.5
│       │   ├── ryu v1.0.20
│       │   └── serde v1.0.219
│       ├── sharded-slab v0.1.7
│       │   └── lazy_static v1.5.0
│       ├── smallvec v1.15.1
│       ├── thread_local v1.1.9
│       │   └── cfg-if v1.0.1
│       ├── tracing-core v0.1.34 (*)
│       ├── tracing-log v0.2.0
│       │   ├── log v0.4.27
│       │   ├── once_cell v1.21.3
│       │   └── tracing-core v0.1.34 (*)
│       └── tracing-serde v0.2.0
│           ├── serde v1.0.219
│           └── tracing-core v0.1.34 (*)
└── tracing-subscriber v0.3.19 (*)

Platform

Linux xxx 6.8.0-60-generic _63~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 22 19:00:15 UTC 2 x86_64 x86_64 x86_64 GNU/Linux (Ubuntu 22 LTS)

Crates

Probably tracing_journald?

Description

Consider the following minimal example:

use tracing::{Level, debug, warn};
use tracing_journald::layer as journald_layer;
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::fmt::layer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::{Layer, registry};

fn tracing_init() {
    let mut layers = Vec::new();

    {
        let filter = LevelFilter::from_level(Level::DEBUG); // implicit "max level"?
        let layer = layer()
            .json()
            .with_current_span(false)
            .with_filter(filter)
            .boxed();
        layers.push(layer);
    }

    match journald_layer() {
        Ok(layer) => {
            let filter = LevelFilter::from_level(Level::WARN); // implicit "max level"?
            let layer = layer
                .with_syslog_identifier("FOO_BAR".to_string())
                .with_filter(filter)
                .boxed();
            layers.push(layer);
        }
        Err(_) => {
            panic!("failed to attached to journald");
        } // journald is typically only available on Linux systems
    }

    registry().with(layers).init();
}

fn main() {
    tracing_init();
    debug!(msg = "Goes to STDOUT (as json) as expected");
    warn!(msg = "Goes to STDOUT (as json), but not to JOURNALD, although it should?");
    warn!("Goes to both STDOUT (as json) *and* JOURNALD as expected");
}

On stdout, it results in:

{"timestamp":"2025-06-26T19:28:50.708470Z","level":"DEBUG","fields":{"msg":"Goes to STDOUT (as json) as expected"},"target":"tracingtest"}
{"timestamp":"2025-06-26T19:28:50.708506Z","level":"WARN","fields":{"msg":"Goes to STDOUT (as json), but not to JOURNALD, although it should?"},"target":"tracingtest"}
{"timestamp":"2025-06-26T19:28:50.708529Z","level":"WARN","fields":{"message":"Goes to both STDOUT (as json) *and* JOURNALD as expected"},"target":"tracingtest"}

In journald, it results in:

Jun 26 21:28:50 e3 FOO_BAR[1432418]: Goes to both STDOUT (as json) *and* JOURNALD as expected

The first call of warn! which has a field named msg instead of passing the data anonymously does not make it to journald (silently, no error or warning of any kind).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions