Skip to content

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
- fix rust-analyzer command
- remove relative timestamps
  • Loading branch information
Purpzie committed May 4, 2023
1 parent 97c7178 commit 93084e2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"rust-analyzer.checkOnSave.command": "clippy",
"rust-analyzer.check.overrideCommand": ["cargo", "clippy", "--all-targets", "--all-features", "--message-format=json"],
"rust-analyzer.cargo.features": "all",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tinylog"
version = "4.0.0"
version = "4.0.1"
license = "MIT"
description = "A logger for my personal projects."
authors = ["Purpzie"]
Expand Down
38 changes: 1 addition & 37 deletions src/tracing_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
util::{with_local_buf, Indented, StringLike},
Logger, PrefixOptions,
};
use std::{io, time::Instant};
use std::io;
use tracing::{
span::{Attributes, Record},
Event, Id, Subscriber,
Expand All @@ -18,7 +18,6 @@ use std::time::SystemTime;
struct SpanData {
content: String,
prefix_end_index: usize,
timestamp: Instant,
}

impl<S, T: io::Write + Send + Sync + 'static> Layer<S> for Logger<T>
Expand All @@ -27,7 +26,6 @@ where
{
fn on_new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<S>) {
let span = ctx.span(id).expect("span missing");
let timestamp = Instant::now();

let mut content = String::new();
self.write_prefix(
Expand All @@ -46,7 +44,6 @@ where
extensions.insert(SpanData {
content,
prefix_end_index,
timestamp,
});
}

Expand All @@ -60,10 +57,8 @@ where
}

fn on_event(&self, event: &Event, ctx: Context<S>) {
let event_timestamp = Instant::now();
#[cfg(feature = "timestamps")]
let time = SystemTime::now();
let color = self.color;

with_local_buf(move |mut buf| {
buf.clear();
Expand Down Expand Up @@ -92,37 +87,6 @@ where
i_buf.push_str(prefix);
i_buf.indent += 2;

// if at least 1 millisecond has passed, let's print it
let time_passed = event_timestamp - data.timestamp;
const NANOS_PER_MILLISECOND: u32 = 1_000_000;
if time_passed.subsec_nanos() >= NANOS_PER_MILLISECOND
|| time_passed.as_secs() > 0
{
let seconds = time_passed.as_secs();
let milliseconds = time_passed.subsec_millis();

i_buf.push(' ');
if color {
// dim
i_buf.push_str("\x1b[2m");
}
i_buf.push('(');
if seconds == 0 {
i_buf.push_str(itoa::Buffer::new().format(milliseconds));
i_buf.push('m');
} else {
i_buf.push_str(
ryu::Buffer::new()
.format((seconds as f64) + ((milliseconds as f64) / 1000.0)),
);
}
i_buf.push_str("s ago)");
if color {
// reset
i_buf.push_str("\x1b[m");
}
}

let name = span.name();
if !name.is_empty() {
i_buf.push('\n');
Expand Down

0 comments on commit 93084e2

Please sign in to comment.