Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash on openbsd with set_time_offset_to_local() #138

Open
labannah9125 opened this issue Oct 5, 2023 · 1 comment
Open

crash on openbsd with set_time_offset_to_local() #138

labannah9125 opened this issue Oct 5, 2023 · 1 comment

Comments

@labannah9125
Copy link

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.
@qarmin
Copy link

qarmin commented Oct 10, 2023

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants