1
0
Fork 0

Switch to using NIH-log for the logger

This greatly simplifies the setup, provides more deterministic and
performant behavior, and allows for better WinDbg integration by
detecting its presence at runtime and by using the regular pretty log
format there as well.
This commit is contained in:
Robbert van der Helm 2023-03-01 19:01:15 +01:00
parent e3a923ff3b
commit c381744b47
3 changed files with 84 additions and 136 deletions

138
Cargo.lock generated
View file

@ -419,7 +419,7 @@ dependencies = [
[[package]] [[package]]
name = "baseview" name = "baseview"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/RustAudio/baseview.git#7001c2521fa1a439a01967cb881b411cd75d9ee0" source = "git+https://github.com/RustAudio/baseview.git#c129b12ead4f5ac02126f559ceb8ce43cc982200"
dependencies = [ dependencies = [
"cocoa", "cocoa",
"core-foundation", "core-foundation",
@ -514,9 +514,9 @@ checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.13.0" version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393" checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
dependencies = [ dependencies = [
"bytemuck_derive", "bytemuck_derive",
] ]
@ -964,9 +964,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-channel" name = "crossbeam-channel"
version = "0.5.6" version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils",
@ -974,9 +974,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-deque" name = "crossbeam-deque"
version = "0.8.2" version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"crossbeam-epoch", "crossbeam-epoch",
@ -985,14 +985,14 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-epoch" name = "crossbeam-epoch"
version = "0.9.13" version = "0.9.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"crossbeam-utils", "crossbeam-utils",
"memoffset 0.7.1", "memoffset 0.8.0",
"scopeguard", "scopeguard",
] ]
@ -1008,9 +1008,9 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.14" version = "0.8.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@ -1754,9 +1754,9 @@ dependencies = [
[[package]] [[package]]
name = "glyph_brush" name = "glyph_brush"
version = "0.7.6" version = "0.7.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b773a724cb29f6119043a46bd2fc6bfedce59ab9898a3c07df66082acbea0ca" checksum = "4edefd123f28a0b1d41ec4a489c2b43020b369180800977801611084f342978d"
dependencies = [ dependencies = [
"glyph_brush_draw_cache", "glyph_brush_draw_cache",
"glyph_brush_layout", "glyph_brush_layout",
@ -2048,9 +2048,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]] [[package]]
name = "jobserver" name = "jobserver"
version = "0.1.25" version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@ -2267,9 +2267,9 @@ dependencies = [
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.7.1" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
@ -2390,6 +2390,20 @@ dependencies = [
"jni-sys", "jni-sys",
] ]
[[package]]
name = "nih_log"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6770b5cd61a41a585c932979a3da2b3248be00e879b9cf85ddfb97040ce3f40a"
dependencies = [
"atty",
"log",
"once_cell",
"termcolor",
"time",
"windows 0.44.0",
]
[[package]] [[package]]
name = "nih_plug" name = "nih_plug"
version = "0.0.0" version = "0.0.0"
@ -2415,6 +2429,7 @@ dependencies = [
"log", "log",
"midi-consts", "midi-consts",
"midir", "midir",
"nih_log",
"nih_plug_derive", "nih_plug_derive",
"objc", "objc",
"parking_lot 0.12.1", "parking_lot 0.12.1",
@ -2422,10 +2437,8 @@ dependencies = [
"rtrb", "rtrb",
"serde", "serde",
"serde_json", "serde_json",
"simplelog",
"vst3-sys", "vst3-sys",
"widestring", "widestring",
"win_dbg_logger",
"windows 0.32.0", "windows 0.32.0",
"zstd", "zstd",
] ]
@ -2562,15 +2575,6 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "nom8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "num-complex" name = "num-complex"
version = "0.4.3" version = "0.4.3"
@ -2633,18 +2637,18 @@ dependencies = [
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.5.10" version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e0072973714303aa6e3631c7e8e777970cf4bdd25dc4932e41031027b8bcc4e" checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9"
dependencies = [ dependencies = [
"num_enum_derive", "num_enum_derive",
] ]
[[package]] [[package]]
name = "num_enum_derive" name = "num_enum_derive"
version = "0.5.10" version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0629cbd6b897944899b1f10496d9c4a7ac5878d45fd61bc22e9e79bfbbc29597" checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -3078,9 +3082,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro-crate" name = "proc-macro-crate"
version = "1.3.0" version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66618389e4ec1c7afe67d51a9bf34ff9236480f8d51e7489b7d5ab0303c13f34" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"toml_edit", "toml_edit",
@ -3646,17 +3650,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "simplelog"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dfff04aade74dd495b007c831cd6f4e0cee19c344dd9dc0884c0289b70a786"
dependencies = [
"log",
"termcolor",
"time",
]
[[package]] [[package]]
name = "sine" name = "sine"
version = "0.1.0" version = "0.1.0"
@ -3847,9 +3840,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.108" version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d56e159d99e6c2b93995d171050271edb50ecc5288fbc7cc17de8fdce4e58c14" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3878,9 +3871,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.3" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -3913,9 +3906,9 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.19" version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890"
dependencies = [ dependencies = [
"itoa 1.0.5", "itoa 1.0.5",
"libc", "libc",
@ -3933,9 +3926,9 @@ checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.7" version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c" checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36"
dependencies = [ dependencies = [
"time-core", "time-core",
] ]
@ -3972,19 +3965,19 @@ dependencies = [
[[package]] [[package]]
name = "toml_datetime" name = "toml_datetime"
version = "0.5.1" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4553f467ac8e3d374bc9a177a26801e5d0f9b211aa1673fb137a403afd1c9cf5" checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.18.1" version = "0.19.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c59d8dd7d0dcbc6428bf7aa2f0e823e26e43b3c9aca15bbc9475d23e5fa12b" checksum = "9a1eb0622d28f4b9c90adc4ea4b2b46b47663fde9ac5fafcb14a1369d5508825"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"nom8",
"toml_datetime", "toml_datetime",
"winnow",
] ]
[[package]] [[package]]
@ -4541,15 +4534,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
[[package]]
name = "win_dbg_logger"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d1b4c22244dc27534d81e2f6fc3efd6b20e50c010f177efc20b719ec759a779"
dependencies = [
"log",
]
[[package]] [[package]]
name = "winapi" name = "winapi"
version = "0.3.9" version = "0.3.9"
@ -4631,6 +4615,15 @@ dependencies = [
"windows_x86_64_msvc 0.42.1", "windows_x86_64_msvc 0.42.1",
] ]
[[package]]
name = "windows"
version = "0.44.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e745dab35a0c4c77aa3ce42d595e13d2003d6902d6b08c9ef5fc326d08da12b"
dependencies = [
"windows-targets",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"
@ -4806,6 +4799,15 @@ dependencies = [
"x11-dl", "x11-dl",
] ]
[[package]]
name = "winnow"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faf09497b8f8b5ac5d3bb4d05c0a99be20f26fd3d5f2db7b0716e946d5103658"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "wio" name = "wio"
version = "0.2.2" version = "0.2.2"

View file

@ -85,11 +85,11 @@ crossbeam = "0.8"
lazy_static = "1.4" lazy_static = "1.4"
log = { version = "0.4", features = ["std", "release_max_level_info"] } log = { version = "0.4", features = ["std", "release_max_level_info"] }
midi-consts = "0.1" midi-consts = "0.1"
nih_log = "0.1.0"
parking_lot = "0.12" parking_lot = "0.12"
raw-window-handle = "0.4" raw-window-handle = "0.4"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
simplelog = "0.12"
widestring = "1.0.0-beta.1" widestring = "1.0.0-beta.1"
# Used for the `assert_process_allocs` feature. This fork includes support for # Used for the `assert_process_allocs` feature. This fork includes support for
@ -130,11 +130,6 @@ libc = "0.2.124"
objc = "0.2.7" objc = "0.2.7"
core-foundation = "0.9.3" core-foundation = "0.9.3"
[target.'cfg(target_os = "windows")'.dependencies]
# STDIO isn't reliable on Windows, so when hosting plugins in a DAW it may be
# useful to log using `OutputDebugString()` instead
win_dbg_logger = "0.1"
[target.'cfg(target_os = "windows")'.dependencies.windows] [target.'cfg(target_os = "windows")'.dependencies.windows]
version = "0.32" version = "0.32"
features = [ features = [

View file

@ -91,11 +91,11 @@ pub fn clamp_output_event_timing(timing: u32, total_buffer_len: u32) -> u32 {
} }
/// Set up the logger so that the `nih_*!()` logging and assertion macros log output to a /// Set up the logger so that the `nih_*!()` logging and assertion macros log output to a
/// centralized location and panics also get written there. By default this logs to STDERR unless /// centralized location and panics also get written there. By default this logs to STDERR. If a
/// the user is running Windows and a debugger has been attached, in which case /// Windows debugger is attached, then messages will be sent there instead. This uses
/// `OutputDebugString()` will be used instead. /// [NIH-log](https://github.com/robbert-vdh/nih-log). See the readme there for more information.
/// ///
/// The logger's behavior can be controlled by setting the `NIH_LOG` environment variable to: /// In short, NIH-log's behavior can be controlled by setting the `NIH_LOG` environment variable to:
/// ///
/// - `stderr`, in which case the log output always gets written to STDERR. /// - `stderr`, in which case the log output always gets written to STDERR.
/// - `windbg` (only on Windows), in which case the output always gets logged using /// - `windbg` (only on Windows), in which case the output always gets logged using
@ -103,70 +103,21 @@ pub fn clamp_output_event_timing(timing: u32, total_buffer_len: u32) -> u32 {
/// - A file path, in which case the output gets appended to the end of that file which will be /// - A file path, in which case the output gets appended to the end of that file which will be
/// created if necessary. /// created if necessary.
pub fn setup_logger() { pub fn setup_logger() {
// `win_dbg_logger` has no way to let us know that the logger has already been set up, so we'll
// need to do it this way
static LOGGER_SET_UP: AtomicBool = AtomicBool::new(false);
if LOGGER_SET_UP
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_err()
{
return;
}
let nih_log_env = std::env::var(NIH_LOG_ENV);
let nih_log_env_str = nih_log_env.as_deref().unwrap_or("");
#[cfg(target_os = "windows")]
if nih_log_env_str.eq_ignore_ascii_case("windbg")
|| (nih_log_env_str.is_empty() && win_dbg_logger::is_debugger_present())
{
win_dbg_logger::init();
log_panics();
return;
}
// If opening the file fails, then we'll log to STDERR anyways, hence this closure // If opening the file fails, then we'll log to STDERR anyways, hence this closure
let log_level = if cfg!(debug_assertions) { let log_level = if cfg!(debug_assertions) {
simplelog::LevelFilter::Trace log::LevelFilter::Trace
} else { } else {
simplelog::LevelFilter::Info log::LevelFilter::Info
};
let logger_config = simplelog::ConfigBuilder::new()
.set_thread_mode(simplelog::ThreadLogMode::Both)
.set_location_level(simplelog::LevelFilter::Debug)
.add_filter_ignore_str("cosmic_text::buffer")
.add_filter_ignore_str("cosmic_text::shape")
.build();
let init_stderr_logger = || {
simplelog::TermLogger::init(
log_level,
logger_config.clone(),
simplelog::TerminalMode::Stderr,
simplelog::ColorChoice::Auto,
)
}; };
// If the logger has already been set up outside of this function then that won't cause any let logger_set = nih_log::LoggerBuilder::new(log_level)
// problems, so we can ignore the results here .filter_module("cosmic_text::buffer")
if nih_log_env_str.eq_ignore_ascii_case("stderr") || nih_log_env_str.is_empty() { .filter_module("cosmic_text::shape")
let _ = init_stderr_logger(); .build_global()
} else { .is_ok();
let file = File::options() if logger_set {
.append(true) log_panics();
.create(true)
.open(nih_log_env_str);
match file {
Ok(file) => {
let _ = simplelog::WriteLogger::init(log_level, logger_config, file);
}
Err(err) => {
let _ = init_stderr_logger();
nih_debug_assert_failure!("Could not open '{}': {:?}", nih_log_env_str, err);
}
}
} }
log_panics();
} }
/// This is copied from same as the `log_panics` crate, but it's wrapped in `permit_alloc()`. /// This is copied from same as the `log_panics` crate, but it's wrapped in `permit_alloc()`.