Skip to content

Commit

Permalink
date format sec
Browse files Browse the repository at this point in the history
  • Loading branch information
Akmot9 committed Aug 18, 2023
1 parent 00d5b2b commit 21f8cfd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "my_logger"
version = "0.1.4"
version = "0.1.5"
authors = ["akmot9 avicocyprien@yahoo.com"]
edition = "2018"
description = "A simple marco to do logging in a file.log"
Expand Down
16 changes: 15 additions & 1 deletion file.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
[2023-08-07 21:55:28.310429743 UTC] error: Something went wrong!
[2023-08-18 15:36:32] Test message 1

[2023-08-18 15:36:32] Test message 2

[2023-08-18 15:36:32] This is a log message.

[2023-08-18 15:36:32] Another log message with a value: 42

[2023-08-18 15:36:32] This is a log message.

[2023-08-18 15:36:32] Another log message with a value: 42

[2023-08-18 15:36:32] This is a log message.

[2023-08-18 15:36:32] Another log message with a value: 42

7 changes: 4 additions & 3 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
#[macro_export]
macro_rules! log {
($($arg:tt)*) => {{
use chrono::Utc;
use chrono::Local;
use std::fs::OpenOptions;
use std::io::Write;
let log_message = format!($($arg)*);
let now = Utc::now();
let log_line = format!("[{}] {}\n", now, log_message);
let now = Local::now();
let formatted = format!("{}", now.format("%Y-%m-%d %H:%M:%S")) ;
let log_line = format!("[{}] {}\n", formatted, log_message);
println!("{log_line}");

if let Ok(mut file) = OpenOptions::new()
Expand Down

0 comments on commit 21f8cfd

Please sign in to comment.