4 releases
Uses new Rust 2024
new 0.1.3 | Apr 29, 2025 |
---|---|
0.1.2 | Apr 29, 2025 |
0.1.1 | Apr 29, 2025 |
0.1.0 | Apr 29, 2025 |
#300 in Configuration
279 downloads per month
11KB
170 lines
log4rs-tcp
⚠️ Pre-Production Notice ⚠️
WARNING: This crate is currently in early development (v0.1.0) and NOT READY FOR PRODUCTION USE.
- The API may change without notice
- Error handling needs improvement
- Performance optimizations are still being implemented
- Debug statements are present in the code
- Comprehensive testing is not yet complete
We welcome feedback and contributions as we work toward a stable release.
Overview
log4rs-tcp
provides a TCP appender for the log4rs logging framework. It allows log messages to be sent to a remote TCP server with configurable connection handling, buffering, and automatic reconnection capabilities.
Features
- Send log messages to a remote TCP endpoint
- Configurable connection timeout
- Automatic reconnection with exponential backoff
- Message buffering when connection is unavailable
Installation
Add this to your Cargo.toml
:
[dependencies]
log4rs = "1.3.0"
log = "0.4.26"
Basic Usage
use log::{info, LevelFilter};
use log4rs::append::console::ConsoleAppender;
use log4rs::config::{Appender, Config, Root};
use log4rs::encode::pattern::PatternEncoder;
use log4rs_tcp::TcpAppender;
use std::time::Duration;
fn main() {
// Create a TCP appender
let tcp = TcpAppender::builder()
.encoder(Box::new(PatternEncoder::new("{d} - {m}{n}")))
.timeout(Duration::from_secs(5))
.buffer_len(100)
.build("127.0.0.1:9000")
.unwrap();
// Create a basic console appender as backup
let console = ConsoleAppender::builder().build();
// Build the log4rs config with both appenders
let config = Config::builder()
.appender(Appender::builder().build("tcp", Box::new(tcp)))
.appender(Appender::builder().build("console", Box::new(console)))
.build(Root::builder()
.appender("tcp")
.appender("console")
.build(LevelFilter::Info))
.unwrap();
// Initialize the logger
log4rs::init_config(config).unwrap();
// Send some log messages
info!("This message will be sent to the TCP server!");
}
Current Status
This project is in active development. Here's what's working and what's still in progress:
Implemented:
- Basic TCP appender functionality
- Connection timeout configuration
- Automatic reconnection with exponential backoff
- Message buffering
In Progress:
- Removing debug print statements
- Comprehensive error handling
- Performance optimization
- Full test coverage
- Documentation improvements
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
log4rs-tcp
is licensed under the MIT License.
Dependencies
~2.5MB
~51K SLoC