2

I developed some stuff in rust and I log some errors or warnings. I 'm using systemd_journal_logger lib to do the job. It works fine until I compile and try to use relase binary. As debug symbols are not present in it and it simply cannot log. Is there an way to make log work in this case ?

I discovered that shared_memory lib causes it

I have a simple example

use log::LevelFilter;

fn main() {
  systemd_journal_logger::init().unwrap();

  log::set_max_level( LevelFilter::Debug);

  log::warn!("A warning.");
  log::error!("An error");
}    

In my Cargo.toml I have

[dependencies]
serde =  { version = "1.0", features = ["derive"] }
serde_json = "1.0"
log = "=0.4.14"
systemd-journal-logger = "=0.3.1"

running it with

cargo run

./target/debug/mytest

or even

./target/release/mytest

works perfectly looking at journal

 journalctl -f

But if I include

 shared_memory = "0.12.2"

as a dependency

cargo build --release
./target/release/mytest

stops working

  • 2
    You can add `[profile.release] debug = true` to your `Cargo.toml` to include debug symbols in the release build. But I don't think that's the cause or fix for your problem. You might want to create a minimal reproducing code example so we can have a look… – Caesar Jan 12 '22 at 04:28
  • 1
    What do you mean it cannot do the job or simply not log because debug symbols are not present? Do you mean the `debug!` macro is not getting used in production or do you mean that your binary doesn't contain linking symbols? ( I suspect you mean the first ) – Ahmed Masud Jan 12 '22 at 05:50
  • @Caesar I'll try create an small example and put it here, but in resume if I run binary from target/debug logs go to journal trace!, warn!, error!, ..., but if I run same binary from target/release it doesnt. I've already done it and after compile still don't work – Vanderci Curvelo Junior Jan 12 '22 at 18:23
  • 1
    @Caesar I noticed what is happening but don't know how to solve. I use shared_memory in my project and because of it log to journal stops working. – Vanderci Curvelo Junior Feb 04 '22 at 02:37

1 Answers1

1

Ou, this is mean. shared_memory sets

[features]
default = ["log/release_max_level_off"]

This has since been fixed but not released, you can avoid the problem by downgrading the shared_memory version to <0.12.2, or carefully disabling the default features without breaking shared_memory's build…

shared_memory = { version = "0.12.2", default_features = false, features = ["log"] }
Caesar
  • 6,733
  • 4
  • 38
  • 44