From 92bf98812e6853285d8a1654a2977b52b05e1851 Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Thu, 8 Jan 2026 20:41:10 +0900 Subject: [PATCH] feat: revert to use log and env_logger for logging --- Cargo.lock | 203 ++++++++++++++++++++----------- Cargo.toml | 15 +-- NEWS | 1 - capi/Cargo.toml | 4 +- capi/src/io.rs | 203 +++++++++++++++---------------- capi/src/logger.rs | 134 ++++++++++---------- fuzzer/Cargo.toml | 4 +- fuzzer/src/bin/fuzzer.rs | 2 +- fuzzer/src/bin/trieloader.rs | 4 +- src/conversion/chewing.rs | 2 +- src/dictionary/layered.rs | 2 +- src/dictionary/loader.rs | 2 +- src/dictionary/trie.rs | 2 +- src/dictionary/trie_buf.rs | 2 +- src/editor/composition_editor.rs | 2 +- src/editor/mod.rs | 2 +- src/path.rs | 2 +- 17 files changed, 307 insertions(+), 279 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f32857d5..77f308955 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.21" @@ -91,9 +100,9 @@ name = "chewing" version = "0.11.0-alpha.7" dependencies = [ "der", + "log", "rusqlite", "tempfile", - "tracing", ] [[package]] @@ -111,9 +120,9 @@ name = "chewing_capi" version = "0.11.0-alpha.7" dependencies = [ "chewing", + "env_logger", + "log", "tempfile", - "tracing", - "tracing-subscriber", ] [[package]] @@ -188,6 +197,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "env_filter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + [[package]] name = "errno" version = "0.3.14" @@ -234,8 +266,8 @@ version = "0.0.0" dependencies = [ "chewing", "chewing_capi", - "tracing", - "tracing-subscriber", + "env_logger", + "log", ] [[package]] @@ -280,6 +312,30 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "jiff" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67e8da4c49d6d9909fe03361f9b620f58898859f5c7aded68351e85e71ecf50" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0c84ee7f197eca9a86c6fd6cb771e55eb991632f15f2bc3ca6ec838929e6e78" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "js-sys" version = "0.3.83" @@ -290,12 +346,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.179" @@ -326,13 +376,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" [[package]] -name = "nu-ansi-term" -version = "0.50.3" +name = "memchr" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" -dependencies = [ - "windows-sys", -] +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "once_cell" @@ -346,32 +393,41 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "portable-atomic" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f89776e4d69bb58bc6993e99ffa1d11f228b839984854c7daeb5d37f87cbe950" + +[[package]] +name = "portable-atomic-util" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +dependencies = [ + "portable-atomic", +] + [[package]] name = "proc-macro2" -version = "1.0.104" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9695f8df41bb4f3d222c95a67532365f569318332d03d5f3f67f37b20e6ebdf0" +checksum = "535d180e0ecab6268a3e718bb9fd44db66bbbc256257165fc699dadf70d16fe7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.42" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f" +checksum = "dc74d9a594b72ae6656596548f56f667211f8a97b3d4c3d467150794690dc40a" dependencies = [ "proc-macro2", ] @@ -382,6 +438,35 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "regex" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" + [[package]] name = "roff" version = "0.2.2" @@ -423,12 +508,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] -name = "sharded-slab" -version = "0.1.7" +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ - "lazy_static", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -464,9 +560,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "2.0.113" +version = "2.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678faa00651c9eb72dd2020cbdf275d92eccb2400d568e419efdd64838145cb4" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" dependencies = [ "proc-macro2", "quote", @@ -506,47 +602,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "tracing" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" -dependencies = [ - "log", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" -dependencies = [ - "once_cell", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "thread_local", - "tracing-core", -] - [[package]] name = "unicode-ident" version = "1.0.22" diff --git a/Cargo.toml b/Cargo.toml index 957a1f2d2..1c8613d0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ include = [ [dependencies] der = { version = "0.7.7", features = ["std"] } +log = { workspace = true } rusqlite = { version = ">= 0.28.0", optional = true } -tracing = { workspace = true } [dev-dependencies] tempfile = { workspace = true } @@ -29,25 +29,16 @@ tempfile = { workspace = true } default = [] sqlite = ["dep:rusqlite"] sqlite-bundled = ["sqlite", "rusqlite/bundled"] -log = ["tracing/log"] [workspace] members = ["capi", "fuzzer", "tests/testhelper", "tools"] resolver = "3" [workspace.dependencies] +env_logger = "0.11.0" +log = "0.4.0" tempfile = "3.10.1" -[workspace.dependencies.tracing] -version = "0.1.18" -default-features = false -features = ["std", "release_max_level_info"] - -[workspace.dependencies.tracing-subscriber] -version = "0.3.0" -default-features = false -features = ["ansi", "fmt", "std"] - [profile.release] lto = true opt-level = 3 diff --git a/NEWS b/NEWS index 6e2208462..7d7d5b2bb 100644 --- a/NEWS +++ b/NEWS @@ -39,7 +39,6 @@ What's New in libchewing (unreleased) - autolearn: new phrases with break words inside will be learned both with and without the break word. - rust: simplified dictionary API. - - rust: logging now depends on tracing and tracing-subscriber. - rust: the DictionaryMut trait is merged back to the Dictionary trait. - rust: the Editor::set_editor_options now accepts a closure for setting options in place. diff --git a/capi/Cargo.toml b/capi/Cargo.toml index 208e53282..8326f9a8f 100644 --- a/capi/Cargo.toml +++ b/capi/Cargo.toml @@ -11,8 +11,8 @@ crate-type = ["rlib", "staticlib"] [dependencies] chewing = { version = "0.11.0-alpha.7", path = ".." } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } +env_logger = { workspace = true } +log = { workspace = true } [dev-dependencies] tempfile = { workspace = true } diff --git a/capi/src/io.rs b/capi/src/io.rs index 6bc0cdad8..520b2bfaf 100644 --- a/capi/src/io.rs +++ b/capi/src/io.rs @@ -1,13 +1,12 @@ use std::{ cmp::min, collections::BTreeMap, - env, ffi::{CStr, CString, c_char, c_int, c_uint, c_ushort, c_void}, mem, ops::Not, ptr::{null, null_mut}, slice, - str::{self, FromStr}, + str::{self}, sync::RwLock, }; @@ -34,11 +33,10 @@ use chewing::{ }, zhuyin::Syllable, }; -use tracing::{debug, info, level_filters::LevelFilter}; -use tracing_subscriber::{filter::Targets, layer::SubscriberExt, util::SubscriberInitExt}; +use log::{debug, info}; use crate::{ - logger::init_scoped_logging_subscriber, + logger::init_scoped_logging, public::{ CHEWING_CONVERSION_ENGINE, CHINESE_MODE, ChewingConfigData, ChewingContext, FULLSHAPE_MODE, FUZZY_CHEWING_CONVERSION_ENGINE, HALFSHAPE_MODE, IntervalType, MAX_SELKEY, @@ -170,17 +168,8 @@ pub unsafe extern "C" fn chewing_new3( >, logger_data: *mut c_void, ) -> *mut ChewingContext { - let targets = match env::var("RUST_LOG") { - Ok(var) => Targets::from_str(&var).unwrap_or_default(), - Err(_) => Targets::new(), - }; - let _ = tracing_subscriber::fmt() - .without_time() - .with_max_level(LevelFilter::TRACE) - .finish() - .with(targets) - .try_init(); - let _logger_guard = init_scoped_logging_subscriber(logger_fn, logger_data); + let _ = crate::logger::init(); + let _logger_guard = init_scoped_logging(logger_fn, logger_data); let mut dict_names: Vec = DEFAULT_DICT_NAMES.iter().map(|&n| n.to_owned()).collect(); if !enabled_dicts.is_null() { if let Ok(enabled_dicts) = unsafe { CStr::from_ptr(enabled_dicts).to_str() } { @@ -332,7 +321,7 @@ macro_rules! as_ref_or_return { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_Reset(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.clear(); OK } @@ -353,7 +342,7 @@ pub unsafe extern "C" fn chewing_Reset(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_ack(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.ack(); OK } @@ -367,7 +356,7 @@ pub unsafe extern "C" fn chewing_config_has_option( name: *const c_char, ) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let cstr = unsafe { CStr::from_ptr(name) }; let name = cstr.to_string_lossy(); @@ -403,7 +392,7 @@ pub unsafe extern "C" fn chewing_config_get_int( name: *const c_char, ) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if unsafe { chewing_config_has_option(ctx, name) } != 1 { return ERROR; @@ -456,7 +445,7 @@ pub unsafe extern "C" fn chewing_config_set_int( value: c_int, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if unsafe { chewing_config_has_option(ctx, name) } != 1 { return ERROR; @@ -585,7 +574,7 @@ pub unsafe extern "C" fn chewing_config_get_str( value: *mut *mut c_char, ) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if unsafe { chewing_config_has_option(ctx, name) } != 1 { return ERROR; @@ -632,7 +621,7 @@ pub unsafe extern "C" fn chewing_config_set_str( value: *const c_char, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if unsafe { chewing_config_has_option(ctx, name) } != 1 { return ERROR; @@ -705,7 +694,7 @@ pub unsafe extern "C" fn chewing_config_set_str( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_set_KBType(ctx: *mut ChewingContext, kbtype: c_int) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); use KeyboardLayoutCompat as KB; let kb_compat = match KB::try_from(kbtype as u8) { @@ -751,7 +740,7 @@ pub unsafe extern "C" fn chewing_set_KBType(ctx: *mut ChewingContext, kbtype: c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_get_KBType(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.kb_compat as c_int } @@ -777,7 +766,7 @@ pub unsafe extern "C" fn chewing_get_KBString(ctx: *const ChewingContext) -> *mu ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let kb_string = ctx.kb_compat.to_string(); owned_into_raw( @@ -943,7 +932,7 @@ pub unsafe extern "C" fn chewing_set_selKey( len: c_int, ) { let ctx = as_mut_or_return!(ctx); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if sel_keys.is_null() || len != 10 { return; @@ -965,7 +954,7 @@ pub unsafe extern "C" fn chewing_set_selKey( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_get_selKey(ctx: *const ChewingContext) -> *mut c_int { let ctx = as_ref_or_return!(ctx, null_mut()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let len = ctx.sel_keys.0.len(); let ptr = Box::into_raw(ctx.sel_keys.0.to_vec().into_boxed_slice()); @@ -1169,7 +1158,7 @@ pub unsafe extern "C" fn chewing_get_autoLearn(ctx: *const ChewingContext) -> c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_get_phoneSeq(ctx: *const ChewingContext) -> *mut c_ushort { let ctx = as_ref_or_return!(ctx, null_mut()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let syllables: Vec<_> = ctx .editor @@ -1194,7 +1183,7 @@ pub unsafe extern "C" fn chewing_get_phoneSeq(ctx: *const ChewingContext) -> *mu #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_get_phoneSeqLen(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor .symbols() @@ -1280,7 +1269,7 @@ pub unsafe extern "C" fn chewing_set_logger( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_userphrase_enumerate(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.userphrase_iter = Some(ctx.editor.user_dict().entries().peekable()); OK @@ -1302,7 +1291,7 @@ pub unsafe extern "C" fn chewing_userphrase_has_next( bopomofo_len: *mut c_uint, ) -> c_int { let ctx = as_mut_or_return!(ctx, FALSE); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if ctx.userphrase_iter.is_none() { return 0; @@ -1353,7 +1342,7 @@ pub unsafe extern "C" fn chewing_userphrase_get( bopomofo_len: c_uint, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if ctx.userphrase_iter.is_none() { return -1; @@ -1403,7 +1392,7 @@ pub unsafe extern "C" fn chewing_userphrase_add( bopomofo_buf: *const c_char, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let syllables = match unsafe { str_from_ptr_with_nul(bopomofo_buf) } { Some(bopomofo) => bopomofo @@ -1440,7 +1429,7 @@ pub unsafe extern "C" fn chewing_userphrase_remove( bopomofo_buf: *const c_char, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); // return FALSE when phrase does not exist is C API only behavior if unsafe { chewing_userphrase_lookup(ctx, phrase_buf, bopomofo_buf) } != TRUE { @@ -1478,7 +1467,7 @@ pub unsafe extern "C" fn chewing_userphrase_lookup( bopomofo_buf: *const c_char, ) -> c_int { let ctx = as_mut_or_return!(ctx, FALSE); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let syllables = match unsafe { str_from_ptr_with_nul(bopomofo_buf) } { Some(bopomofo) => bopomofo @@ -1519,7 +1508,7 @@ pub unsafe extern "C" fn chewing_userphrase_lookup( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_first(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return -1; @@ -1544,7 +1533,7 @@ pub unsafe extern "C" fn chewing_cand_list_first(ctx: *mut ChewingContext) -> c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_last(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return -1; @@ -1564,7 +1553,7 @@ pub unsafe extern "C" fn chewing_cand_list_last(ctx: *mut ChewingContext) -> c_i #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_has_next(ctx: *mut ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, FALSE); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return 0; @@ -1583,7 +1572,7 @@ pub unsafe extern "C" fn chewing_cand_list_has_next(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_has_prev(ctx: *mut ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, FALSE); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return 0; @@ -1607,7 +1596,7 @@ pub unsafe extern "C" fn chewing_cand_list_has_prev(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_next(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return -1; @@ -1633,7 +1622,7 @@ pub unsafe extern "C" fn chewing_cand_list_next(ctx: *mut ChewingContext) -> c_i #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_list_prev(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return -1; @@ -1658,7 +1647,7 @@ pub unsafe extern "C" fn chewing_cand_list_prev(ctx: *mut ChewingContext) -> c_i #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_commit_preedit_buf(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if ctx.editor.is_selecting() { return ERROR; @@ -1684,7 +1673,7 @@ pub unsafe extern "C" fn chewing_commit_preedit_buf(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_clean_preedit_buf(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if ctx.editor.is_selecting() { return ERROR; @@ -1708,7 +1697,7 @@ pub unsafe extern "C" fn chewing_clean_preedit_buf(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_clean_bopomofo_buf(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.clear_syllable_editor(); OK @@ -1786,7 +1775,7 @@ pub unsafe extern "C" fn chewing_handle_KeyboardEvent( state: u32, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); // XXX hack for selkey let key = if ctx.editor.is_selecting() { @@ -1842,7 +1831,7 @@ pub unsafe extern "C" fn chewing_handle_KeyboardEvent( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Space(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_SPACE, @@ -1860,7 +1849,7 @@ pub unsafe extern "C" fn chewing_handle_Space(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Esc(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_ESC, @@ -1878,7 +1867,7 @@ pub unsafe extern "C" fn chewing_handle_Esc(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Enter(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_ENTER, @@ -1896,7 +1885,7 @@ pub unsafe extern "C" fn chewing_handle_Enter(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Del(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_DELETE, @@ -1914,7 +1903,7 @@ pub unsafe extern "C" fn chewing_handle_Del(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Backspace(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_BACKSPACE, @@ -1932,7 +1921,7 @@ pub unsafe extern "C" fn chewing_handle_Backspace(ctx: *mut ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Tab(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_TAB, @@ -1950,7 +1939,7 @@ pub unsafe extern "C" fn chewing_handle_Tab(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_ShiftLeft(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent( KeyboardEvent::builder() @@ -1970,7 +1959,7 @@ pub unsafe extern "C" fn chewing_handle_ShiftLeft(ctx: *mut ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Left(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_LEFT, @@ -1988,7 +1977,7 @@ pub unsafe extern "C" fn chewing_handle_Left(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_ShiftRight(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent( KeyboardEvent::builder() @@ -2008,7 +1997,7 @@ pub unsafe extern "C" fn chewing_handle_ShiftRight(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Right(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_RIGHT, @@ -2029,7 +2018,7 @@ pub unsafe extern "C" fn chewing_handle_Right(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Up(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_UP, @@ -2047,7 +2036,7 @@ pub unsafe extern "C" fn chewing_handle_Up(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Home(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_HOME, @@ -2065,7 +2054,7 @@ pub unsafe extern "C" fn chewing_handle_Home(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_End(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_END, @@ -2083,7 +2072,7 @@ pub unsafe extern "C" fn chewing_handle_End(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_PageUp(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_PAGEUP, @@ -2101,7 +2090,7 @@ pub unsafe extern "C" fn chewing_handle_PageUp(ctx: *mut ChewingContext) -> c_in #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_PageDown(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_PAGEDOWN, @@ -2121,7 +2110,7 @@ pub unsafe extern "C" fn chewing_handle_PageDown(ctx: *mut ChewingContext) -> c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Down(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent(KeyboardEvent { code: KEY_DOWN, @@ -2139,7 +2128,7 @@ pub unsafe extern "C" fn chewing_handle_Down(ctx: *mut ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Capslock(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent( KeyboardEvent::builder() @@ -2161,7 +2150,7 @@ pub unsafe extern "C" fn chewing_handle_Capslock(ctx: *mut ChewingContext) -> c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Default(ctx: *mut ChewingContext, key: c_int) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let evt = map_ascii(&ctx.keymap, key as u8); @@ -2179,7 +2168,7 @@ pub unsafe extern "C" fn chewing_handle_Default(ctx: *mut ChewingContext, key: c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_CtrlNum(ctx: *mut ChewingContext, key: c_int) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let (code, ksym) = match key as u8 { b'0' => (KEY_0, SYM_0), @@ -2213,7 +2202,7 @@ pub unsafe extern "C" fn chewing_handle_CtrlNum(ctx: *mut ChewingContext, key: c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_ShiftSpace(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.process_keyevent( KeyboardEvent::builder() @@ -2233,7 +2222,7 @@ pub unsafe extern "C" fn chewing_handle_ShiftSpace(ctx: *mut ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_DblTab(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); // todo!() OK @@ -2250,7 +2239,7 @@ pub unsafe extern "C" fn chewing_handle_DblTab(ctx: *mut ChewingContext) -> c_in #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_handle_Numlock(ctx: *mut ChewingContext, key: c_int) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let (code, ksym) = match key as u8 { b'0' => (KEY_KP0, SYM_KP0), @@ -2291,7 +2280,7 @@ pub unsafe extern "C" fn chewing_handle_Numlock(ctx: *mut ChewingContext, key: c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_commit_Check(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); !ctx.editor.display_commit().is_empty() as c_int } @@ -2315,7 +2304,7 @@ pub unsafe extern "C" fn chewing_commit_String(ctx: *const ChewingContext) -> *m ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let buffer = ctx.editor.display_commit(); let cstr = match CString::new(buffer) { @@ -2337,7 +2326,7 @@ pub unsafe extern "C" fn chewing_commit_String(ctx: *const ChewingContext) -> *m #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_commit_String_static(ctx: *const ChewingContext) -> *const c_char { let ctx = as_mut_or_return!(ctx.cast_mut(), global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); copy_cstr(&mut ctx.commit_buf, ctx.editor.display_commit()) } @@ -2361,7 +2350,7 @@ pub unsafe extern "C" fn chewing_buffer_String(ctx: *const ChewingContext) -> *m ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let buffer = ctx.editor.display(); let cstr = match CString::new(buffer) { @@ -2383,7 +2372,7 @@ pub unsafe extern "C" fn chewing_buffer_String(ctx: *const ChewingContext) -> *m #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_buffer_String_static(ctx: *const ChewingContext) -> *const c_char { let ctx = as_mut_or_return!(ctx.cast_mut(), global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); copy_cstr(&mut ctx.preedit_buf, &ctx.editor.display()) } @@ -2398,7 +2387,7 @@ pub unsafe extern "C" fn chewing_buffer_String_static(ctx: *const ChewingContext #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_buffer_Check(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); !ctx.editor.is_empty() as c_int } @@ -2416,7 +2405,7 @@ pub unsafe extern "C" fn chewing_buffer_Check(ctx: *const ChewingContext) -> c_i #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_buffer_Len(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.len() as c_int } @@ -2435,7 +2424,7 @@ pub unsafe extern "C" fn chewing_bopomofo_String_static( ctx: *const ChewingContext, ) -> *const c_char { let ctx = as_mut_or_return!(ctx.cast_mut(), global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); copy_cstr(&mut ctx.bopomofo_buf, &ctx.editor.syllable_buffer_display()) } @@ -2459,7 +2448,7 @@ pub unsafe extern "C" fn chewing_bopomofo_String(ctx: *const ChewingContext) -> ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let buffer = ctx.editor.syllable_buffer_display(); let cstr = match CString::new(buffer) { @@ -2479,7 +2468,7 @@ pub unsafe extern "C" fn chewing_bopomofo_String(ctx: *const ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_bopomofo_Check(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.entering_syllable() as c_int } @@ -2492,7 +2481,7 @@ pub unsafe extern "C" fn chewing_bopomofo_Check(ctx: *const ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cursor_Current(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.cursor() as c_int } @@ -2510,7 +2499,7 @@ pub unsafe extern "C" fn chewing_cursor_Current(ctx: *const ChewingContext) -> c #[deprecated(note = "The chewing_cand_TotalPage function could achieve the same effect.")] pub unsafe extern "C" fn chewing_cand_CheckDone(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if ctx.editor.is_selecting() { FALSE @@ -2531,7 +2520,7 @@ pub unsafe extern "C" fn chewing_cand_CheckDone(ctx: *const ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_TotalPage(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.total_page().unwrap_or_default() as c_int } @@ -2546,7 +2535,7 @@ pub unsafe extern "C" fn chewing_cand_TotalPage(ctx: *const ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_ChoicePerPage(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.editor_options().candidates_per_page as c_int } @@ -2559,7 +2548,7 @@ pub unsafe extern "C" fn chewing_cand_ChoicePerPage(ctx: *const ChewingContext) #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_TotalChoice(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.all_candidates() { Ok(candidates) => candidates.len() as c_int, @@ -2585,7 +2574,7 @@ pub unsafe extern "C" fn chewing_cand_TotalChoice(ctx: *const ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_CurrentPage(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.current_page_no().unwrap_or_default() as c_int } @@ -2603,7 +2592,7 @@ pub unsafe extern "C" fn chewing_cand_CurrentPage(ctx: *const ChewingContext) -> #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_Enumerate(ctx: *mut ChewingContext) { let ctx = as_mut_or_return!(ctx); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if let Ok(candidates) = ctx.editor.paginated_candidates() { debug!("candidates: {candidates:?}"); @@ -2625,7 +2614,7 @@ pub unsafe extern "C" fn chewing_cand_Enumerate(ctx: *mut ChewingContext) { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_hasNext(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if !ctx.editor.is_selecting() { return FALSE; @@ -2656,7 +2645,7 @@ pub unsafe extern "C" fn chewing_cand_String(ctx: *mut ChewingContext) -> *mut c ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.cand_iter.as_mut().and_then(|it| it.next()) { Some(phrase) => { @@ -2684,7 +2673,7 @@ pub unsafe extern "C" fn chewing_cand_String(ctx: *mut ChewingContext) -> *mut c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_String_static(ctx: *mut ChewingContext) -> *const c_char { let ctx = as_mut_or_return!(ctx, global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.cand_iter.as_mut().and_then(|it| it.next()) { Some(phrase) => copy_cstr(&mut ctx.cand_buf, &phrase), @@ -2716,7 +2705,7 @@ pub unsafe extern "C" fn chewing_cand_string_by_index( ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if let Ok(phrases) = ctx.editor.all_candidates() { if let Some(phrase) = phrases.get(index as usize) { @@ -2747,7 +2736,7 @@ pub unsafe extern "C" fn chewing_cand_string_by_index_static( index: c_int, ) -> *const c_char { let ctx = as_mut_or_return!(ctx, global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); if let Ok(phrases) = ctx.editor.all_candidates() { if let Some(phrase) = phrases.get(index as usize) { @@ -2777,7 +2766,7 @@ pub unsafe extern "C" fn chewing_cand_choose_by_index( index: c_int, ) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.select(index as usize) { Ok(_) => OK, @@ -2797,7 +2786,7 @@ pub unsafe extern "C" fn chewing_cand_choose_by_index( #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_open(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.start_selecting() { Ok(_) => OK, @@ -2815,7 +2804,7 @@ pub unsafe extern "C" fn chewing_cand_open(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_cand_close(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.cancel_selecting() { Ok(_) => OK, @@ -2836,7 +2825,7 @@ pub unsafe extern "C" fn chewing_cand_close(ctx: *mut ChewingContext) -> c_int { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_interval_Enumerate(ctx: *mut ChewingContext) { let ctx = as_mut_or_return!(ctx); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.interval_iter = Some( (Box::new(ctx.editor.intervals().filter(|it| it.is_phrase)) @@ -2855,7 +2844,7 @@ pub unsafe extern "C" fn chewing_interval_Enumerate(ctx: *mut ChewingContext) { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_interval_hasNext(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.interval_iter .as_mut() @@ -2875,7 +2864,7 @@ pub unsafe extern "C" fn chewing_interval_hasNext(ctx: *mut ChewingContext) -> c #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_interval_Get(ctx: *mut ChewingContext, it: *mut IntervalType) { let ctx = as_mut_or_return!(ctx); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let it = unsafe { match it.as_mut() { @@ -2901,7 +2890,7 @@ pub unsafe extern "C" fn chewing_interval_Get(ctx: *mut ChewingContext, it: *mut #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_aux_Check(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); !ctx.editor.notification().is_empty() as c_int } @@ -2919,7 +2908,7 @@ pub unsafe extern "C" fn chewing_aux_Check(ctx: *const ChewingContext) -> c_int #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_aux_Length(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.editor.notification().chars().count() as c_int } @@ -2943,7 +2932,7 @@ pub unsafe extern "C" fn chewing_aux_String(ctx: *const ChewingContext) -> *mut Some(ctx) => ctx, None => return owned_into_raw(Owned::CString, CString::default().into_raw()), }; - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let cstring = CString::new(ctx.editor.notification()).expect("notification should be valid UTF-8"); @@ -2962,7 +2951,7 @@ pub unsafe extern "C" fn chewing_aux_String(ctx: *const ChewingContext) -> *mut #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_aux_String_static(ctx: *const ChewingContext) -> *const c_char { let ctx = as_mut_or_return!(ctx.cast_mut(), global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); copy_cstr(&mut ctx.aux_buf, ctx.editor.notification()) } @@ -2977,7 +2966,7 @@ pub unsafe extern "C" fn chewing_aux_String_static(ctx: *const ChewingContext) - #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_keystroke_CheckIgnore(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.last_key_behavior() { EditorKeyBehavior::Ignore => TRUE, @@ -2999,7 +2988,7 @@ pub unsafe extern "C" fn chewing_keystroke_CheckIgnore(ctx: *const ChewingContex #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_keystroke_CheckAbsorb(ctx: *const ChewingContext) -> c_int { let ctx = as_ref_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.editor.last_key_behavior() { EditorKeyBehavior::Absorb => TRUE, @@ -3034,7 +3023,7 @@ pub unsafe extern "C" fn chewing_kbtype_Total(_ctx: *const ChewingContext) -> c_ #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_kbtype_Enumerate(ctx: *mut ChewingContext) { let ctx = as_mut_or_return!(ctx); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.kbcompat_iter = Some( (Box::new((0..).map_while(|id| KeyboardLayoutCompat::try_from(id).ok())) @@ -3053,7 +3042,7 @@ pub unsafe extern "C" fn chewing_kbtype_Enumerate(ctx: *mut ChewingContext) { #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_kbtype_hasNext(ctx: *mut ChewingContext) -> c_int { let ctx = as_mut_or_return!(ctx, ERROR); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); ctx.kbcompat_iter .as_mut() @@ -3082,7 +3071,7 @@ pub unsafe extern "C" fn chewing_kbtype_String(ctx: *mut ChewingContext) -> *mut ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.kbcompat_iter.as_mut().and_then(|it| it.next()) { Some(kb_compat) => { @@ -3110,7 +3099,7 @@ pub unsafe extern "C" fn chewing_kbtype_String(ctx: *mut ChewingContext) -> *mut #[unsafe(no_mangle)] pub unsafe extern "C" fn chewing_kbtype_String_static(ctx: *mut ChewingContext) -> *const c_char { let ctx = as_mut_or_return!(ctx, global_empty_cstr()); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); match ctx.kbcompat_iter.as_mut().and_then(|it| it.next()) { Some(kb_compat) => copy_cstr(&mut ctx.kbtype_buf, &kb_compat.to_string()), @@ -3164,7 +3153,7 @@ pub unsafe extern "C" fn chewing_zuin_String( ctx, owned_into_raw(Owned::CString, CString::default().into_raw()) ); - let _logger_guard = init_scoped_logging_subscriber(ctx.logger_fn, ctx.logger_data); + let _logger_guard = init_scoped_logging(ctx.logger_fn, ctx.logger_data); let syllable = ctx.editor.syllable_buffer_display(); unsafe { diff --git a/capi/src/logger.rs b/capi/src/logger.rs index f9c9d2448..5b56f165b 100644 --- a/capi/src/logger.rs +++ b/capi/src/logger.rs @@ -1,101 +1,95 @@ use std::{ + cell::RefCell, ffi::{CString, c_char, c_int, c_void}, - io::Write, - mem, }; -use tracing::Level; -use tracing::dispatcher::DefaultGuard; -use tracing_subscriber::{fmt::MakeWriter, util::SubscriberInitExt}; +use env_logger::Logger as EnvLogger; +use log::{Level, LevelFilter, Log, Metadata, Record, SetLoggerError}; use crate::setup::{ CHEWING_LOG_DEBUG, CHEWING_LOG_ERROR, CHEWING_LOG_INFO, CHEWING_LOG_VERBOSE, CHEWING_LOG_WARN, }; +thread_local! { + static CTX_LOGGER: RefCell> = const { RefCell::new(vec![]) }; +} + pub(crate) type ExternLoggerFn = unsafe extern "C" fn(data: *mut c_void, level: c_int, fmt: *const c_char, arg: ...); -#[derive(Clone)] pub(crate) struct ChewingLogger { - level: c_int, - buffer: Vec, - logger_fn: ExternLoggerFn, - logger_data: *mut c_void, + env_logger: EnvLogger, +} + +pub(crate) struct ChewingLoggerGuard; + +pub(crate) fn init() -> Result<(), SetLoggerError> { + log::set_boxed_logger(Box::new(ChewingLogger::new())) + .map(|()| log::set_max_level(LevelFilter::Trace)) +} + +pub(crate) fn init_scoped_logging( + logger_fn: Option, + data: *mut c_void, +) -> ChewingLoggerGuard { + if let Some(logger_fn) = logger_fn { + CTX_LOGGER.with_borrow_mut(|ctx_logger| ctx_logger.push((logger_fn, data))); + } + ChewingLoggerGuard } impl ChewingLogger { - pub(crate) fn new(logger_fn: ExternLoggerFn, logger_data: *mut c_void) -> ChewingLogger { + pub(crate) fn new() -> ChewingLogger { ChewingLogger { - level: 0, - buffer: vec![], - logger_fn, - logger_data, + env_logger: EnvLogger::from_default_env(), } } } -unsafe impl Send for ChewingLogger {} -unsafe impl Sync for ChewingLogger {} - -impl<'a> MakeWriter<'a> for ChewingLogger { - type Writer = ChewingLogger; - fn make_writer(&'a self) -> Self::Writer { - self.clone() - } - fn make_writer_for(&'a self, meta: &tracing::Metadata<'_>) -> Self::Writer { - let mut writer = self.make_writer(); - writer.level = as_chewing_level(meta.level()); - writer +impl Drop for ChewingLoggerGuard { + fn drop(&mut self) { + CTX_LOGGER.with_borrow_mut(|ctx_logger| ctx_logger.pop()); } } -impl Write for ChewingLogger { - fn write(&mut self, buf: &[u8]) -> std::io::Result { - self.buffer.write(buf) - } - fn flush(&mut self) -> std::io::Result<()> { - Ok(()) +impl Log for ChewingLogger { + fn enabled(&self, metadata: &Metadata) -> bool { + self.env_logger.enabled(metadata) } -} - -impl Drop for ChewingLogger { - fn drop(&mut self) { - if !self.buffer.is_empty() { - let buffer = mem::take(&mut self.buffer); - let fmt_cstring = CString::new(buffer).unwrap(); - unsafe { - (self.logger_fn)( - self.logger_data, - self.level, - c"%s".as_ptr().cast(), - fmt_cstring.as_ptr(), - ) + fn log(&self, record: &Record) { + self.env_logger.log(record); + CTX_LOGGER.with_borrow(|ctx_logger| { + if let Some((logger_fn, data)) = ctx_logger.last() { + let fmt = format!( + "[{}:{} {}] {}", + record.file().unwrap_or("unknown"), + record.line().unwrap_or_default(), + record.module_path().unwrap_or("unknown"), + record.args() + ); + let fmt_cstring = CString::new(fmt).unwrap(); + unsafe { + logger_fn( + *data, + as_chewing_level(record.level()), + c"%s\n".as_ptr().cast(), + fmt_cstring.as_ptr(), + ) + } } - return; - } + }) + } + fn flush(&self) { + self.env_logger.flush(); } } -fn as_chewing_level(level: &Level) -> c_int { - (match *level { - Level::ERROR => CHEWING_LOG_ERROR, - Level::WARN => CHEWING_LOG_WARN, - Level::INFO => CHEWING_LOG_INFO, - Level::DEBUG => CHEWING_LOG_DEBUG, - Level::TRACE => CHEWING_LOG_VERBOSE, +fn as_chewing_level(level: Level) -> c_int { + (match level { + Level::Error => CHEWING_LOG_ERROR, + Level::Warn => CHEWING_LOG_WARN, + Level::Info => CHEWING_LOG_INFO, + Level::Debug => CHEWING_LOG_DEBUG, + Level::Trace => CHEWING_LOG_VERBOSE, }) as c_int } - -pub(crate) fn init_scoped_logging_subscriber( - logger_fn: Option, - logger_data: *mut c_void, -) -> Option { - logger_fn.map(|logger_fn| { - tracing_subscriber::fmt() - .with_writer(ChewingLogger::new(logger_fn, logger_data)) - .without_time() - .with_ansi(false) - .finish() - .set_default() - }) -} diff --git a/fuzzer/Cargo.toml b/fuzzer/Cargo.toml index ac56e15b5..c69ef8627 100644 --- a/fuzzer/Cargo.toml +++ b/fuzzer/Cargo.toml @@ -8,5 +8,5 @@ edition = "2021" [dependencies] chewing = { version = "0.11.0-alpha.7", path = ".." } chewing_capi = { version = "0.11.0-alpha.7", path = "../capi" } -tracing = { workspace = true } -tracing-subscriber = { workspace = true } +env_logger = { workspace = true } +log = { workspace = true } diff --git a/fuzzer/src/bin/fuzzer.rs b/fuzzer/src/bin/fuzzer.rs index de8905aa2..45400f6a1 100644 --- a/fuzzer/src/bin/fuzzer.rs +++ b/fuzzer/src/bin/fuzzer.rs @@ -96,7 +96,7 @@ impl From for ChewingHandle { } pub fn main() -> Result<()> { - tracing_subscriber::fmt::init(); + env_logger::init(); let syspath = env::args() .nth(1) diff --git a/fuzzer/src/bin/trieloader.rs b/fuzzer/src/bin/trieloader.rs index d466cc739..232fbb577 100644 --- a/fuzzer/src/bin/trieloader.rs +++ b/fuzzer/src/bin/trieloader.rs @@ -5,10 +5,10 @@ use chewing::{ syl, zhuyin::Bopomofo, }; -use tracing::{debug, info}; +use log::{debug, info}; pub fn main() -> Result<()> { - tracing_subscriber::fmt::init(); + env_logger::init(); let dict_path = env::args() .nth(1) diff --git a/src/conversion/chewing.rs b/src/conversion/chewing.rs index f10db5405..46039865a 100644 --- a/src/conversion/chewing.rs +++ b/src/conversion/chewing.rs @@ -3,7 +3,7 @@ use std::{ fmt::{Debug, Display, Write}, }; -use tracing::trace; +use log::trace; use super::{Composition, ConversionEngine, Gap, Interval, Outcome, Symbol}; use crate::{ diff --git a/src/dictionary/layered.rs b/src/dictionary/layered.rs index 75e1c4c90..82a0b619d 100644 --- a/src/dictionary/layered.rs +++ b/src/dictionary/layered.rs @@ -3,7 +3,7 @@ use std::{ iter, }; -use tracing::error; +use log::error; use super::{Dictionary, DictionaryInfo, Entries, LookupStrategy, Phrase, UpdateDictionaryError}; use crate::zhuyin::Syllable; diff --git a/src/dictionary/loader.rs b/src/dictionary/loader.rs index 973f75dfb..6530213f8 100644 --- a/src/dictionary/loader.rs +++ b/src/dictionary/loader.rs @@ -7,7 +7,7 @@ use std::{ path::{Path, PathBuf}, }; -use tracing::{error, info}; +use log::{error, info}; #[cfg(feature = "sqlite")] use super::SqliteDictionary; diff --git a/src/dictionary/trie.rs b/src/dictionary/trie.rs index f0ea822a4..2e1e9c138 100644 --- a/src/dictionary/trie.rs +++ b/src/dictionary/trie.rs @@ -17,7 +17,7 @@ use der::{ SliceReader, Tag, TagMode, TagNumber, Tagged, Writer, asn1::{ContextSpecificRef, OctetStringRef, Utf8StringRef}, }; -use tracing::{error, warn}; +use log::{error, warn}; use super::{ BuildDictionaryError, Dictionary, DictionaryBuilder, DictionaryInfo, Entries, LookupStrategy, diff --git a/src/dictionary/trie_buf.rs b/src/dictionary/trie_buf.rs index 933e0baed..7d004a9fe 100644 --- a/src/dictionary/trie_buf.rs +++ b/src/dictionary/trie_buf.rs @@ -7,7 +7,7 @@ use std::{ thread::{self, JoinHandle}, }; -use tracing::{error, info}; +use log::{error, info}; use super::{ BuildDictionaryError, Dictionary, DictionaryBuilder, DictionaryInfo, Entries, LookupStrategy, diff --git a/src/editor/composition_editor.rs b/src/editor/composition_editor.rs index 9d8ea6d7a..18fcbb0eb 100644 --- a/src/editor/composition_editor.rs +++ b/src/editor/composition_editor.rs @@ -2,7 +2,7 @@ use std::cmp::min; -use tracing::warn; +use log::warn; use crate::conversion::{Composition, Gap, Interval, Symbol}; diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 22a93f98d..d5429e795 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -8,7 +8,7 @@ use std::{ mem, }; -use tracing::{debug, error, info, trace, warn}; +use log::{debug, error, info, trace, warn}; pub use self::estimate::{LaxUserFreqEstimate, UserFreqEstimate}; pub use self::{abbrev::AbbrevTable, selection::symbol::SymbolSelector}; diff --git a/src/path.rs b/src/path.rs index 59d3919de..9932460de 100644 --- a/src/path.rs +++ b/src/path.rs @@ -8,7 +8,7 @@ use std::{ path::{Path, PathBuf}, }; -use tracing::{info, warn}; +use log::{info, warn}; #[cfg(target_family = "windows")] const DEFAULT_SYS_PATH: &str = "C:\\Program Files\\ChewingTextService\\Dictionary";