telelog/lib.rs
1//! # Telelog - High-Performance Structured Logging
2//!
3//! Telelog is a high-performance logging library for Rust that provides:
4//! - Structured JSON-first logging
5//! - Performance profiling and monitoring
6//! - Cross-language bindings support
7//! - System resource monitoring
8//! - Context management and decorators
9//! - Thread-local buffer pooling for reduced allocations
10//!
11//! ## Quick Start
12//!
13//! ```rust
14//! use telelog::{Logger, LogLevel};
15//!
16//! let logger = Logger::new("my_app");
17//! logger.info("Application started");
18//!
19//! // With structured data
20//! logger.info_with("User logged in", &[
21//! ("user_id", "12345"),
22//! ("session_id", "abcdef"),
23//! ]);
24//!
25//! // Performance profiling
26//! let _guard = logger.profile("expensive_operation");
27//! // Your expensive operation here
28//! ```
29//!
30//! ## Async Support
31//!
32//! Enable the `async` feature for bounded async output with backpressure:
33//!
34//! ```rust,ignore
35//! use telelog::{Logger, AsyncOutput};
36//!
37//! #[tokio::main]
38//! async fn main() {
39//! let logger = Logger::new("app");
40//! let mut async_output = AsyncOutput::new();
41//! logger.add_output(Box::new(async_output));
42//! logger.info("Async logging!");
43//! }
44//! ```
45//!
46//! ## Performance
47//!
48//! - **~788ns** per log with thread-local buffer pooling
49//! - **~11ns** level check overhead (nearly free when filtered)
50//! - **Bounded async** channels with backpressure (capacity: 1000)
51//!
52//! ## Features
53//!
54//! - **Thread-safe** logging with parking_lot
55//! - **Optimized allocations** with thread-local buffer pooling
56//! - **Optional features**: async, system-monitor, console, python
57
58pub mod component;
59pub mod config;
60pub mod context;
61pub mod level;
62pub mod logger;
63pub mod output;
64pub mod profile;
65pub mod visualization;
66
67#[cfg(feature = "async")]
68pub mod async_output;
69
70#[cfg(feature = "system-monitor")]
71pub mod monitor;
72
73pub use component::{
74 Component, ComponentGuard, ComponentMetadata, ComponentStatus, ComponentTracker,
75};
76pub use config::Config;
77pub use context::{Context, ContextGuard};
78pub use level::LogLevel;
79pub use logger::Logger;
80pub use output::{BufferedOutput, LogMessage};
81pub use profile::ProfileGuard;
82pub use visualization::{ChartConfig, ChartType, Direction, MermaidGenerator};
83
84#[cfg(feature = "async")]
85pub use async_output::AsyncOutput;
86
87#[cfg(feature = "system-monitor")]
88pub use monitor::SystemMonitor;
89
90#[cfg(feature = "python")]
91pub mod python;
92
93pub const VERSION: &str = env!("CARGO_PKG_VERSION");
94
95/// Initialize telelog with default configuration.
96///
97/// For more control, use `Logger::new()` directly.
98///
99/// # Example
100///
101/// ```rust
102/// use telelog;
103///
104/// let logger = telelog::init("my_app");
105/// logger.info("Hello, telelog!");
106/// ```
107pub fn init(name: &str) -> Logger {
108 Logger::new(name)
109}
110
111/// Initialize telelog with custom configuration
112///
113/// # Example
114///
115/// ```rust
116/// use telelog::{init_with_config, Config};
117///
118/// let config = Config::new()
119/// .with_console_output(true)
120/// .with_json_format(true);
121///
122/// let logger = init_with_config("my_app", config);
123/// logger.info("Hello, telelog!");
124/// ```
125pub fn init_with_config(name: &str, config: Config) -> Logger {
126 Logger::with_config(name, config)
127}
128
129#[cfg(test)]
130mod tests {
131 use super::*;
132
133 #[test]
134 fn test_init() {
135 let logger = init("test");
136 assert_eq!(logger.name(), "test");
137 }
138
139 #[test]
140 fn test_version() {
141 assert!(!VERSION.is_empty());
142 }
143}