simplelog.rs icon indicating copy to clipboard operation
simplelog.rs copied to clipboard

attempted to set a logger after the logging system was already initialized

Open goodidea-kp opened this issue 3 years ago • 3 comments

I am getting the error: attempted to set a logger after the logging system was already initialized Logging is not working. How to fix it? Only 1 occurrence in my code, but runs from async function.

  • simplelog = 0.12.1
  • log = 0.4.17
match CombinedLogger::init(vec![
            TermLogger::new(
                LevelFilter::Warn,
                simplelog::Config::default(),
                TerminalMode::Mixed,
                ColorChoice::Auto,
            ),
            WriteLogger::new(LevelFilter::Trace, simplelog::Config::default(), logger),
        ]) {
            Ok(v) => (),
            Err(err) => println!("Log err:{}", err.to_string()),
        };

goodidea-kp avatar Mar 18 '23 20:03 goodidea-kp

Unable to tell from that small code sample.

I would suggest to attach a debugger, set a breakpoint at CombinedLogger::init and check if it really is only called once.

If it is some other crate might be initializing the log-infrastructure. In that case put a breakpoint at log::set_global_logger and figure out throw backtraces, which other crate is interfering here.

Drakulix avatar Mar 19 '23 10:03 Drakulix

My code is deployed as Docker Compose for now. Any help on how to attach a debugger on the remote? How to run the Rust app in debug mode? I know how to do it on Java, but not sure I know how to do remote debugging on Rust. I can see the terminal console very well, but the file is empty. Permissions on file structure? Not sure how to debug. Please advise...

goodidea-kp avatar Mar 19 '23 12:03 goodidea-kp

My code is deployed as Docker Compose for now. Any help on how to attach a debugger on the remote?

I am sorry, but this is a repository for a logging library, I am not here to offer general support on linux deployment and configuration.

gdb needs to run on the system the executable is running and since you want to attach at launch it would likely need to run inside the container. I strongly advise to test your application outside of docker for debugging.

How to run the Rust app in debug mode?

Compile without --release. If you compile this application as part of a larger build system, that depends.

Drakulix avatar Mar 19 '23 14:03 Drakulix