Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Akmot9/my_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

28 Commits

Repository files navigation

My Logger Crate

Crates.io

My Logger is a custom logging crate for Rust that provides a simple log! macro to log messages to a file with timestamps. it doesn't use unsafe rust.

Installation

Add this crate to your Cargo.toml:

[dependencies]
my_logger = "0.2.1" # Replace with the latest version available

Usage

First, import the log! macro from the crate:

use my_logger::{log, logw, logd};

Then, you can use the log! macro to log messages:

fn main() {
 log!("This is a log message.");
 log!("Another log message with a value: {}", 42);
 let err = "Something went wrong!";
 log!("error: {}", err);
 logd!("debug: {}", err);
 logw!("warning: {}", err);
}

The log messages will be written to a file named "file.log" in the current directory, and each log entry will include a timestamp.

Exemple

The log file (file.log) will contain a line like this:

[2023年08月18日 21:48:01] This is a log message.
[2023年08月18日 21:48:02] Another log message with a value: 42
[2023年08月18日 21:48:03] error: Something went wrong!
[2023年08月18日 21:48:04] warning: Something went wrong!

About

A custom logging crate for Rust to log message in a file.log

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /