Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
60
.github/formatting_codes.md
vendored
60
.github/formatting_codes.md
vendored
@ -1,60 +0,0 @@
|
|||||||
# Formatting codes
|
|
||||||
|
|
||||||
When formatting a message you can use arguments in the form of `{{name}}`. Following arguments are available by default:
|
|
||||||
|
|
||||||
| Name | Description | Example |
|
|
||||||
| :---------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------- |
|
|
||||||
| `message` | Log message | `My message` |
|
|
||||||
| `level` | Uppercase level name. Will have colors attached to it if the output is stdout or stderr | `ERROR` |
|
|
||||||
| `timestamp` | UTC timestamp the log function was called (Technically the time the format function was called). Can be formatted using the `timestamp_format` field of the formatter | `2023-11-27 20:49:47` |
|
|
||||||
| `path` | Relative path to the caller of the log macro | `src\main.rs` |
|
|
||||||
|
|
||||||
Users can also specify custom arguments by either supplying a `Vec<(&str, String)>` of key-value pairs of the argument name and value or using the fields in the macros:
|
|
||||||
|
|
||||||
```rust,ignore
|
|
||||||
logging_rs::log!(logger, "My message with {{arg}}", "arg" = "my arguments")
|
|
||||||
```
|
|
||||||
|
|
||||||
## ASCII format characters
|
|
||||||
|
|
||||||
Most terminals support special ASCII characters.
|
|
||||||
|
|
||||||
| Name | Description |
|
|
||||||
| :--------------------- | :-------------------------------------------------- |
|
|
||||||
| `end` | Escapes any previously started escape sequences |
|
|
||||||
| `bold` | Makes the text bold |
|
|
||||||
| `italic` | Makes the text italic |
|
|
||||||
| `underline` | Underlines the text |
|
|
||||||
| `overline` | Overlines the text (Not supported by all terminals) |
|
|
||||||
| `color.black` | Makes the text black |
|
|
||||||
| `color.red` | Makes the text red |
|
|
||||||
| `color.green` | Makes the text green |
|
|
||||||
| `color.yellow` | Makes the text yellow |
|
|
||||||
| `color.blue` | Makes the text blue |
|
|
||||||
| `color.magenta` | Makes the text magenta |
|
|
||||||
| `color.cyan` | Makes the text cyan |
|
|
||||||
| `color.white` | Makes the text white |
|
|
||||||
| `color.bright_black` | Makes the text bright black |
|
|
||||||
| `color.bright_red` | Makes the text bright red |
|
|
||||||
| `color.bright_green` | Makes the text bright green |
|
|
||||||
| `color.bright_yellow` | Makes the text bright yellow |
|
|
||||||
| `color.bright_blue` | Makes the text bright blue |
|
|
||||||
| `color.bright_magenta` | Makes the text bright magenta |
|
|
||||||
| `color.bright_cyan` | Makes the text bright cyan |
|
|
||||||
| `color.bright_white` | Makes the text bright white |
|
|
||||||
| `back.black` | Makes the text background black |
|
|
||||||
| `back.red` | Makes the text background red |
|
|
||||||
| `back.green` | Makes the text background green |
|
|
||||||
| `back.yellow` | Makes the text background yellow |
|
|
||||||
| `back.blue` | Makes the text background blue |
|
|
||||||
| `back.magenta` | Makes the text background magenta |
|
|
||||||
| `back.cyan` | Makes the text background cyan |
|
|
||||||
| `back.white` | Makes the text background white |
|
|
||||||
| `back.bright_black` | Makes the text background bright black |
|
|
||||||
| `back.bright_red` | Makes the text background bright red |
|
|
||||||
| `back.bright_green` | Makes the text background bright green |
|
|
||||||
| `back.bright_yellow` | Makes the text background bright yellow |
|
|
||||||
| `back.bright_blue` | Makes the text background bright blue |
|
|
||||||
| `back.bright_magenta` | Makes the text background bright magenta |
|
|
||||||
| `back.bright_cyan` | Makes the text background bright cyan |
|
|
||||||
| `back.bright_white` | Makes the text background bright white |
|
|
||||||
@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "logging-rs"
|
name = "logging-rs"
|
||||||
description = "logging-rs helps you add logging to your projects using simple macros."
|
description = "logging-rs helps you add logging to your projects using simple macros."
|
||||||
version = "1.1.0"
|
version = "1.0.0"
|
||||||
authors = [
|
authors = [
|
||||||
"ElBe-Plaq <elbe.dev.plaq@gmail.com>"
|
"ElBe-Plaq <elbe.dev.plaq@gmail.com>"
|
||||||
]
|
]
|
||||||
@ -18,4 +18,4 @@ categories = [
|
|||||||
publish = true
|
publish = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = "0.4.31"
|
# chrono = "0.4.31"
|
||||||
|
|||||||
@ -9,11 +9,4 @@ fn main() {
|
|||||||
logging_rs::error!(logger, "Error!");
|
logging_rs::error!(logger, "Error!");
|
||||||
logging_rs::fatal!(logger, "Fatal error!");
|
logging_rs::fatal!(logger, "Fatal error!");
|
||||||
logging_rs::log!(logger, "Log message");
|
logging_rs::log!(logger, "Log message");
|
||||||
|
|
||||||
logging_rs::debug!(logger, "Debug message with {{more_info}}", "more_info" = "additional information");
|
|
||||||
logging_rs::info!(logger, "Info and {{details}}", "details" = "more stuff");
|
|
||||||
logging_rs::warn!(logger, "Warning: {{name}} is bad", "name" = "War");
|
|
||||||
logging_rs::error!(logger, "Error! {{stuff}} went wrong", "stuff" = "Everything");
|
|
||||||
logging_rs::fatal!(logger, "Fatal error! Code {{code}}", "code" = "404");
|
|
||||||
logging_rs::log!(logger, "Log message and {{more}}", "more" = "more");
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
#![doc = include_str!("../.github/errors.md")]
|
#![doc = include_str!("../.github/errors.md")]
|
||||||
// logging-rs errors
|
// logging-rs errors
|
||||||
// Version: 1.1.0
|
// Version: 1.0.0
|
||||||
|
|
||||||
// Copyright (c) 2023-present ElBe Development.
|
// Copyright (c) 2023-present ElBe Development.
|
||||||
|
|
||||||
|
|||||||
254
src/lib.rs
254
src/lib.rs
@ -1,6 +1,6 @@
|
|||||||
#![doc = include_str!("../.github/README.md")]
|
#![doc = include_str!("../.github/README.md")]
|
||||||
// Logging-rs
|
// Logging-rs.
|
||||||
// Version: 1.1.0
|
// Version: 1.0.0
|
||||||
|
|
||||||
// Copyright (c) 2023-present I Language Development.
|
// Copyright (c) 2023-present I Language Development.
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ pub mod errors;
|
|||||||
use std;
|
use std;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use chrono;
|
// use chrono;
|
||||||
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -62,6 +62,25 @@ pub enum Level {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
// HTTP METHODS //
|
||||||
|
//////////////////
|
||||||
|
|
||||||
|
// HTTP methods
|
||||||
|
/*#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
|
||||||
|
pub enum HTTPMethod {
|
||||||
|
/// GET request. The default value
|
||||||
|
#[default]
|
||||||
|
GET,
|
||||||
|
/// POST request
|
||||||
|
POST,
|
||||||
|
/// PUT request
|
||||||
|
PUT,
|
||||||
|
/// PATCH request
|
||||||
|
PATCH
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
// OUTPUT TYPE //
|
// OUTPUT TYPE //
|
||||||
/////////////////
|
/////////////////
|
||||||
@ -78,7 +97,12 @@ pub enum Output {
|
|||||||
FILE {
|
FILE {
|
||||||
/// File path
|
/// File path
|
||||||
path: String
|
path: String
|
||||||
}
|
},
|
||||||
|
// Web request (not currently implemented)
|
||||||
|
/*REQUEST {
|
||||||
|
method: HTTPMethod,
|
||||||
|
url: String
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -184,7 +208,7 @@ impl Formatter {
|
|||||||
/// logging_rs::Output::default(),
|
/// logging_rs::Output::default(),
|
||||||
/// logging_rs::Level::default(),
|
/// logging_rs::Level::default(),
|
||||||
/// "Some message with an {{argument}}",
|
/// "Some message with an {{argument}}",
|
||||||
/// vec![("argument", "replaced value".to_string())]
|
/// vec![("argument", "replaced value")]
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@ -193,78 +217,90 @@ impl Formatter {
|
|||||||
/// - [`Formatter`]
|
/// - [`Formatter`]
|
||||||
/// - [`Output`]
|
/// - [`Output`]
|
||||||
/// - [`Level`]
|
/// - [`Level`]
|
||||||
#[doc = include_str!("../.github/formatting_codes.md")]
|
pub fn format<'a>(&self, output: Output, level: Level, message: &'a str, mut arguments: Vec<(&str, &'a str)>) -> String {
|
||||||
pub fn format<'a>(&self, output: Output, level: Level, message: &'a str, mut extra_arguments: Vec<(&str, String)>) -> String {
|
// TODO (ElBe): Make timestamps work. None of chrono, time or humantime have the things I want
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
let timestamp: &str = "TIMESTAMP";
|
||||||
let mut colors: Vec<(&str, String)> = vec![
|
|
||||||
|
// let time = chrono::Utc::now();
|
||||||
|
//let _timestamp = time.format("%Y-%m-%d %H:%M:%S").to_string(); //chrono::format::DelayedFormat<chrono::format::StrftimeItems<'_>>
|
||||||
|
//let parsed = chrono::NaiveDateTime::parse_from_str(&_timestamp.to_string(), "%Y-%m-%d %H:%M:%S").expect("Bad");
|
||||||
|
|
||||||
|
//let borrowed = &_timestamp;
|
||||||
|
|
||||||
|
//println!("{}", _timestamp);
|
||||||
|
//println!("{}", parsed.to_string().as_str());
|
||||||
|
|
||||||
|
// arguments.push(("timestamp", &time.format("%Y-%m-%d %H:%M:%S").to_string()));
|
||||||
|
|
||||||
|
let mut colors: Vec<(&str, &str)> = vec![
|
||||||
// Formatting codes
|
// Formatting codes
|
||||||
("end", "\x1b[0m".to_string()),
|
("end", "\x1b[0m"),
|
||||||
("bold", "\x1b[1m".to_string()),
|
("bold", "\x1b[1m"),
|
||||||
("italic", "\x1b[3m".to_string()),
|
("italic", "\x1b[3m"),
|
||||||
("underline", "\x1b[4m".to_string()),
|
("underline", "\x1b[4m"),
|
||||||
("overline", "\x1b[53m".to_string()),
|
("overline", "\x1b[53m"),
|
||||||
|
|
||||||
// Foreground colors
|
// Foreground colors
|
||||||
("color.black", "\x1b[30m".to_string()),
|
("color.black", "\x1b[30m"),
|
||||||
("color.red", "\x1b[31m".to_string()),
|
("color.red", "\x1b[31m"),
|
||||||
("color.green", "\x1b[32m".to_string()),
|
("color.green", "\x1b[32m"),
|
||||||
("color.yellow", "\x1b[33m".to_string()),
|
("color.yellow", "\x1b[33m"),
|
||||||
("color.blue", "\x1b[34m".to_string()),
|
("color.blue", "\x1b[34m"),
|
||||||
("color.magenta", "\x1b[35m".to_string()),
|
("color.magenta", "\x1b[35m"),
|
||||||
("color.cyan", "\x1b[36m".to_string()),
|
("color.cyan", "\x1b[36m"),
|
||||||
("color.white", "\x1b[37m".to_string()),
|
("color.white", "\x1b[37m"),
|
||||||
|
|
||||||
// Bright foreground colors
|
// Bright foreground colors
|
||||||
("color.bright_black", "\x1b[90m".to_string()),
|
("color.bright_black", "\x1b[90m"),
|
||||||
("color.bright_red", "\x1b[91m".to_string()),
|
("color.bright_red", "\x1b[91m"),
|
||||||
("color.bright_green", "\x1b[92m".to_string()),
|
("color.bright_green", "\x1b[92m"),
|
||||||
("color.bright_yellow", "\x1b[93m".to_string()),
|
("color.bright_yellow", "\x1b[93m"),
|
||||||
("color.bright_blue", "\x1b[94m".to_string()),
|
("color.bright_blue", "\x1b[94m"),
|
||||||
("color.bright_magenta", "\x1b[95m".to_string()),
|
("color.bright_magenta", "\x1b[95m"),
|
||||||
("color.bright_cyan", "\x1b[96m".to_string()),
|
("color.bright_cyan", "\x1b[96m"),
|
||||||
("color.bright_white", "\x1b[97m".to_string()),
|
("color.bright_white", "\x1b[97m"),
|
||||||
|
|
||||||
// Background colors
|
// Background colors
|
||||||
("back.black", "\x1b[40m".to_string()),
|
("back.black", "\x1b[40m"),
|
||||||
("back.red", "\x1b[41m".to_string()),
|
("back.red", "\x1b[41m"),
|
||||||
("back.green", "\x1b[42m".to_string()),
|
("back.green", "\x1b[42m"),
|
||||||
("back.yellow", "\x1b[43m".to_string()),
|
("back.yellow", "\x1b[43m"),
|
||||||
("back.blue", "\x1b[44m".to_string()),
|
("back.blue", "\x1b[44m"),
|
||||||
("back.magenta", "\x1b[45m".to_string()),
|
("back.magenta", "\x1b[45m"),
|
||||||
("back.cyan", "\x1b[46m".to_string()),
|
("back.cyan", "\x1b[46m"),
|
||||||
("back.white", "\x1b[47m".to_string()),
|
("back.white", "\x1b[47m"),
|
||||||
|
|
||||||
// Bright background colors
|
// Bright background colors
|
||||||
("back.bright_black", "\x1b[100m".to_string()),
|
("back.bright_black", "\x1b[100m"),
|
||||||
("back.bright_red", "\x1b[101m".to_string()),
|
("back.bright_red", "\x1b[101m"),
|
||||||
("back.bright_green", "\x1b[102m".to_string()),
|
("back.bright_green", "\x1b[102m"),
|
||||||
("back.bright_yellow", "\x1b[103m".to_string()),
|
("back.bright_yellow", "\x1b[103m"),
|
||||||
("back.bright_blue", "\x1b[104m".to_string()),
|
("back.bright_blue", "\x1b[104m"),
|
||||||
("back.bright_magenta", "\x1b[105m".to_string()),
|
("back.bright_magenta", "\x1b[105m"),
|
||||||
("back.bright_cyan", "\x1b[106m".to_string()),
|
("back.bright_cyan", "\x1b[106m"),
|
||||||
("back.bright_white", "\x1b[107m".to_string()),
|
("back.bright_white", "\x1b[107m"),
|
||||||
];
|
];
|
||||||
|
|
||||||
let level_string: (&str, String) = ("level", match level {
|
let level_string: (&str, &str) = ("level", match level {
|
||||||
Level::DEBUG => "DEBUG",
|
Level::DEBUG => "DEBUG",
|
||||||
Level::INFO => "INFO",
|
Level::INFO => "INFO",
|
||||||
Level::WARN => "WARNING",
|
Level::WARN => "WARNING",
|
||||||
Level::ERROR => "ERROR",
|
Level::ERROR => "ERROR",
|
||||||
Level::FATAL => "FATAL",
|
Level::FATAL => "FATAL",
|
||||||
Level::MESSAGE => "MESSAGE"
|
Level::MESSAGE => "MESSAGE"
|
||||||
}.to_string());
|
});
|
||||||
let colored_level_string: (&str, String) = ("level", match level {
|
let colored_level_string: (&str, &str) = ("level", match level {
|
||||||
Level::DEBUG => "DEBUG",
|
Level::DEBUG => "DEBUG",
|
||||||
Level::INFO => "{{color.blue}}INFO{{end}}",
|
Level::INFO => "{{color.blue}}INFO{{end}}",
|
||||||
Level::WARN => "{{color.yellow}}WARNING{{end}}",
|
Level::WARN => "{{color.yellow}}WARNING{{end}}",
|
||||||
Level::ERROR => "{{color.red}}ERROR{{end}}",
|
Level::ERROR => "{{color.red}}ERROR{{end}}",
|
||||||
Level::FATAL => "{{color.red}}FATAL{{end}}",
|
Level::FATAL => "{{color.red}}FATAL{{end}}",
|
||||||
Level::MESSAGE => "{{color.blue}}MESSAGE{{end}}"
|
Level::MESSAGE => "{{color.blue}}MESSAGE{{end}}"
|
||||||
}.to_string());
|
});
|
||||||
|
|
||||||
arguments.push(("message", message.to_string()));
|
arguments.push(("message", message));
|
||||||
arguments.push(("timestamp", chrono::Utc::now().format(&self.timestamp_format).to_string()));
|
arguments.push(("timestamp", timestamp));
|
||||||
arguments.append(&mut extra_arguments);
|
//arguments.push(("timestamp", chrono::Utc::now().format("%Y-%m-%d %H:%M:%S").to_string().to_owned().as_str()));
|
||||||
|
|
||||||
let mut result: String = match output {
|
let mut result: String = match output {
|
||||||
Output::STDOUT | Output::STDERR => {
|
Output::STDOUT | Output::STDERR => {
|
||||||
@ -280,7 +316,7 @@ impl Formatter {
|
|||||||
arguments.append(&mut colors);
|
arguments.append(&mut colors);
|
||||||
|
|
||||||
for (key, value) in arguments {
|
for (key, value) in arguments {
|
||||||
result = result.replace(("{{".to_owned() + key + "}}").as_str(), &value);
|
result = result.replace(("{{".to_owned() + key + "}}").as_str(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.clone();
|
return result.clone();
|
||||||
@ -363,7 +399,6 @@ impl Logger {
|
|||||||
/// - `message`: The message to log
|
/// - `message`: The message to log
|
||||||
/// - `level`: The log [`Level`] to use for logging
|
/// - `level`: The log [`Level`] to use for logging
|
||||||
/// - `path`: The path of the calling file
|
/// - `path`: The path of the calling file
|
||||||
/// - `arguments`: A list of arguments to use when formatting the message
|
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
@ -377,8 +412,7 @@ impl Logger {
|
|||||||
/// logger.log(
|
/// logger.log(
|
||||||
/// "Some message",
|
/// "Some message",
|
||||||
/// logging_rs::Level::default(),
|
/// logging_rs::Level::default(),
|
||||||
/// "src/lib.rs",
|
/// "src/lib.rs"
|
||||||
/// vec![]
|
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
@ -392,10 +426,9 @@ impl Logger {
|
|||||||
/// - [`log!()`]
|
/// - [`log!()`]
|
||||||
/// - [`Logger`]
|
/// - [`Logger`]
|
||||||
/// - [`Level`]
|
/// - [`Level`]
|
||||||
pub fn log(&self, message: &str, level: Level, path: &str, mut arguments: Vec<(&str, String)>) {
|
pub fn log(&self, message: &str, level: Level, path: &str) {
|
||||||
arguments.push(("path", path.to_string()));
|
|
||||||
for writable in self.writable_list.clone() {
|
for writable in self.writable_list.clone() {
|
||||||
let formatted: String = self.formatter.format(writable.clone(), level, message, arguments.clone());
|
let formatted: String = self.formatter.format(writable.clone(), level, message, vec![("path", path)]);
|
||||||
|
|
||||||
match writable {
|
match writable {
|
||||||
Output::STDOUT => println!("{}", formatted),
|
Output::STDOUT => println!("{}", formatted),
|
||||||
@ -411,7 +444,16 @@ impl Logger {
|
|||||||
if let Err(error) = write {
|
if let Err(error) = write {
|
||||||
errors::Error::new("Writing error", "The file could not be edited", 2).raise(format!("File: {}\nText: {}\nError: {}", path, formatted, error).as_str());
|
errors::Error::new("Writing error", "The file could not be edited", 2).raise(format!("File: {}\nText: {}\nError: {}", path, formatted, error).as_str());
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
// TODO (ElBe): Add HTTP support
|
||||||
|
/*Output::REQUEST { ref method, ref url } => {
|
||||||
|
match method {
|
||||||
|
HTTPMethod::GET => {},
|
||||||
|
HTTPMethod::POST => {},
|
||||||
|
HTTPMethod::PUT => {},
|
||||||
|
HTTPMethod::PATCH => {},
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -435,7 +477,6 @@ impl Logger {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::debug!(logger, "A message");
|
/// logging_rs::debug!(logger, "A message");
|
||||||
/// logging_rs::debug!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -450,19 +491,7 @@ impl Logger {
|
|||||||
macro_rules! debug {
|
macro_rules! debug {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::DEBUG, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::DEBUG, std::panic::Location::caller().file());
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::DEBUG, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -480,7 +509,6 @@ macro_rules! debug {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::info!(logger, "A message");
|
/// logging_rs::info!(logger, "A message");
|
||||||
/// logging_rs::info!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -495,21 +523,9 @@ macro_rules! debug {
|
|||||||
macro_rules! info {
|
macro_rules! info {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::INFO, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::INFO, std::panic::Location::caller().file());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::INFO, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs the given message with logging level [`Level::WARN`].
|
/// Logs the given message with logging level [`Level::WARN`].
|
||||||
@ -525,7 +541,6 @@ macro_rules! info {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::warn!(logger, "A message");
|
/// logging_rs::warn!(logger, "A message");
|
||||||
/// logging_rs::warn!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -540,21 +555,9 @@ macro_rules! info {
|
|||||||
macro_rules! warn {
|
macro_rules! warn {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::WARN, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::WARN, std::panic::Location::caller().file());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::WARN, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs the given message with logging level [`Level::ERROR`].
|
/// Logs the given message with logging level [`Level::ERROR`].
|
||||||
@ -570,7 +573,6 @@ macro_rules! warn {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::error!(logger, "A message");
|
/// logging_rs::error!(logger, "A message");
|
||||||
/// logging_rs::error!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -585,21 +587,9 @@ macro_rules! warn {
|
|||||||
macro_rules! error {
|
macro_rules! error {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::ERROR, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::ERROR, std::panic::Location::caller().file());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::ERROR, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs the given message with logging level [`Level::FATAL`].
|
/// Logs the given message with logging level [`Level::FATAL`].
|
||||||
@ -615,7 +605,6 @@ macro_rules! error {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::fatal!(logger, "A message");
|
/// logging_rs::fatal!(logger, "A message");
|
||||||
/// logging_rs::fatal!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -630,21 +619,9 @@ macro_rules! error {
|
|||||||
macro_rules! fatal {
|
macro_rules! fatal {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::FATAL, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::FATAL, std::panic::Location::caller().file());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::FATAL, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Logs the given message with logging level [`Level::MESSAGE`].
|
/// Logs the given message with logging level [`Level::MESSAGE`].
|
||||||
@ -660,7 +637,6 @@ macro_rules! fatal {
|
|||||||
/// # use logging_rs;
|
/// # use logging_rs;
|
||||||
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
/// # let logger: logging_rs::Logger = logging_rs::Logger::default();
|
||||||
/// logging_rs::log!(logger, "A message");
|
/// logging_rs::log!(logger, "A message");
|
||||||
/// logging_rs::log!(logger, "A message with more {{details}}", "details" = "stuff");
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// # See also
|
/// # See also
|
||||||
@ -675,19 +651,7 @@ macro_rules! fatal {
|
|||||||
macro_rules! log {
|
macro_rules! log {
|
||||||
($logger:expr, $message:expr) => {
|
($logger:expr, $message:expr) => {
|
||||||
{
|
{
|
||||||
$logger.log($message, $crate::Level::MESSAGE, std::panic::Location::caller().file(), vec![]);
|
$logger.log($message, $crate::Level::MESSAGE, std::panic::Location::caller().file());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
($logger:expr, $message:expr, $($argument_name:literal = $argument_value:literal),* $(,)?) => {
|
|
||||||
{
|
|
||||||
let mut arguments: Vec<(&str, String)> = vec![];
|
|
||||||
|
|
||||||
$(
|
|
||||||
arguments.push(($argument_name, $argument_value.to_string()));
|
|
||||||
)*
|
|
||||||
|
|
||||||
$logger.log($message, $crate::Level::MESSAGE, std::panic::Location::caller().file(), arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// logging-rs error tests
|
// logging-rs error tests
|
||||||
// Version: 1.1.0
|
// Version: 1.0.0
|
||||||
|
|
||||||
// Copyright (c) 2023-present ElBe Development.
|
// Copyright (c) 2023-present ElBe Development.
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
// logging-rs tests
|
// logging-rs tests
|
||||||
// Version: 1.1.0
|
// Version: 1.0.0
|
||||||
|
|
||||||
// Copyright (c) 2023-present ElBe Development.
|
// Copyright (c) 2023-present ElBe Development.
|
||||||
|
|
||||||
@ -25,8 +25,6 @@
|
|||||||
// IMPORTS AND USE STATEMENTS //
|
// IMPORTS AND USE STATEMENTS //
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use chrono;
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use logging_rs;
|
use logging_rs;
|
||||||
|
|
||||||
@ -87,7 +85,7 @@ mod tests {
|
|||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
formatter.format(logging_rs::Output::default(), logging_rs::Level::default(), "Test", vec![]),
|
formatter.format(logging_rs::Output::default(), logging_rs::Level::default(), "Test", vec![]),
|
||||||
format!("[\x1b[94m{}\x1b[0m] [DEBUG] {{{{path}}}}: Test", chrono::Local::now().format(&logging_rs::Formatter::default().timestamp_format))
|
"[\x1b[94mTIMESTAMP\x1b[0m] [DEBUG] {{path}}: Test"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user