#logging #index #file #write #log-messages #env-var #log-index

file_log

A library to write logs to files with an index

2 releases

0.1.1 Feb 6, 2024
0.1.0 Feb 6, 2024

#54 in #log-messages

MIT license

7KB
93 lines

File Log

The file_log module provides functionality for logging messages to files. Using different indexes for each run of your code.

The idea of this crate is to maintain all previous logs without needing to change the code.

This crate creates a file called log_index to maintain the last index created. Unless the environment variable FILE_LOG_INDEX is found.

Installation

Add the following to your Cargo.toml file:

[dependencies]
file_log = "0.1.0"

Quick usage

use file_log::{log, index};

fn main() {
    log!("log", "Hello"); // this will append "hello" to log_<index>.log
    log!("log" "xyz", "{} {} {}", index(), index(), index()); // this will append "<index> <index> <index>" to log_<index>.xyz
}

By running:

$ cargo run

You create the log_index file that mantains the last index used, and every log file used in the log! macro.

Or, using:

$ FILE_LOG_INDEX=10 cargo run

The log_index file will not be created, and the index in the file_log::index() function, will be 10.

Usage

See the brief example at Example


This project is licensed under the MIT License.

Dependencies

~48KB