Skip to content

Commit

Permalink
Merge pull request #26 from Tomasz-Kluczkowski/feat/log-to-files
Browse files Browse the repository at this point in the history
feat(logging): Add logging to file in json format
  • Loading branch information
Tomasz-Kluczkowski authored Dec 29, 2024
2 parents 40e7cf2 + 8713375 commit 7ca08b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target
.secrets
.test_data
.run
logs
39 changes: 18 additions & 21 deletions config/logging_config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
refresh_rate: 120 seconds

appenders:
stdout:
kind: console
Expand All @@ -6,28 +8,23 @@ appenders:
filters:
- kind: threshold
level: info
# file:
# kind: file
# path: "log/file.log"
# encoder:
# pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
# rollingfile:
# kind: rolling_file
# path: "log/rolling_file.log"
# encoder:
# pattern: "[{d(%Y-%m-%dT%H:%M:%S%.6f)} {h({l}):<5.5} {M}] {m}{n}"
# policy:
# trigger:
# kind: time
# interval: 1 minute
# roller:
# kind: fixed_window
# pattern: "log/old-rolling_file-{}.log"
# base: 0
# count: 2
rollingfile:
kind: rolling_file
path: "logs/slack-gcal-sync.log"
encoder:
kind: json
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
pattern: "logs/slack-gcal-sync-{}.log"
base: 1
count: 5
root:
level: info
appenders:
- stdout
# - file
# - rollingfile
- rollingfile
9 changes: 7 additions & 2 deletions configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ pub fn get_application_configuration(
) -> Result<ApplicationConfiguration, ConfigurationError> {
let mut app_config: ApplicationConfiguration = if Path::new(args.application_config_path.as_str()).exists() {
info!(
"Loading application configuration from file at path: {}.",
"Loading application configuration from file at path: '{}'.",
args.application_config_path
);
read_json_configuration::<ApplicationConfiguration>(&args.application_config_path)?
let app_config = read_json_configuration::<ApplicationConfiguration>(&args.application_config_path)?;
info!(
"Successfully loaded application configuration from file at path: '{}'.",
args.application_config_path
);
app_config
} else {
warn!(
"No application configuration file found at path: '{}'. Using default settings. \
Expand Down

0 comments on commit 7ca08b9

Please sign in to comment.