rasant 0.8.0

Rasant is a lightweight, high performance and flexible Rust library for structured logging.
Documentation
use ntime::Duration;
use std::env;
use std::process;
use std::sync::LazyLock;

/// Process ID running this module.
pub static PROCESS_ID: LazyLock<u32> = LazyLock::new(|| process::id());

/// Name of the process running this module.
pub static PROCESS_NAME: LazyLock<String> = LazyLock::new(|| {
	let current_exe = env::current_exe();
	match &current_exe {
		Ok(ce) => match ce.file_name() {
			Some(n) => match n.to_str() {
				Some(s) => return String::from(s),
				None => String::from("process_invalid_name"),
			},
			_ => String::from("process_no_name"),
		},
		_ => String::from("process"),
	}
});

/// System hostname
// TODO: fix me!
pub static HOSTNAME: LazyLock<String> = LazyLock::new(|| String::from("localhost"));

/// UTF-8 byte-order-mark
pub static UTF8_BOM: [u8; 3] = [0xef, 0xbb, 0xbf];

/// Attribute key for error details.
pub const ATTRIBUTE_KEY_ERROR: &str = "error";
/// Attribute key for log level.
pub const ATTRIBUTE_KEY_LEVEL: &str = "level";
/// Attribute key for log messages.
pub const ATTRIBUTE_KEY_MESSAGE: &str = "message";
/// Attribute key for timestamps, as string.
pub const ATTRIBUTE_KEY_TIME: &str = "time";
/// Attribute key for numeric timestamps;
pub const ATTRIBUTE_KEY_TIMESTAMP: &str = "timestamp";
/// Attribute key for logger IDs.
pub const ATTRIBUTE_KEY_LOGGER_ID: &str = "logger_id";

/// Maximum allowed [`crate::logger::Logger`] depth.
pub const MAX_LOGGER_DEPTH: u16 = 1024;

/// Default log separator for binary format outputs.
pub const DEFAULT_LOG_DELIMITER_BINARY: &[u8] = "".as_bytes();

/// Default log separator for string format outputs.
#[cfg(not(target_os = "windows"))]
pub const DEFAULT_LOG_DELIMITER_STRING: &[u8] = "\n".as_bytes();
#[cfg(target_os = "windows")]
pub const DEFAULT_LOG_DELIMITER_STRING: &[u8] = "\r\n".as_bytes();

/// How long to wait for open threads to finalize.
pub const THREAD_FINALIZE_TIMEOUT: Duration = Duration::from_secs(5);
/// How often to check on open threads for finalization.
pub const THREAD_FINALIZE_SPINLOCK_WAIT: Duration = Duration::from_millis(50);

/// Timeout for network operations.
pub const NETWORK_TIMEOUT: Duration = Duration::from_secs(30);
/// Default journald *NIX socket for writes
pub const DEFUALT_JOURNALD_SOCKET: &str = "/run/systemd/journal/socket";
/// Default local *NIX syslog sockets.
#[cfg(unix)]
pub const DEFAULT_LOCAL_SYSLOG_SOCKETS: [&str; 3] = ["/dev/log", "/var/run/log", "/var/run/syslog"];