Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions crates/logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@ where
let mut visitor = LogVisitor(&mut fields);
event.record(&mut visitor);

let binding = fields.clone();
let message = binding.get("message");
let target = binding.get("target");

fields.remove("message");
fields.remove("target");
let message = fields.remove("message");
let target = fields.remove("target");

let mut logfmt = LogFormat {
timestamp: Local::now(),
message,
target,
level: event.metadata().level(),
fields: fields.clone(),
fields,
};

if let Some(logfile) = &self.logfile {
Expand Down Expand Up @@ -70,14 +66,14 @@ where
}

/// Formatting Logs
struct LogFormat<'a> {
struct LogFormat {
timestamp: DateTime<Local>,
message: Option<&'a String>,
level: &'a Level,
target: Option<&'a String>,
message: Option<String>,
level: &'static Level,
target: Option<String>,
fields: HashMap<String, String>,
}
impl LogFormat<'_> {
impl LogFormat {
/// Formatting logs with styling & colors
pub fn with_ansi(&mut self) -> String {
format!(
Expand All @@ -95,8 +91,8 @@ impl LogFormat<'_> {
"{} {:<6}[{}]{} {}",
self.timestamp,
self.level,
self.target.unwrap_or(&"".to_string()),
self.message.unwrap_or(&"".to_string()),
self.target.as_ref().map_or("", |s| s),
self.message.as_ref().map_or("", |s| s),
self.fields_as_str()
)
}
Expand Down Expand Up @@ -124,17 +120,15 @@ impl LogFormat<'_> {
}
/// Custom format for target
fn format_target(&self) -> String {
if let Some(target) = self.target {
self.target.as_ref().map_or("".to_string(), |target| {
format!("[{}]", Style::new().italic().dimmed().paint(target))
} else {
"".to_string()
}
})
}
/// Custom format for log message
pub fn format_message(&self) -> String {
Style::new()
.bold()
.paint(self.message.unwrap_or(&"".to_string()))
.paint(self.message.as_ref().map_or("", |s| s))
.to_string()
}
/// Custom format for fields
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-bundler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> WebBundler<'a> {
.map(|(k, path)| {
let path = Path::new(path);
if !path.exists() {
non_found_files.push(path.to_str().unwrap());
non_found_files.push(path.display().to_string());
}
(k.into(), path)
})
Expand Down
2 changes: 1 addition & 1 deletion crates/metassr-html/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const BODY_TAG: &str = "%BODY%";
const SCRIPTS_TAG: &str = "%SCRIPTS%";
const STYLES_TAG: &str = "%STYLES%";

#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct HtmlOutput(String);

impl HtmlOutput {
Expand Down
1 change: 1 addition & 0 deletions crates/metassr-watcher/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn is_relevant_event(event: &DebouncedEvent) -> bool {
Create(_) | Modify(ModifyKind::Data(_)) | Modify(ModifyKind::Name(_)) | Remove(_)
)
}

pub fn format_event(event: &DebouncedEvent) -> String {
let action = match event.kind {
Create(_) => "created",
Expand Down
Loading