Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented abstracted logging methods for requests elapsed time and …
…for rejected api tokens
- Loading branch information
danielsanchezq
committed
Aug 3, 2020
1 parent
62d219f
commit 0819356
Showing
4 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use logging_lib::messages::{DefaultLogMessageBuilder, DefaultMetadata, LogMessageId}; | ||
use std::time::Duration; | ||
|
||
pub fn log_request_elapsed_time(elapsed_time: Duration) { | ||
let elapsed = elapsed_time.as_nanos().to_string(); | ||
let mut metadata = DefaultMetadata::new(); | ||
metadata.insert("elapsed_nano_seconds".into(), elapsed.clone()); | ||
DefaultLogMessageBuilder::new() | ||
.with_level(log::Level::Info) | ||
.with_tags(vec!["request", "elapsed"]) | ||
.with_message(format!("Request elapsed time: {}ns", elapsed)) | ||
.with_id(LogMessageId::Other("request_elapsed_time".into())) | ||
.build() | ||
.log(); | ||
} | ||
|
||
pub fn log_rejected_api_key(api_key: String) { | ||
let mut metadata = DefaultMetadata::new(); | ||
metadata.insert("api_key".into(), api_key.clone()); | ||
DefaultLogMessageBuilder::new() | ||
.with_level(log::Level::Info) | ||
.with_tags(vec!["api_key", "reject"]) | ||
.with_message(format!("Rejected API-Token: {}", api_key)) | ||
.with_id(LogMessageId::Other("RejectedAPIToken".into())) | ||
.build() | ||
.log(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters