feat: cleaner logging
- less clutter with unusable `span` info (on my personal preference)
- less errors logged when being scanned (ex.: after status response
don't log errors with ping packets, scanners usually close
the connection)
- implemented more detailed OpaqueError fields
- `tracing::Level`
- error `kind`
This commit is contained in:
parent
efe080a9e7
commit
ee7a05152e
4 changed files with 102 additions and 35 deletions
|
|
@ -1,10 +1,13 @@
|
|||
use std::{error::Error, fmt};
|
||||
use tracing::Level;
|
||||
use tracing_error::SpanTrace;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OpaqueError {
|
||||
span_trace: SpanTrace,
|
||||
pub context: String,
|
||||
pub level: Level,
|
||||
kind: Option<String>,
|
||||
}
|
||||
|
||||
impl fmt::Display for OpaqueError {
|
||||
|
|
@ -31,10 +34,20 @@ impl fmt::Display for OpaqueError {
|
|||
}
|
||||
impl Error for OpaqueError {}
|
||||
impl OpaqueError {
|
||||
pub fn create(str: &str) -> OpaqueError {
|
||||
pub fn create(context: &str) -> OpaqueError {
|
||||
Self {
|
||||
span_trace: SpanTrace::capture(),
|
||||
context: str.to_string(),
|
||||
context: context.to_string(),
|
||||
level: Level::ERROR,
|
||||
kind: None,
|
||||
}
|
||||
}
|
||||
pub fn create_with_kind(context: &str, kind: &str) -> OpaqueError {
|
||||
Self {
|
||||
span_trace: SpanTrace::capture(),
|
||||
context: context.to_string(),
|
||||
level: Level::ERROR,
|
||||
kind: Some(kind.to_string()),
|
||||
}
|
||||
}
|
||||
pub fn get_span_trace(&self) -> String {
|
||||
|
|
@ -62,6 +75,16 @@ impl OpaqueError {
|
|||
Err(_) => str,
|
||||
}
|
||||
}
|
||||
pub fn set_level(mut self, lvl: Level) -> Self {
|
||||
self.level = lvl;
|
||||
self
|
||||
}
|
||||
pub fn get_kind(&self) -> &str {
|
||||
match self.kind.as_ref() {
|
||||
Some(x) => &x,
|
||||
None => &self.context,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for OpaqueError {
|
||||
|
|
@ -69,6 +92,8 @@ impl From<String> for OpaqueError {
|
|||
Self {
|
||||
span_trace: SpanTrace::capture(),
|
||||
context: value,
|
||||
level: Level::ERROR,
|
||||
kind: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -78,6 +103,8 @@ impl From<&str> for OpaqueError {
|
|||
Self {
|
||||
span_trace: SpanTrace::capture(),
|
||||
context: value.to_string(),
|
||||
level: Level::ERROR,
|
||||
kind: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -87,6 +114,8 @@ impl From<crate::packets::ParseErrorTrace> for OpaqueError {
|
|||
Self {
|
||||
span_trace: value.context,
|
||||
context: format!("{:?}", value.inner),
|
||||
level: Level::ERROR,
|
||||
kind: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue