Drakulix / simplelog.rs

Simple Logging Facility for Rust
https://docs.rs/simplelog/
Apache License 2.0
414 stars 71 forks source link

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

Open goodidea-kp opened 1 year ago

goodidea-kp commented 1 year ago

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.

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()),
        };
Drakulix commented 1 year ago

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.

goodidea-kp commented 1 year ago

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...

Drakulix commented 1 year ago

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.