0.1.0-2-beta.1.fix.3
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/common/game-logging-lib/src/lib.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![deny(unreachable_pub)]
|
||||
@@ -10,11 +10,11 @@
|
||||
mod runtime;
|
||||
mod test_support;
|
||||
|
||||
/// Re-export of the console tracing initialization error.
|
||||
/// Re-export of the platform tracing initialization error.
|
||||
pub use self::runtime::LoggingInitError;
|
||||
/// Re-export of the guard keeping the non-blocking tracing writer alive.
|
||||
/// Re-export of the guard keeping platform tracing resources alive.
|
||||
pub use self::runtime::LoggingWorkerGuard;
|
||||
/// Re-export of the standard console tracing initializer.
|
||||
/// Re-export of the platform tracing initializer.
|
||||
pub use self::runtime::init_console_tracing;
|
||||
/// Re-export of the scoped tracing helper intended for tests.
|
||||
pub use self::test_support::with_test_tracing;
|
||||
|
||||
@@ -1,31 +1,50 @@
|
||||
// file: crates/common/game-logging-lib/src/runtime.rs
|
||||
// version: 1
|
||||
// version: 2
|
||||
|
||||
/// Error returned when the process-global tracing subscriber is already configured.
|
||||
/// Error returned when the process-global tracing subscriber cannot be configured.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct LoggingInitError;
|
||||
|
||||
impl std::fmt::Display for LoggingInitError {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
return formatter.write_str("the process-global tracing subscriber is already configured");
|
||||
return formatter.write_str("the process-global tracing subscriber could not be configured");
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for LoggingInitError {}
|
||||
|
||||
/// Guard keeping the non-blocking tracing writer alive for the application lifetime.
|
||||
/// Guard keeping platform tracing resources alive for the application lifetime.
|
||||
pub struct LoggingWorkerGuard {
|
||||
#[cfg(not(target_os = "android"))]
|
||||
_worker_guard: tracing_appender::non_blocking::WorkerGuard,
|
||||
}
|
||||
|
||||
/// Initializes a process-global non-blocking tracing subscriber writing formatted events to standard error.
|
||||
/// Initializes process-global tracing for the current platform.
|
||||
///
|
||||
/// Native desktop/Tauri processes write formatted events to standard error.
|
||||
/// Android processes write directly to logcat through the Android NDK logging API.
|
||||
///
|
||||
/// The returned guard must remain alive for as long as events may still be emitted.
|
||||
pub fn init_console_tracing() -> std::result::Result<LoggingWorkerGuard, LoggingInitError> {
|
||||
let (writer, worker_guard) = tracing_appender::non_blocking(std::io::stderr());
|
||||
let subscriber = tracing_subscriber::fmt().with_target(true).with_writer(writer).finish();
|
||||
if tracing::subscriber::set_global_default(subscriber).is_err() {
|
||||
return std::result::Result::Err(LoggingInitError);
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let layer = match tracing_android::layer("games.sasedev") {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(_) => return std::result::Result::Err(LoggingInitError),
|
||||
};
|
||||
let subscriber = tracing_subscriber::layer::SubscriberExt::with(tracing_subscriber::registry(), layer);
|
||||
if tracing::subscriber::set_global_default(subscriber).is_err() {
|
||||
return std::result::Result::Err(LoggingInitError);
|
||||
}
|
||||
return std::result::Result::Ok(LoggingWorkerGuard {});
|
||||
}
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
let (writer, worker_guard) = tracing_appender::non_blocking(std::io::stderr());
|
||||
let subscriber = tracing_subscriber::fmt().with_target(true).with_writer(writer).finish();
|
||||
if tracing::subscriber::set_global_default(subscriber).is_err() {
|
||||
return std::result::Result::Err(LoggingInitError);
|
||||
}
|
||||
return std::result::Result::Ok(LoggingWorkerGuard { _worker_guard: worker_guard });
|
||||
}
|
||||
return std::result::Result::Ok(LoggingWorkerGuard { _worker_guard: worker_guard });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user