aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-06-03 13:19:26 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-06-03 13:19:26 +0200
commit401edb8d00c268d5cfa1fc0de0d3e0dd045d4adc (patch)
treeddbb396bca4ec29a20a754e394047c57883fa7ec
parentde7031da1c8f1d12575bc1a988c28310f70e176c (diff)
log timestamps
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs11
2 files changed, 8 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 536e404..213980a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,5 +7,6 @@ edition = "2021"
[dependencies]
anyhow = "1.0.68"
+humantime = "2.1.0"
sys-mount = "2.0.2"
termcolor = "1.1.3"
diff --git a/src/main.rs b/src/main.rs
index 89603fb..f7584ca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,11 @@
-use anyhow::bail;
use std::fs::{self, File};
use std::io::{BufRead, BufReader, Write};
use std::path::Path;
use std::process::{self, ChildStderr, ChildStdout, Command, ExitCode, Stdio};
use std::thread;
-use std::time::Duration;
+use std::time::{Duration, SystemTime};
+
+use anyhow::bail;
use sys_mount::{Mount, Unmount, UnmountDrop, UnmountFlags};
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
@@ -71,7 +72,8 @@ fn log_out(pipe: ChildStdout, service_name: String) -> anyhow::Result<()> {
r.read_line(&mut buf)?;
if !buf.is_empty() {
- let buf = format!("[{}] {}", service_name, buf);
+ let timestamp = humantime::format_rfc3339_seconds(SystemTime::now());
+ let buf = format!("[{} {}] {}", timestamp, service_name, buf);
stdout.set_color(ColorSpec::new().set_fg(Some(Color::White)))?;
write!(&mut stdout, "{}", buf)?;
@@ -91,7 +93,8 @@ fn log_err(pipe: ChildStderr, service_name: String) -> anyhow::Result<()> {
r.read_line(&mut buf)?;
if !buf.is_empty() {
- let buf = format!("[{}] {}", service_name, buf);
+ let timestamp = humantime::format_rfc3339_seconds(SystemTime::now());
+ let buf = format!("[{} {}] {}", timestamp, service_name, buf);
stdout.set_color(ColorSpec::new().set_fg(Some(Color::White)))?;
write!(&mut stdout, "{}", buf)?;