emabee/flexi_logger

Unable to customize format to not contain timestamp

Closed this issue · 2 comments

Hi,

I've been turning this one around from one side to another and seem not to be able to get it right...

The objective was to customize formatting such as to get the with_thread formatting version minus the timestamp being logged to stderr. This because it is being logged through systemd (by capture of stdout/stderr), which already keeps track of the date and time, prepending it already... so if I go for the build-in with_thread formatter, the timestamp ends up being printed twice in each line.

My attempt; (copy&paste with_thread and modify...)

pub fn formatter(w: &mut Write, record: &LogRecord) -> Result<(), IoError>
{
    write!(
        w,
        "T[{:?}] {} [{}:{}] {}",
        thread::current().name().unwrap_or("<unnamed>"),
        record.level(),
        record.file().unwrap_or("<unnamed>"),
        record.line().unwrap_or(0),
        &record.args()
    )
}

...and the venerable main...

fn main()
{
    Logger::with_env_or_str("info")
        .format(formatter)
        .start()
        .unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
}

But to no avail. What am I doing wrong?
Any help would be much appreciated.

Best regards,
lwk

Sorry, my bad. Found the issue hidden in the cross-compilation targets and different release folders. Messed up the one modified vs the one deployed so no changes where reflected although done.

Good to know. Sorry for not responding earlier, I was effectively offline for two weeks.