{"id":28396883,"url":"https://github.com/gistyr/better-logger","last_synced_at":"2025-07-25T18:33:58.140Z","repository":{"id":288981020,"uuid":"969730496","full_name":"Gistyr/better-logger","owner":"Gistyr","description":"Flexible sync/async Rust logger with console, file, and http output","archived":false,"fork":false,"pushed_at":"2025-05-20T21:16:08.000Z","size":1905,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-27T13:40:45.132Z","etag":null,"topics":["async","async-logging","console-logger","debug","file-logger","http-client","http-logger","lightweight","log","log-management","logger","logging","logging-library","native","network-log","rust","rust-logger","structured-logging","versatile","wasm"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/better-logger","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/Gistyr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"zenodo":null}},"created_at":"2025-04-20T20:05:12.000Z","updated_at":"2025-05-20T21:16:11.000Z","dependencies_parsed_at":"2025-04-20T21:23:13.634Z","dependency_job_id":"d684fb14-ea11-43a6-8472-9cee4bfd903d","html_url":"https://github.com/Gistyr/better-logger","commit_stats":null,"previous_names":["gistyr/better-logger"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gistyr/better-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gistyr%2Fbetter-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gistyr%2Fbetter-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gistyr%2Fbetter-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gistyr%2Fbetter-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gistyr","download_url":"https://codeload.github.com/Gistyr/better-logger/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gistyr%2Fbetter-logger/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267046180,"owners_count":24026897,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","async-logging","console-logger","debug","file-logger","http-client","http-logger","lightweight","log","log-management","logger","logging","logging-library","native","network-log","rust","rust-logger","structured-logging","versatile","wasm"],"created_at":"2025-05-31T23:31:15.667Z","updated_at":"2025-07-25T18:33:58.129Z","avatar_url":"https://github.com/Gistyr.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BETTER-LOGGER\n### Full stack developement, one logger to rule them all\n✔️ **Native Environment**       \n✔️ **WASM Environment**        \n✔️ **Terminal Logging**               \n✔️ **File Logging**              \n✔️ **Network Logging**           \n# HOW TO USE\n## 😺 ONE: Declare Feature\n```rust\n/* no default feature enabled (enabling both at once won't compile) */\nbetter-logger = { version = \"1.0.3\", features = [\"native\"] }\nbetter-logger = { version = \"1.0.3\", features = [\"wasm\"] }\n```\n## 💻 TWO: Settings\n```rust\nuse better_logger::LoggerSettings;\n\n/* native settings */\nlet settings = LoggerSettings {\n    terminal_logs: true,\n    terminal_log_lvl: \"trace\".to_string(),\n    wasm_logging: false, // must be false \n    file_logs: true,\n    file_log_lvl: \"error\".to_string(),\n    log_file_path: \"/path/to/my/file.log\".to_string(),\n    network_logs: true,\n    network_log_lvl: \"warn\".to_string(),\n    network_endpoint_url: \"http://127.0.0.1:8090/\".to_string(),\n    debug_extra: true,\n    async_logging: false,\n};\n\n/* wasm settings */\nlet settings = LoggerSettings {\n    terminal_logs: true,\n    terminal_log_lvl: \"debug\".to_string(),\n    wasm_logging: true, // must be true\n    file_logs: false, // must be false\n    file_log_lvl: \"\".to_string(), // value doesn't matter\n    log_file_path: \"\".to_string(), // value doesn't matter\n    network_logs: true,\n    network_log_lvl: \"trace\".to_string(),\n    network_endpoint_url: \"https://my.domain.com\".to_string(),\n    debug_extra: true,\n    async_logging: true, // if network_logs is true, async_logging must also be true \n};\n```\n## 💡 THREE: Initialize\n```rust\nuse better_logger::logger;\n\nfn main() {\n    if let Err(err) = logger::init(settings) {\n        eprintln!(\"{:?}\", err);\n        std::process::exit(1);\n    }\n}\n```\n## ⚠️ FOUR: Log\n```rust\nuse better_logger::logger::*;\n\nfn my_function() {\n    let debug_msg: \u0026str = \"world\";\n    let debugx_msg: String = format!(\", world\");\n    let fail: \u0026str = r#\"\"failed\"\"#;\n\n    trace!(\"hello\");\n    debug!(\"{}\", debug_msg);\n    debugx!(\"hello{}\", debugx_msg);\n    info!(\"hello message\");\n    warn!(\"world message\");\n    error!(r#\"\"hello\" \"world\" {}\"#, fail);\n}\n```\n`trace!` ➡️ (`debug!`, `debugx!`) ➡️ `info!` ➡️ `warn!` ➡️ `error!`\n| SETTING                  | DESCRIPTION                   |   \n|--------------------------|-------------------------------|\n| `terminal_logs`          | Log to terminal               |\n| `terminal_log_lvl`       | Minimum level to display      |\n| `wasm_logging`           | Log to dev tools console      | \n| `file_logs`              | Log to file                   |\n| `file_log_lvl`           | Minimum level to write        |\n| `log_file_path`          | Path to log file              |\n| `network_logs`           | Log to an HTTP endpoint       |\n| `network_log_lvl`        | Minimum level to send         |\n| `network_endpoint_url`   | URL to send log messages to   |\n| `debug_extra`            | Show `debugx!` logs           |\n| `async_logging`          | Enable async logging          |\n# ℹ️ INFORMATION\n- NATIVE console logging uses [env_logger](https://crates.io/crates/env_logger)\n- WASM console logging uses [wasm-logger](https://crates.io/crates/wasm-logger)\n- Log messages ([log](https://crates.io/crates/log)) routed through [env_logger](https://crates.io/crates/env_logger) and [wasm-logger](https://crates.io/crates/wasm-logger) **are NOT written to the file or sent via HTTP**\n    - **Only** messages emitted via [better-logger](https://crates.io/crates/better-logger) are **persisted** to the log file and sent via HTTP \n    - **You can use [better-logger](https://crates.io/crates/better-logger) as your logging facade**\n        - You would have to incorporate [better-logger](https://crates.io/crates/better-logger) into your low level crates, but only initialize **ONCE at the highest level**\n- `logger::init()` Can only be called ONCE, subsequent calls will cause a `panic!()`\n- [better-logger's](https://crates.io/crates/better-logger) NATIVE feature **requires the [tokio](https://crates.io/crates/tokio) runtime**\n    - [tokio](https://crates.io/crates/tokio) is only required when `async_logging = true`, if you log synchronously (`async_logging = false`) you don’t need [tokio](https://crates.io/crates/tokio)\n    - Many async frameworks will start the [tokio](https://crates.io/crates/tokio) runtime for you\n- `File and network logging` uses the same `formatting` as the `NATIVE console logs`\n    - `[\u003cRFC 3339 timestamp\u003e \u003cLEVEL\u003e \u003ctarget\u003e] \u003cmessage\u003e`\n- better-logger will automatically create the path and file if not already created\n    - `log_file_path` requires a `local` or `absolute` path, **a file name only will fail** `(E.g. log_file_path: \"file.log\".to_string())` \n    - File logs are **overwritten, not appended**\n- Async logging uses a **“fire and forget”** model:\n    - It spawns a new async task on the current ([tokio](https://crates.io/crates/tokio)) runtime for each message\n- Network logging uses a **“fire and forget”** model\n     - If your HTTP endpoint is down, [better-logger's](https://crates.io/crates/better-logger) will continue to run without issue\n- HTTP messages are sent as `Content-Type`: `text/plain; charset=utf-8`\n- Why is `synchronous` `network logging` NOT allowed `in WASM`? Browsers don’t allow blocking network I/O on the main thread\n- Why is `file logging` NOT allowed `in WASM`? Browsers can't talk to your file system\n- All macros use `format!()` under the hood, any string-like type is accepted\n- The `testing-wasm` and `testing-http` features are for TESTING only\n    - The NATIVE tests are `tests/async_native.rs` or `tests/sync_native.rs`\n    - The WASM test is `tests/wasm_environment/main.rs`; this is also the `\"wasm-test\"` binary\n    - The `\"http-test\"` binary is a simple HTTP server that will print log messages it receives\n- Instructions for testing are in the comments of these files \n#### What is `DEBUGX`?\nIt is just a second debug, the `debugx!()` logs will be labeled as `DEBUG` when they print\n#### Why would I want to use `DEBUGX`?\nLet’s say you’re in development, so you want to see all your ``debug`` logs. However, some of your ``debug`` logs are massive and clutter your terminal.                                                                    \nYou can mark those verbose logs as `debugx!()` and set `debug_extra = false` to hide them.                                      \nLater, if you're troubleshooting or need to view them, set `debug_extra = true` and see your extra debug logs!                  \n# 🎉 Contributing\n#### TODO:\n- Validate all user settings in the init function\n- Formatting options for the log messages\n- UDP logging\n- Append option for file logs\n- Native async logging without Tokio\n- Consolidation, optimization\n- **This list is not exclusive, all ideas are welcome**\n# License\n\u0026copy; 2025 Gistyr LLC               \nThis project, **better-logger**, is dual-licensed under your choice of:\n- **Apache License 2.0**  \n  See the [LICENSE-APACHE](LICENSE-APACHE) file or view it online at \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e\n- **MIT License**  \n  See the [LICENSE-MIT](LICENSE-MIT) file or view it online at \u003chttp://opensource.org/licenses/MIT\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgistyr%2Fbetter-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgistyr%2Fbetter-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgistyr%2Fbetter-logger/lists"}