{"id":13637218,"url":"https://github.com/rbatis/fast_log","last_synced_at":"2025-05-15T08:10:48.281Z","repository":{"id":37207920,"uuid":"243965565","full_name":"rbatis/fast_log","owner":"rbatis","description":"Rust async log High-performance asynchronous logging","archived":false,"fork":false,"pushed_at":"2024-11-18T08:54:38.000Z","size":461,"stargazers_count":255,"open_issues_count":15,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T14:59:40.693Z","etag":null,"topics":["async","log","logging","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rbatis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-29T12:33:50.000Z","updated_at":"2025-04-09T10:42:17.000Z","dependencies_parsed_at":"2024-11-09T06:32:13.257Z","dependency_job_id":"f991f9f7-5a86-476f-b077-299504a42fa1","html_url":"https://github.com/rbatis/fast_log","commit_stats":{"total_commits":589,"total_committers":1,"mean_commits":589.0,"dds":0.0,"last_synced_commit":"fc26e2073b50ed2c4e233478df890a67d6461866"},"previous_names":["co-rs/fast_log"],"tags_count":87,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbatis%2Ffast_log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbatis%2Ffast_log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbatis%2Ffast_log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbatis%2Ffast_log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbatis","download_url":"https://codeload.github.com/rbatis/fast_log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254301432,"owners_count":22047904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","log","logging","rust"],"created_at":"2024-08-02T00:01:13.058Z","updated_at":"2025-05-15T08:10:48.234Z","avatar_url":"https://github.com/rbatis.png","language":"Rust","readme":"# fast_log\n\n![Build Status](https://api.travis-ci.com/rbatis/fast_log.svg?branch=master)\n[![GitHub release](https://img.shields.io/github/v/release/rbatis/fast_log)](https://github.com/rbatis/fast_log/releases)\n\n\u003cimg style=\"width: 200px;height: 200px;\" width=\"200\" height=\"200\" src=\"https://github.com/rbatis/rbatis/blob/master/logo.png?raw=true\" /\u003e\n\nA log implementation for extreme speed, using Crossbeam/channel ,once Batch write logs,fast log date, Appender\narchitecture, appender per thread\n\n* High performance,Low overhead, logs auto merge, Full APPEND mode file writing\n* Built-in `ZIP`,`LZ4` compression\n* Support use ```log::logger().flush()``` method wait to flush disk\n* Support custom file(impl Trait)\n* Support rolling log(`ByDate`,`BySize`,`ByDuration`)\n* Support Keep log(`All`,`KeepTime`,`KeepNum`) Delete old logs,Prevent logs from occupying the disk\n* uses `#![forbid(unsafe_code)]` 100% Safe Rust.\n\n```\n              -----------------\nlog data-\u003e    | main channel(crossbeam)  |   -\u003e          \n              ----------------- \n                                        ----------------                                    ----------------------\n                                  -\u003e    |thread channel)|  -\u003e background thread  |    appender1  |\n                                        ----------------                                    ----------------------\n\n                                        ----------------                                    ----------------------\n                                  -\u003e    |thread channel)|  -\u003e background thread  |    appender2  |\n                                        ----------------                                    ----------------------\n\n                                        ----------------                                    ----------------------\n                                  -\u003e    |thread channel)|  -\u003e background thread  |    appender3  |\n                                        ----------------                                    ----------------------\n\n                                        ----------------                                    ----------------------\n                                  -\u003e    |thread channel)|  -\u003e background thread  |    appender4  |\n                                        ----------------                                    ----------------------\n\n\n```\n\n* How fast is?\n\n* no flush(chan_len=1000000) benches/log.rs\n\n```\n//MACOS(Apple M1MAX-32GB)\ntest bench_log ... bench:          85 ns/iter (+/- 1,800)\n```\n\n* all log flush into file(chan_len=1000000) example/bench_test_file.rs\n\n```\n//MACOS(Apple M1MAX-32GB)\ntest bench_log ... bench:          323 ns/iter (+/- 0)\n```\n\n* how to use?\n\n```toml\nlog = \"0.4\"\nfast_log = { version = \"1.7\" }\n```\n\nor enable zip/lz4/gzip Compression library\n\n```toml\nlog = \"0.4\"\n# \"lz4\",\"zip\",\"gzip\"\nfast_log = { version = \"1.7\", features = [\"lz4\", \"zip\", \"gzip\"] }\n```\n\n#### Performance optimization(important)\n\n* use ```chan_len(Some(100000))``` Preallocating channel memory reduces the overhead of memory allocation，for example:\n\n```rust\nuse log::{error, info, warn};\nfn main() {\n    fast_log::init(Config::new().file(\"target/test.log\").chan_len(Some(100000))).unwrap();\n    log::info!(\"Commencing yak shaving{}\", 0);\n}\n```\n\n#### Use Log(Console)\n\n```rust\nuse log::{error, info, warn};\nfn main() {\n    fast_log::init(Config::new().console().chan_len(Some(100000))).unwrap();\n    log::info!(\"Commencing yak shaving{}\", 0);\n}\n```\n\n#### Use Log(Console Print)\n\n```rust\nuse log::{error, info, warn};\nfn main() {\n    fast_log::init(Config::new().console().chan_len(Some(100000))).unwrap();\n    fast_log::print(\"Commencing print\\n\".into());\n}\n```\n\n#### Use Log(File)\n\n```rust\nuse fast_log::{init_log};\nuse log::{error, info, warn};\nfn main() {\n    fast_log::init(Config::new().file(\"target/test.log\").chan_len(Some(100000))).unwrap();\n    log::info!(\"Commencing yak shaving{}\", 0);\n    info!(\"Commencing yak shaving\");\n}\n```\n\n#### Split Log(ByLogDate)\n\n```rust\nuse fast_log::config::Config;\nuse fast_log::plugin::file_split::{RollingType, KeepType, DateType, Rolling};\nuse std::thread::sleep;\nuse std::time::Duration;\nuse fast_log::plugin::packer::LogPacker;\nfn main() {\n    fast_log::init(Config::new().chan_len(Some(100000)).console().file_split(\n        \"target/logs/\",\n        Rolling::new(RollingType::ByDate(DateType::Day)),\n        KeepType::KeepNum(2),\n        LogPacker {},\n    ))\n        .unwrap();\n    for _ in 0..60 {\n        sleep(Duration::from_secs(1));\n        log::info!(\"Commencing yak shaving\");\n    }\n    log::logger().flush();\n    println!(\"you can see log files in path: {}\", \"target/logs/\")\n}\n\n```\n\n#### Split Log(ByLogSize)\n\n```rust\nuse fast_log::config::Config;\nuse fast_log::consts::LogSize;\nuse fast_log::plugin::file_split::{RollingType, KeepType, Rolling};\nuse fast_log::plugin::packer::LogPacker;\nfn main() {\n    fast_log::init(Config::new().chan_len(Some(100000)).console().file_split(\n        \"target/logs/\",\n        Rolling::new(RollingType::BySize(LogSize::KB(500))),\n        KeepType::KeepNum(2),\n        LogPacker {},\n    ))\n        .unwrap();\n    for _ in 0..40000 {\n        log::info!(\"Commencing yak shaving\");\n    }\n    log::logger().flush();\n    println!(\"you can see log files in path: {}\", \"target/logs/\")\n}\n\n```\n\n##### Custom Log(impl do_log method)\n\n```rust\nuse fast_log::appender::{FastLogRecord, LogAppender};\nuse fast_log::config::Config;\nuse fastdate::DateTime;\nuse log::Level;\n\nstruct CustomLog {}\n\nimpl LogAppender for CustomLog {\n    fn do_logs(\u0026mut self, records: \u0026[FastLogRecord]) {\n        for record in records {\n            let now = DateTime::from(record.now);\n            let data;\n            match record.level {\n                Level::Warn | Level::Error =\u003e {\n                    data = format!(\n                        \"{} {} {} - {}  {}\\n\",\n                        now, record.level, record.module_path, record.args, record.formated\n                    );\n                }\n                _ =\u003e {\n                    data = format!(\n                        \"{} {} {} - {}\\n\",\n                        \u0026now, record.level, record.module_path, record.args\n                    );\n                }\n            }\n            print!(\"{}\", data);\n        }\n    }\n}\n\nfn main() {\n    fast_log::init(Config::new().custom(CustomLog {})).unwrap();\n    log::info!(\"Commencing yak shaving\");\n    log::error!(\"Commencing error\");\n    log::logger().flush();\n}\n\n```\n","funding_links":[],"categories":["Libraries","库 Libraries"],"sub_categories":["Logging","日志记录 Logging"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbatis%2Ffast_log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbatis%2Ffast_log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbatis%2Ffast_log/lists"}