Skip to content

Commit

Permalink
fix(logs): add timebased rolling logs
Browse files Browse the repository at this point in the history
  • Loading branch information
perryrh0dan committed Apr 30, 2021
1 parent 7e59fbd commit 37f7a10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tmpo"
description = "Command line utility to create new workspaces based on predefined templates"
version = "2.5.0"
version = "2.5.1"
authors = ["Thomas Pöhlmann <thomaspoehlmann96@googlemail.com>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,7 +13,6 @@ serde_json = "1.0.62"
serde_yaml = "0.8.17"
dirs = "3.0.1"
log = "0.4.14"
log4rs = "1.0.0"
git2 = "0.13"
colored = "2.0.0"
dialoguer = "0.7.1"
Expand All @@ -27,6 +26,10 @@ base64 = "0.13.0"
semver = "0.11.0"
convert_case = "0.4.0"
linked_hash_set = "0.1.4"
chrono = "0.4.13"

[dependencies.log4rs]
version = "1.0.0"

[dependencies.reqwest]
version = "0.11.0"
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# What's new in Tmpo

### 2.5.1

### Fix

- Setup timebased rolling log files

## 2.5.0

### Feature
Expand Down
9 changes: 8 additions & 1 deletion src/logger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use chrono::Local;
use log::LevelFilter;
use log4rs::{
append::{
Expand All @@ -21,7 +22,7 @@ pub fn init() {
.build();

// Logging to log file
let logfile_path = config::directory().join("log/output.log");
let logfile_path = config::directory().join(get_log_file_name());

let logfile = FileAppender::builder()
.encoder(Box::new(PatternEncoder::new(
Expand All @@ -47,3 +48,9 @@ pub fn init() {

log4rs::init_config(config).unwrap();
}

fn get_log_file_name() -> String {
let local = Local::now();
let timestamp = local.format("%Y-%m-%d").to_string();
return String::from("log/") + &timestamp + ".log";
}

0 comments on commit 37f7a10

Please sign in to comment.