9 个版本
0.3.0 | 2022 年 12 月 17 日 |
---|---|
0.2.4 | 2022 年 8 月 15 日 |
0.2.3 | 2021 年 8 月 1 日 |
0.2.2 | 2021 年 6 月 6 日 |
0.1.1 | 2020 年 4 月 17 日 |
#343 in 异步
3,509 每月下载量
用于 7 crates
60KB
1K SLoC
linemux
一个提供针对(特别是日志)文件的异步、复用式尾部跟写的库。
还包括底层的文件事件流(由 notify
驱动),它可以注册不存在的文件。
用法
使用以下命令将 linemux 添加到您的 Cargo.toml
[dependencies]
linemux = "0.3"
示例
use linemux::MuxedLines;
#[tokio::main]
async fn main() -> std::io::Result<()> {
let mut lines = MuxedLines::new()?;
// Register some files to be tailed, whether they currently exist or not.
lines.add_file("some/file.log").await?;
lines.add_file("/some/other/file.log").await?;
// Wait for `Line` event, which contains the line captured for a given
// source path.
while let Ok(Some(line)) = lines.next_line().await {
println!("source: {}, line: {}", line.source().display(), line.line());
}
Ok(())
}
注意事项
目前,linemux 假设如果添加了不存在的文件,其父目录至少存在,可以使用 notify
注册目录监视。这样做是为了性能原因,并简化待处理监视的复杂性(如限制递归和 fs 事件垃圾邮件)。然而,如果出现需要,这可能会改变。
最低支持的 Rust 版本 (MSRV)
此包保证在稳定 Rust 1.60 及以上版本中编译。
许可
根据您的选择,受以下任一许可的许可:
- Apache 许可证 2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证 (LICENSE-MIT 或 https://open-source.org.cn/licenses/MIT)
。
贡献
除非您明确声明,否则您提交给包含在您的工作中的任何贡献,根据 Apache-2.0 许可证定义,应作为上述双重许可,不附加任何额外条款或条件。
依赖项
~3–12MB
~122K SLoC