Expand description
§apple-log
Safe Rust bindings for Apple’s unified logging stack on macOS.
apple-log v0.5 adds a Swift bridge on top of the C os APIs and the Swift os / OSLog modules, covering:
LoggerOSLogOSLogStoreOSLogEntryLogOSLogEntrySignpostOSLogEntryBoundaryOSLogEntryActivityOSSignpostIDOSSignposterOSActivityOSAtomic
Platform: macOS 12+ (the bridge uses Swift
LoggerandOSSignposter).
§Quick start
use std::time::Duration;
use apple_log::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let logger = Logger::new("fish.doom.myapp", "network")?;
logger.info("booting service");
logger.log_with_privacy(Level::Info, "token=secret", Privacy::Private);
let signposter = OSSignposter::new("fish.doom.myapp", CATEGORY_POINTS_OF_INTEREST)?;
let signpost_id = signposter.make_signpost_id();
let interval = signposter.begin_interval("startup", signpost_id, "begin startup");
signposter.end_interval("startup", interval, "end startup");
let activity = OSActivity::new(
"index cache",
Some(&OSActivity::current()),
OSActivityFlags::DEFAULT,
)?;
activity.apply(|| Logger::default().info("inside activity"));
let store = OSLogStore::new(OSLogStoreScope::CurrentProcessIdentifier)?;
let entries = store.entries(
OSLogEnumeratorOptions::REVERSE,
Some(&store.position_time_interval_since_end(Duration::from_secs(5))),
None,
)?;
println!("recent entries: {}", entries.len());
Ok(())
}§Areas and modules
apple_log::logger::Loggerand compatibility free functions inapple_log::logapple_log::os_log::OSLogapple_log::os_log_store::{OSLogStore, OSLogPosition, OSLogStoreEntry}apple_log::os_log_entry_*typed entry wrappersapple_log::os_signpost_id::OSSignpostIdapple_log::os_signposter::OSSignposterapple_log::os_activity::OSActivityapple_log::os_atomic::{OSAtomicI32, OSAtomicI64, OSAtomicQueue, OSAtomicFifoQueue}
§Raw C FFI
The crate keeps the low-level C shim behind the raw-ffi feature. The feature is enabled by default for backwards compatibility.
[dependencies]
apple-log = { version = "0.5", default-features = false }Enable raw-ffi when you want direct access to the wrapped C symbols under apple_log::ffi.
§Examples
The crate ships one numbered example per logical area in examples/01_logger.rs through examples/11_os_atomic.rs.
§Coverage
See COVERAGE.md for the SDK audit and implementation matrix.
§License
Licensed under either Apache-2.0 or MIT at your option.
Re-exports§
pub use error::LogError;pub use log::active_activity_id;pub use log::active_activity_ids;pub use log::log;pub use log::log_enabled;pub use log::log_with_privacy;pub use log::ActivityIds;pub use logger::Logger;pub use logger::Privacy;pub use os_activity::OSActivity;pub use os_activity::OSActivityFlags;pub use os_activity::OSActivityScope;pub use os_atomic::OSAtomicFifoQueue;pub use os_atomic::OSAtomicI32;pub use os_atomic::OSAtomicI64;pub use os_atomic::OSAtomicQueue;pub use os_log::Level;pub use os_log::OSLog;pub use os_log::CATEGORY_DYNAMIC_STACK_TRACING;pub use os_log::CATEGORY_DYNAMIC_TRACING;pub use os_log::CATEGORY_POINTS_OF_INTEREST;pub use os_log_entry_activity::OSLogEntryActivity;pub use os_log_entry_boundary::OSLogEntryBoundary;pub use os_log_entry_log::OSLogEntryLog;pub use os_log_entry_log::OSLogEntryLogLevel;pub use os_log_entry_signpost::OSLogEntrySignpost;pub use os_log_entry_signpost::OSLogEntrySignpostType;pub use os_log_store::OSLogEntryCommon;pub use os_log_store::OSLogEntryFromProcess;pub use os_log_store::OSLogEntryWithPayload;pub use os_log_store::OSLogEnumeratorOptions;pub use os_log_store::OSLogMessageArgument;pub use os_log_store::OSLogMessageArgumentCategory;pub use os_log_store::OSLogMessageComponent;pub use os_log_store::OSLogPosition;pub use os_log_store::OSLogStore;pub use os_log_store::OSLogStoreCategory;pub use os_log_store::OSLogStoreEntry;pub use os_log_store::OSLogStoreScope;pub use os_signpost_id::OSSignpostId;pub use os_signpost_id::SignpostId;pub use os_signposter::OSSignpostInterval;pub use os_signposter::OSSignposter;
Modules§
- error
- Errors returned by the
apple-logcrate. - ffi
- Bridge and optional raw FFI declarations.
- log
- Compatibility layer preserving the pre-v0.5
apple_log::logAPI. - logger
- os_
activity - os_
atomic - os_log
- os_
log_ entry_ activity - os_
log_ entry_ boundary - os_
log_ entry_ log - os_
log_ entry_ signpost - os_
log_ store - os_
signpost_ id - os_
signposter - prelude
- Common imports.