don't print auth token on mpv logs
This commit is contained in:
parent
1f482ab512
commit
e52adda2ed
2 changed files with 19 additions and 6 deletions
|
@ -52,6 +52,7 @@ impl From<reqwest::Error> for Error {
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
client: reqwest::Client,
|
client: reqwest::Client,
|
||||||
base_url: reqwest::Url,
|
base_url: reqwest::Url,
|
||||||
|
token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_random_salt(length: usize) -> String {
|
fn get_random_salt(length: usize) -> String {
|
||||||
|
@ -103,9 +104,14 @@ impl Client {
|
||||||
.user_agent(crate::USER_AGENT)
|
.user_agent(crate::USER_AGENT)
|
||||||
.build()?,
|
.build()?,
|
||||||
base_url,
|
base_url,
|
||||||
|
token: token.to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn strip_token(&self, string: &str) -> String {
|
||||||
|
string.replace(&self.token, "[authentication token]")
|
||||||
|
}
|
||||||
|
|
||||||
async fn send<T: serde::de::DeserializeOwned + Send + 'static>(
|
async fn send<T: serde::de::DeserializeOwned + Send + 'static>(
|
||||||
&self,
|
&self,
|
||||||
request: reqwest::RequestBuilder,
|
request: reqwest::RequestBuilder,
|
||||||
|
|
|
@ -522,22 +522,29 @@ mod imp {
|
||||||
fn on_log_message(&self, event: crate::mpv::event::LogMessageEvent) {
|
fn on_log_message(&self, event: crate::mpv::event::LogMessageEvent) {
|
||||||
let span = span!(Level::DEBUG, "mpv_log", prefix = event.prefix);
|
let span = span!(Level::DEBUG, "mpv_log", prefix = event.prefix);
|
||||||
let _guard = span.enter();
|
let _guard = span.enter();
|
||||||
|
|
||||||
|
let event_text = event.text.trim_end_matches("\n"); // trim training newline
|
||||||
|
let event_text = match self.api.borrow().as_ref() {
|
||||||
|
None => event_text.to_string(),
|
||||||
|
Some(api) => api.strip_token(event_text), // hide auth token if printing url
|
||||||
|
};
|
||||||
|
|
||||||
match event.log_level {
|
match event.log_level {
|
||||||
// level has to be 'static so this sux
|
// level has to be 'static so this sux
|
||||||
l if l <= 20 => {
|
l if l <= 20 => {
|
||||||
event!(target: "mpv_event", Level::ERROR, "{}", event.text.trim())
|
event!(target: "mpv_event", Level::ERROR, "{}", event_text)
|
||||||
}
|
}
|
||||||
l if l <= 30 => {
|
l if l <= 30 => {
|
||||||
event!(target: "mpv_event", Level::WARN, "{}", event.text.trim())
|
event!(target: "mpv_event", Level::WARN, "{}", event_text)
|
||||||
}
|
}
|
||||||
l if l <= 40 => {
|
l if l <= 40 => {
|
||||||
event!(target: "mpv_event", Level::INFO, "{}", event.text.trim())
|
event!(target: "mpv_event", Level::INFO, "{}", event_text)
|
||||||
}
|
}
|
||||||
l if l <= 60 => {
|
l if l <= 60 => {
|
||||||
event!(target: "mpv_event", Level::DEBUG, "{}", event.text.trim())
|
event!(target: "mpv_event", Level::DEBUG, "{}", event_text)
|
||||||
}
|
}
|
||||||
l if l <= 70 => {
|
l if l <= 70 => {
|
||||||
event!(target: "mpv_event", Level::TRACE, "{}", event.text.trim())
|
event!(target: "mpv_event", Level::TRACE, "{}", event_text)
|
||||||
}
|
}
|
||||||
// should be unused
|
// should be unused
|
||||||
_ => event!(
|
_ => event!(
|
||||||
|
@ -545,7 +552,7 @@ mod imp {
|
||||||
Level::DEBUG,
|
Level::DEBUG,
|
||||||
log_level = event.log_level,
|
log_level = event.log_level,
|
||||||
"{}",
|
"{}",
|
||||||
event.text.trim(),
|
event_text,
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue