#log #logging #tracing

rlg

A Rust library that implements application-level logging with a simple, readable output format

2 releases

new 0.0.2 Dec 6, 2023
0.0.1 Feb 6, 2023

#147 in Debugging

MIT/Apache

29KB
308 lines

RustLogs (RLG) logo

RLG

A Rust library that implements application-level logging with a simple, readable output format.

Made With Love Crates.io Lib.rs Docs.rs License

divider

Welcome to RustLogs (RLG) 👋

RLG Banner

Website â€ĸ Documentation â€ĸ Report Bug â€ĸ Request Feature â€ĸ Contributing Guidelines

Overview 📖

RustLogs (RLG) is a Rust library that provides application-level logging with a simple, readable output format. It offers logging APIs and various helper macros to simplify common logging tasks.

Features ✨

  • Supports many log levels: ALL, DEBUG, DISABLED, ERROR, FATAL, INFO, NONE, TRACE, VERBOSE and WARNING,
  • Provides structured log formats that are easy to parse and filter,
  • Compatible with multiple output formats including:
    • Common Event Format (CEF),
    • Extended Log Format (ELF),
    • Graylog Extended Log Format (GELF),
    • JavaScript Object Notation (JSON)
    • NCSA Common Log Format (CLF),
    • W3C Extended Log File Format (W3C),
    • and more

Installation đŸ“Ļ

To use rlg in your Rust project, add the following line to your Cargo.toml file:

[dependencies]
rlg = "0.0.2"

Requirements

rlg requires Rust 1.67.0 or later.

Documentation

ℹī¸ Info: Please check out our website for more information and find our documentation on docs.rs, lib.rs and crates.io.

Usage 📖

Macros 🔨

The rlg library provides the following macros for logging:

  • macro_log!: Main macro for logging messages with customizable format.
  • macro_print_log!: Print log message to stdout.
  • macro_log_to_file!: Asynchronously log message to a file.
  • macro_warn_log!: Macro for warning log messages.
  • macro_error_log!: Macro for error log messages.
  • macro_set_log_format_clf!: Set log format to Common Log Format (CLF).
  • macro_debug_log!: Conditional debug logging.

macro_log!

The macro_log! macro is the main macro for logging messages. It takes the following arguments:

  • session_id: A unique identifier for the log session.
  • time: The timestamp of the log message.
  • level: The log level, such as DEBUG, INFO, WARN, or ERROR.
  • component: The name of the component that generated the log message.
  • description: The description of the log message.
  • format: The log format, such as CLF, JSON, or GELF.

Example usage of the macro_log! macro:

use rlg::{Log, LogLevel, LogFormat};
use vrd::Random;

let log = macro_log!(
    &Random::default().int(0, 1_000_000_000).to_string(),
    "2023-04-18T12:38:55Z",
    &LogLevel::INFO,
    "ComponentName",
    "Log message description",
    &LogFormat::CLF,
);

macro_log!(log);

Examples

RLG comes with a set of examples that you can use to get started. The examples are located in the examples directory of the project. To run the examples, clone the repository and run the following command in your terminal from the project root directory.

cargo run --example rlg

Semantic Versioning Policy đŸšĨ

For transparency into our release cycle and in striving to maintain backward compatibility, QRC follows semantic versioning.

License 📝

The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).

Contribution 🤝

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

divider

Acknowledgements 💙

A big thank you to all the awesome contributors of Mini Functions for their help and support. A special thank you goes to the Rust Reddit community for providing a lot of useful suggestions on how to improve this project.

Dependencies

~6–14MB
~152K SLoC