You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
not sure why it crash but works on other platforms. removing unwrap() seems to work BUT isnt localtime.
maybe another patch from @botovq interfering to rust on the os?
% cat Cargo.toml
[package]
name = "simplelog-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
log = "0.4.20"
simplelog = "0.12.1"
% cat src/main.rs
use log::*;
use simplelog::{CombinedLogger, ConfigBuilder, LevelFilter, SimpleLogger, WriteLogger};
use std::fs;
fn main() {
let _ = setup_logger("debug");
info!("Hello world!");
}
fn setup_logger(log_level: &str) -> Result<(), Box<dyn std::error::Error>> {
let log_file_path = format!("./{}.log", env!("CARGO_PKG_NAME"));
let log_file = fs::OpenOptions::new()
.append(true)
.create(true)
.write(true)
.open(log_file_path)?;
// Split the confguration between stdout and file logging for less noisy output in the stdout
// keeping full details in log lived log files.
let mut log_stdout_config_builder = ConfigBuilder::new();
log_stdout_config_builder
.set_time_offset_to_local()
.unwrap();
let mut log_file_config_builder = ConfigBuilder::new();
log_file_config_builder
.set_time_format_rfc3339()
.set_time_offset_to_local()
.unwrap();
// Any invalid log level will simply use the default of "info".
let log_level = match log_level {
"debug" => LevelFilter::Debug,
"info" => LevelFilter::Info,
"error" => LevelFilter::Error,
"warn" => LevelFilter::Warn,
_ => LevelFilter::Info,
};
// If unable to write to the log file, only output to the terminal.
if CombinedLogger::init(vec![
SimpleLogger::new(log_level, log_stdout_config_builder.build()),
WriteLogger::new(log_level, log_file_config_builder.build(), log_file),
])
.is_err()
{
SimpleLogger::new(log_level, log_stdout_config_builder.build());
}
Ok(())
}
% RUST_BACKTRACE=1 cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/simplelog-demo`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConfigBuilder(Config { time: Error, level: Error, level_padding: Off, thread: Debug, thread_log_mode: IDs, thread_padding: Off, target: Debug, target_padding: Off, location: Trace, time_format: Custom([Hour(Hour { padding: Zero, is_12_hour_clock: false }), :, Minute(Minute { padding: Zero }), :, Second(Second { padding: Zero })]), time_offset: +00:00:00, filter_allow: [], filter_ignore: [], level_color: [None, Some(Red), Some(Yellow), Some(Blue), Some(Cyan), Some(White)], write_log_enable_colors: false })', src/main.rs:23:10
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: core::result::unwrap_failed
3: core::result::Result<T,E>::unwrap
at /usr/obj/ports/rust-1.72.1/rustc-1.72.1-src/library/core/src/result.rs:1076:23
4: simplelog_demo::setup_logger
at ./src/main.rs:21:5
5: simplelog_demo::main
at ./src/main.rs:6:13
6: core::ops::function::FnOnce::call_once
at /usr/obj/ports/rust-1.72.1/rustc-1.72.1-src/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
The text was updated successfully, but these errors were encountered:
I had similar problem on single board, custom linux device and I found solution(but not sure if this will work on openbsd)
3 possible solutions with different crates to use local time instead utc:
not sure why it crash but works on other platforms. removing unwrap() seems to work BUT isnt localtime.
maybe another patch from @botovq interfering to rust on the os?
The text was updated successfully, but these errors were encountered: