-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unify rust & C++ logs using the Rust facilities. (#92)
The choice was to write macros to replace the log crate macros, or write templates to sink the C++ logging to Rust. I went with Rust because what good is being in the evangelism task force if I don't ruthlessly carcinicize? Wrote the templates by contemplating what the SKSE peeps did to put templates in front of `spdlog`. These templates are in front of `fmt` instead. The guts of each implementation routes to shims in front of the the `log` crate's macros. The new namespace is `rlog`. All calls to `logger::info()` are now calls to `rlog::info()` which eventually dispatches to `log::info!()`. The debug and trace level log templates add filename & line number information to the start of each log message. Unfortunately those two levels are decorated with fairly useless information from the rust logger, which I can't rid of without also affecting rust-sourced log lines. I'll need to find a new crate. This is, however, good enough to ship. Got rid of spdlog in the build. It remains in the deps because the CommonLibSSE dll needs it. Demoted some logs while I was looking at them in the unified context. I will need to systematically review logging because it feels too voluminous now that it's all in one file.
- Loading branch information
Showing
26 changed files
with
377 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! Logging functions exposed to C++. There's an initialization function | ||
//! that must be called to tell the plugin where to log. The other functions | ||
//! are for C++ to use to share a log file with Rust. For now, C++ must pass | ||
//! a preformatted-string to these functions. This is wasteful, but I don't | ||
//! C strings prove a bit of a pain. | ||
use std::ffi::OsString; | ||
use std::fs::File; | ||
#[cfg(target_os = "windows")] | ||
use std::os::windows::ffi::OsStringExt; | ||
use std::path::Path; | ||
|
||
use simplelog::*; | ||
|
||
use super::settings::settings; | ||
|
||
// ---------- logging | ||
|
||
pub fn initialize_rust_logging(_logdir: &cxx::CxxVector<u16>) { | ||
let config = settings(); | ||
let log_level = config.log_level().to_level_filter(); | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
let chonky_path = OsString::from("placeholder"); | ||
#[cfg(target_os = "windows")] | ||
let chonky_path = OsString::from_wide(_logdir.as_slice()); | ||
let path = Path::new(chonky_path.as_os_str()).with_file_name("SoulsyHUD.log"); | ||
|
||
let Ok(logfile) = File::create(path) else { | ||
// Welp, we failed and I have nowhere to write the darn error. Ha ha. | ||
return; | ||
}; | ||
let config = simplelog::ConfigBuilder::new() | ||
.set_thread_level(LevelFilter::Off) | ||
.set_level_padding(simplelog::LevelPadding::Right) | ||
.build(); | ||
let Ok(_) = WriteLogger::init(log_level, config, logfile) else { | ||
// oh dear | ||
return; | ||
}; | ||
log::info!("SoulsyHUD version {} coming online.", env!("CARGO_PKG_VERSION")); | ||
} | ||
|
||
pub fn log_error(message: String) { | ||
log::error!("{}", message); | ||
} | ||
|
||
pub fn log_warn(message: String) { | ||
log::warn!("{}", message); | ||
} | ||
|
||
pub fn log_info(message: String) { | ||
log::info!("{}", message); | ||
} | ||
|
||
pub fn log_debug(message: String) { | ||
log::debug!("{}", message); | ||
} | ||
|
||
pub fn log_trace(message: String) { | ||
log::trace!("{}", message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.