Skip to content

Commit

Permalink
ローカル時刻でC APIのログを出す (VOICEVOX#400)
Browse files Browse the repository at this point in the history
  • Loading branch information
qryxip authored Mar 5, 2023
1 parent 3483887 commit dcd5653
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/voicevox_core_c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ directml = ["voicevox_core/directml"]

[dependencies]
voicevox_core.workspace = true
chrono = { version = "0.4.23", default-features = false, features = ["clock"] } # https://github.com/chronotope/chrono/issues/602
is-terminal = "0.4.2"
libc = "0.2.134"
once_cell.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions crates/voicevox_core_c_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use libc::c_void;
use once_cell::sync::Lazy;
use std::env;
use std::ffi::{CStr, CString};
use std::fmt;
use std::io::{self, Write};
use std::os::raw::c_char;
use std::ptr::null;
use std::sync::{Mutex, MutexGuard};
use tracing_subscriber::fmt::format::Writer;
use tracing_subscriber::EnvFilter;
use voicevox_core::AudioQueryModel;
use voicevox_core::Result;
Expand All @@ -32,11 +34,16 @@ static INTERNAL: Lazy<Mutex<Internal>> = Lazy::new(|| {
} else {
"error,voicevox_core=info,voicevox_core_c_api=info,onnxruntime=info".into()
})
.with_timer(local_time as fn(&mut Writer<'_>) -> _)
.with_ansi(out().is_terminal() && env_allows_ansi())
.with_writer(out)
.try_init()
}

fn local_time(wtr: &mut Writer<'_>) -> fmt::Result {
wtr.write_str(&chrono::Local::now().to_rfc3339())
}

fn out() -> impl IsTerminal + Write {
io::stderr()
}
Expand Down

0 comments on commit dcd5653

Please sign in to comment.