Drakulix / simplelog.rs

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

SimpleLog not working with docker in non-interactive #30

Closed max-wittig closed 5 years ago

max-wittig commented 5 years ago

Maybe I'm doing something wrong. Not sure, but when I'm using a debian docker image with my rust binary and simplelog, I get this error message. See code and trace below.

Everything works just fine, when not using docker in non-interactive mode. I'm not sure, if the library should handle the case, when something is running non-interactive?

CombinedLogger::init(vec![
        TermLogger::new(log_level, simplelog::Config::default()).expect("Could not init TermLogger"),
    ]).expect("Could not init CombinedLogger");
thread 'main' panicked at 'Could not init TermLogger', libcore/option.rs:1000:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:477
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:391
   6: rust_begin_unwind
             at libstd/panicking.rs:326
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   8: core::option::expect_failed
             at libcore/option.rs:1000
   9: bernard::main
  10: std::rt::lang_start::{{closure}}
  11: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  12: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:103
  13: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  14: main
  15: __libc_start_main
  16: _start
Drakulix commented 5 years ago

This is the reason, why TermLogger is the only one to return a Result on initializing.

It is only compatible with interactive terminals not with a normal stdout/err pipe. For that use-case you should fallback to an SimpleLogger or a WriteLogger initialized with an Stdout.

Use can test this, by trying to initialize a TermLogger and fallback in case of an error instead of using unwrap.

I hope this helps.

max-wittig commented 5 years ago

@Drakulix Thanks for your help!