Async log watch
async_log_watch is a simple Rust library developed as a part of a personal project. It is designed to monitor log files and trigger an async callback whenever a new line is added to the file. The library allows users to easily integrate log file monitoring into their projects, with support for monitoring multiple log files simultaneously.
The primary motivation behind creating this library was to efficiently detect new log lines generated by tools like pm2. The library is built using the async-std (can use the tokio by adding tokio runtime feature) and the notify crate for file system event monitoring.
Usage
Add async-log-watch to your Cargo.toml dependencies:
[]
= { = "0.2"}
Example
For a example demonstrating the usage of this library, please refer to the example code in the examples folder.
Cargo Features
This crate allows you to use tokio runtime featured in async-std by specifying features in your Cargo.toml. By default, it uses async-std with the attributes feature.
To use the crate with the default configuration, add the following line to your Cargo.toml:
= "0.2"
To use a specific Tokio configuration, specify the feature like this:
= { = "0.2", = ["tokio1"] }
Available Features
- default: Uses
async-stdwith theattributesfeature. - tokio1: Uses
async-stdwith theattributesandtokio1features. - tokio02: Uses
async-stdwith theattributesandtokio02features. - tokio03: Uses
async-stdwith theattributesandtokio03features.
Please note that you should only enable one of these features at a time.
TODO
- Implement basic log monitoring.
- Support async callbacks
- Allow monitoring multiple log files simultaneously
- Update with new version of dependencies.
- FIXED: When convert into absolute filepath, tilde('~') is used as folder name.
- FIXED: At the first time, watcher read the first line.
- Error handling for file read errors
- Improve error handling with the
thiserrorlibrary. - file errors occurs in spawn. - Notify error through callback
- Added methods : stop_monitoring_file and change_file_path
- FIXED: absolute path in added methods | test code
- Added new object
LogEventthat encapsulates the line, path andLogErrorobject. - Update the callback function's arguments to include the functionalities.
- It allows user to handle log file rotation in the callback function when receiving a file open error
support tokio runtime
-
Add support for other async runtimes (tokio) - Add support tokio runtime features in async-std
Add filtering options to process specific log lines based on patterns
- Add filtering option
Future Works
- Add support for File name pattern : automatically monitor files that match the specified pattern within a directory.
Add support for log file rotation- Add trace log
License
This project is licensed under the MIT License - see the LICENSE file for details.