logger-nx 0.2.0

A high-performance hourly-rotating file logger implementing the `log` facade, with TTL-based cleanup. Behaviorally equivalent to @imcooder/node-logger.
Documentation

logger-nx

Crates.io docs.rs License: MIT

A high-performance hourly-rotating file logger for Rust, implementing the log facade.

Behaviorally equivalent to the Node.js @imcooder/node-logger library โ€” same log format, same file naming convention, same TTL-based cleanup.

Features

  • ๐Ÿ“ Writes to <app_name>.log, rotates to <app_name>.log.YYYYMMDDHH every hour
  • ๐Ÿงน Auto-deletes files older than ttl_hours (default 72 h)
  • โšก All I/O on a dedicated background thread โ€” calling threads never block
  • ๐Ÿ”’ Zero unsafe code
  • ๐ŸŽฏ Drop-in with the standard log crate โ€” no changes to existing log::info! calls

Log Format

[2026-04-21 10:28:35.123] [INFO] my-app - Application started
[2026-04-21 10:28:35.124] [WARN] my-app - Low disk space
[2026-04-21 10:28:35.125] [ERROR] my-app - Connection failed: timeout

Installation

[dependencies]
logger-nx = "0.1"
log = "0.4"

Quick Start

use logger_nx::{Config, init};
use log::LevelFilter;
use std::path::PathBuf;

fn main() {
    // Option 1: convenience constructor
    logger_nx::init(logger_nx::config("my-app", "/var/log/my-app")).unwrap();

    // Option 2: full config
    logger_nx::init(Config {
        app_name: "my-app".to_string(),
        log_dir:  PathBuf::from("/var/log/my-app"),
        ttl_hours: 72,
        level:    LevelFilter::Info,
        console:  false,
    }).unwrap();

    log::info!("Application started");
    log::warn!("Low disk space");
    log::error!("Connection failed: {}", "timeout");

    // Flush & stop background thread before exit
    logger_nx::shutdown();
}

Configuration

Field Type Default Description
app_name String "app" App / category name. Used in log lines and filenames
log_dir PathBuf system temp Directory where log files are created
ttl_hours i64 72 Hours to retain rotated log files
level LevelFilter Info Minimum log level written to file
console bool true (debug) / false (release) Also print to stderr

File Naming

File Description
my-app.log Current log file (active)
my-app.log.2026042110 Rotated archive for the 10:00โ€“11:00 slot on 2026-04-21

Comparison with @imcooder/node-logger

Feature @imcooder/node-logger logger-nx
Log format [time] [LEVEL] app - msg [time] [LEVEL] app - msg โœ…
File naming app.log.YYYYMMDDHH app.log.YYYYMMDDHH โœ…
Hourly rotation โœ… โœ…
TTL cleanup โœ… (72 h default) โœ… (72 h default)
Async I/O โœ… (Node streams) โœ… (background thread + channel)
Console output โœ… โœ…
Zero blocking โœ… โœ…

License

MIT ยฉ imcooder