From 17a5e7a25873d2c270e5808730721ebb5427a051 Mon Sep 17 00:00:00 2001
From: Jack Wills <32690432+mrjackwills@users.noreply.github.com>
Date: Fri, 21 Feb 2025 11:03:19 +0000
Subject: [PATCH] feat: set log timezone, closes #56
Implement a CLI arg, and config file setting, for changing the timezone of the Docker logs timestamp
---
Cargo.lock | 46 +++++
Cargo.toml | 2 +
README.md | 25 ++-
containerised/Dockerfile_dev | 4 +
create_release.sh | 80 ++++++++
example_config/example.config.json | 6 +
example_config/example.config.jsonc | 14 +-
example_config/example.config.toml | 19 +-
src/app_data/container_state.rs | 109 +++++++++--
src/app_data/mod.rs | 27 ++-
src/config/color_parser.rs | 24 ++-
src/config/config.toml | 19 +-
src/config/mod.rs | 148 ++++++++++++++-
src/config/parse_args.rs | 4 +
src/config/parse_config_file.rs | 26 +--
src/docker_data/mod.rs | 4 +-
src/input_handler/mod.rs | 10 +-
src/main.rs | 6 +-
src/ui/color_match.rs | 7 +-
src/ui/draw_blocks/charts.rs | 13 +-
src/ui/draw_blocks/error.rs | 43 +++--
src/ui/draw_blocks/headers.rs | 2 +-
src/ui/draw_blocks/help.rs | 212 ++++++++++++++++-----
src/ui/draw_blocks/logs.rs | 274 ++++++++++++++++++++++++++--
src/ui/draw_blocks/mod.rs | 3 +
src/ui/draw_blocks/ports.rs | 138 +++++++++++++-
src/ui/mod.rs | 20 +-
27 files changed, 1122 insertions(+), 163 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 06e18b7..e8d5c65 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -906,6 +906,36 @@ version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
+[[package]]
+name = "jiff"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba926fdd8e5b5e7f9700355b0831d8c416afe94b014b1023424037a187c9c582"
+dependencies = [
+ "jiff-tzdb",
+ "jiff-tzdb-platform",
+ "log",
+ "portable-atomic",
+ "portable-atomic-util",
+ "serde",
+ "windows-sys 0.59.0",
+]
+
+[[package]]
+name = "jiff-tzdb"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf2cec2f5d266af45a071ece48b1fb89f3b00b2421ac3a5fe10285a6caaa60d3"
+
+[[package]]
+name = "jiff-tzdb-platform"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a63c62e404e7b92979d2792352d885a7f8f83fd1d0d31eea582d77b2ceca697e"
+dependencies = [
+ "jiff-tzdb",
+]
+
[[package]]
name = "js-sys"
version = "0.3.77"
@@ -1065,6 +1095,7 @@ dependencies = [
"crossterm",
"directories",
"futures-util",
+ "jiff",
"parking_lot",
"ratatui",
"serde",
@@ -1125,6 +1156,21 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
+[[package]]
+name = "portable-atomic"
+version = "1.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6"
+
+[[package]]
+name = "portable-atomic-util"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
+dependencies = [
+ "portable-atomic",
+]
+
[[package]]
name = "powerfmt"
version = "0.2.0"
diff --git a/Cargo.toml b/Cargo.toml
index ac217d8..bc01325 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,6 +33,7 @@ clap = { version = "4.5", features = ["color", "derive", "unicode"] }
crossterm = "0.28"
directories = "6.0"
futures-util = "0.3"
+jiff = { version = "0.2", features = ["tzdb-bundle-always"] }
parking_lot = { version = "0.12" }
ratatui = "0.29"
serde = { version = "1.0", features = ["derive"] }
@@ -45,6 +46,7 @@ tracing = "0.1"
tracing-subscriber = "0.3"
uuid = { version = "1.12", features = ["fast-rng", "v4"] }
+
[profile.release]
lto = true
codegen-units = 1
diff --git a/README.md b/README.md
index 1b1fba9..83097fd 100644
--- a/README.md
+++ b/README.md
@@ -100,8 +100,7 @@ curl https://raw.githubusercontent.com/mrjackwills/oxker/main/install.sh | bash
```shell
oxker
```
-
-In application controls
+In application controls, these can be customized with the [config file](#Config-File)
| button| result|
|--|--|
| ```( tab )``` or ```( shift+tab )``` | Change panel, clicking on a panel also changes the selected panel.|
@@ -118,6 +117,7 @@ In application controls
| ```( esc )``` | Close dialog.|
Available command line arguments
+
| argument|result|
|--|--|
|```-d [number > 0]```| Set the minimum update interval for docker information in milliseconds. Defaults to 1000 (1 second).|
@@ -126,11 +126,30 @@ Available command line arguments
|```-t```| Remove timestamps from each log entry.|
|```-s```| If running via Docker, will display the oxker container.|
|```-g```| No TUI, essentially a debugging mode with limited functionality, for now.|
+|```--config-file [string]```| Location of a `config.toml`/`config.json`/`config.jsonc`.|
|```--host [string]```| Connect to Docker with a custom hostname. Defaults to `/var/run/docker.sock`. Will use `$DOCKER_HOST` environment variable if set.|
|```--no-stderr```| Do not include stderr output in logs.|
|```--save-dir [string]```| Save exported logs into a custom directory. Defaults to `$HOME`.|
+|```--timezone [string]```| Display the Docker logs timestamps in a given [timezone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones). Defaults to `Etc/UTC`.|
|```--use-cli```| Use the Docker application when exec-ing into a container, instead of the Docker API.|
+### Config File
+
+
+A config file enables the user to persist settings, it also enables the user to create a custom keymap, and set the color scheme used by the application.
+
+
+By default, if not found, `oxker` will create a config file in the user's local config directory. Command line arguments take priority over values from the config file.
+
+
+`oxker` supports `.toml`,`.json`, and `.jsonc` file formats. Examples of each can be found in the [example_config](https://github.com/mrjackwills/oxker/tree/main/example_config) directory.
+
+If running an `oxker` container, the default config location will be `/config.toml` rather than the automatically detected platform-specific local config directory.
+
+```shell
+docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock:ro -v /some/location/config.toml:/config.toml:ro oxker
+```
+
## Build step
### x86_64
@@ -163,8 +182,10 @@ If no memory information available, try appending either ```/boot/cmdline.txt```
see https://forums.raspberrypi.com/viewtopic.php?t=203128 and https://github.com/docker/for-linux/issues/1112
+
### Untested on other platforms
+
## Tests
~~As of yet untested, needs work~~
diff --git a/containerised/Dockerfile_dev b/containerised/Dockerfile_dev
index 8a47e04..db0c8b2 100644
--- a/containerised/Dockerfile_dev
+++ b/containerised/Dockerfile_dev
@@ -13,9 +13,13 @@ COPY ./target/x86_64-unknown-linux-musl/release/oxker /app/
# this is used in the application itself, to stop itself show when running from a docker container, so DO NOT EDIT
ENTRYPOINT [ "/app/oxker"]
+
# Dev build for testing
# docker build -t oxker_dev -f containerised/Dockerfile_dev . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
+# docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume ./example_config/example.config.toml:/config.toml:ro oxker_dev --config-file /config.toml
+
+# docker run --rm -it --volume /etc/timezone:/etc/timezone:ro --volume /etc/localtime:/etc/localtime:ro --volume /var/run/docker.sock:/var/run/docker.sock:ro --volume ./example_config/example.config.toml:/config.toml:ro oxker_dev --config-file /config.toml
# Dev build one liner, x86 host
# docker image prune -a; cargo build --release --target x86_64-unknown-linux-musl && docker build -t oxker_dev -f containerised/Dockerfile_dev . && docker run --rm -it --volume /var/run/docker.sock:/var/run/docker.sock:ro oxker_dev
diff --git a/create_release.sh b/create_release.sh
index 8008aae..0d69f16 100755
--- a/create_release.sh
+++ b/create_release.sh
@@ -266,6 +266,40 @@ check_allow_unused() {
fi
}
+# build container for amd64 platform
+build_container_amd64() {
+ docker image rm oxker_amd64:latest
+ docker builder prune -a
+ echo -e "${YELLOW}docker build --platform linux/amd64 -t oxker_amd64 -f containerised/Dockerfile .; docker save -o /tmp/oxker_amd64.tar oxker_amd64${RESET}"
+ docker build --platform linux/amd64 -t oxker_amd64 -f containerised/Dockerfile .
+ docker save -o /tmp/oxker_amd64.tar oxker_amd64
+}
+# build container for aarm64 platform
+build_container_arm64() {
+ docker image rm oxker_arm64:latest
+ docker builder prune -a
+ echo -e "${YELLOW}docker build --platform linux/arm64 -t oxker_arm64 -f containerised/Dockerfile .; docker save -o /tmp/oxker_arm64.tar oxker_arm64${RESET}"
+ docker build --platform linux/arm64 -t oxker_arm64 -f containerised/Dockerfile .
+ docker save -o /tmp/oxker_arm64.tar oxker_arm64
+}
+# build container for armv6 platform
+build_container_armv6() {
+ docker image rm oxker_armv6:latest
+ docker builder prune -a
+ echo -e "${YELLOW}docker build --platform linux/arm/v6 -t oxker_armv6 -f containerised/Dockerfile .; docker save -o /tmp/oxker_armv6.tar oxker_armv6${RESET}"
+ docker build --platform linux/arm/v6 -t oxker_armv6 -f containerised/Dockerfile .
+ docker save -o /tmp/oxker_armv6.tar oxker_armv6
+}
+
+# Build all the containers, this get executed in the github action
+build_container_all() {
+ build_container_amd64
+ ask_continue
+ build_container_arm64
+ ask_continue
+ build_container_armv6
+}
+
# Full flow to create a new release
release_flow() {
check_allow_unused
@@ -276,6 +310,7 @@ release_flow() {
cargo_test
cross_build_all
+ build_container_all
cargo_publish_dry_run
cd "${CWD}" || error_close "Can't find ${CWD}"
@@ -379,6 +414,45 @@ build_choice() {
;;
esac
done
+}
+
+build_container_choice() {
+ cmd=(dialog --backtitle "Choose option" --radiolist "choose" 14 80 16)
+ options=(
+ 1 "x86 " off
+ 2 "aarch64" off
+ 3 "armv6" off
+ 4 "all" off
+ )
+ choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
+ exitStatus=$?
+ clear
+ if [ $exitStatus -ne 0 ]; then
+ exit
+ fi
+ for choice in $choices; do
+ case $choice in
+ 0)
+ exit
+ ;;
+ 1)
+ build_container_amd64
+ exit
+ ;;
+ 2)
+ build_container_arm64
+ exit
+ ;;
+ 3)
+ build_container_armv6
+ exit
+ ;;
+ 4)
+ build_container_all
+ exit
+ ;;
+ esac
+ done
}
@@ -388,6 +462,7 @@ main() {
1 "test" off
2 "release" off
3 "build" off
+ 4 "docker builds" off
)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
exitStatus=$?
@@ -414,6 +489,11 @@ main() {
main
break
;;
+ 4)
+ build_container_choice
+ main
+ break
+ ;;
esac
done
}
diff --git a/example_config/example.config.json b/example_config/example.config.json
index 37ef0bf..bf382a3 100644
--- a/example_config/example.config.json
+++ b/example_config/example.config.json
@@ -7,6 +7,8 @@
"show_self": false,
"show_std_err": false,
"show_timestamp": true,
+ "timezone": "Etc/UTC",
+ "timestamp_format":"%Y-%m-%dT%H:%M:%S.%8f",
"use_cli": false,
"colors": {
"borders": {
@@ -68,6 +70,10 @@
"text": "black",
"text_selected": "gray"
},
+ "logs": {
+ "background": "reset",
+ "text": "reset"
+ },
"popup_delete": {
"background": "white",
"text": "black",
diff --git a/example_config/example.config.jsonc b/example_config/example.config.jsonc
index db7e7e5..6ceb44d 100644
--- a/example_config/example.config.jsonc
+++ b/example_config/example.config.jsonc
@@ -1,7 +1,7 @@
{
// Example JSONC config file
// This needs to be renamed to "config.jsonc" ("config.json" will also work, even if the file is actually a jsonc) in order for oxker to automatically load
- // oxker will also read .jsonc and .json files which use the same key/value structure & format as this file
+ // oxker will also read .toml and .json files which use the same key/value structure & format as this file
// Every key is optional, with defaults that oxker will choose if missing or invalid
// The `--config-file` cli argument can be used to load configuration files from any readable location
// Docker update interval in ms, minimum effectively 1000
@@ -20,6 +20,11 @@
"gui": true,
// Docker host location
"host": "/var/run/docker.sock",
+ // Display the timestamp in a custom format, if given option is invalid, it will default to %Y-%m-%dT%H:%M:%S.%8f -> 2025-02-18T12:34:56.01234567
+ // *Should* accept any valid strftime string up to 32 chars
+ "timestamp_format":"%Y-%m-%dT%H:%M:%S.%8f",
+ // Display the container logs timestamp with a given timezone, if timezone is unknown, defaults to UTC
+ "timezone": "Etc/UTC",
// Directory for saving exported logs, defaults to `$HOME`, this is automatically *correctly* calculated for Linux, Mac, and Windows
// "save_dir": "$HOME",
// Force use of docker cli when execing into containers, honestly mostly pointless
@@ -246,6 +251,13 @@
// Ports & IP listing text
"text": "white"
},
+ // The logs panel, will only be applied if color_logs is false
+ "logs": {
+ // Background color of panel
+ "background": "reset",
+ // text color
+ "text": "reset"
+ },
// The help popup
"popup_help": {
// Background color
diff --git a/example_config/example.config.toml b/example_config/example.config.toml
index feb3da1..8115b9c 100644
--- a/example_config/example.config.toml
+++ b/example_config/example.config.toml
@@ -1,8 +1,5 @@
-# Example toml config file
-
-# This needs to be renamed to "config.toml" in order for oxker to automatically load
+# oxker config file
# oxker will also read .jsonc and .json files which use the same key/value structure & format as this file
-
# Every key is optional, with defaults that oxker will choose if missing or invalid
# The `--config-file` cli argument can be used to load configuration files from any readable location
@@ -30,6 +27,13 @@ gui = true
# Docker host location
host = "/var/run/docker.sock"
+# Display the container logs timestamp with a given timezone, if timezone is unknown, defaults to UTC
+timezone = "Etc/UTC"
+
+# Display the timestamp in a custom format, if given option is invalid, it will default to %Y-%m-%dT%H:%M:%S.%8f -> 2025-02-18T12:34:56.012345678Z
+# *Should* accept any valid strftime string up to 32 chars
+timestamp_format="%Y-%m-%dT%H:%M:%S.%8f"
+
# Directory for saving exported logs, defaults to `$HOME`, this is automatically *correctly* calculated for Linux, Mac, and Windows
# save_dir = "$HOME"
@@ -141,6 +145,13 @@ text_rx="#FFE9C1"
# Text color of the TX column
text_tx="#CD8C8C"
+# The logs panel, will only be applied if color_logs is false
+[colors.logs]
+# Background color of panel
+background = "reset"
+# text color
+text="reset"
+
# Each state of a container has a color, which is used in multiple places, i.e. chart titles, state/status/cpu/memory columns in the container section
[colors.container_state]
dead="red"
diff --git a/src/app_data/container_state.rs b/src/app_data/container_state.rs
index f888ec1..a510e61 100644
--- a/src/app_data/container_state.rs
+++ b/src/app_data/container_state.rs
@@ -6,6 +6,7 @@ use std::{
};
use bollard::service::Port;
+use jiff::{tz::TimeZone, Timestamp};
use ratatui::{
style::Color,
widgets::{ListItem, ListState},
@@ -34,6 +35,7 @@ impl ContainerId {
}
/// Only return first 8 chars of id, is usually more than enough for uniqueness
+ /// TODO container id is a hex string, so can assume that 0..=8 will always return a 8 char ascii &str - need to update tests to use real ids, or atleast strings of the correct-ish length
pub fn get_short(&self) -> String {
self.0.chars().take(8).collect::()
}
@@ -513,21 +515,34 @@ pub type CpuTuple = (Vec<(f64, f64)>, CpuStats, State);
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LogsTz(String);
-/// The docker log, which should always contain a timestamp, is in the format `2023-01-14T19:13:30.783138328Z Lorem ipsum dolor sit amet`
-/// So just split at the inclusive index of the first space, needs to be inclusive, hence the use of format to at the space, so that we can remove the whole thing when the `-t` flag is set
-/// Need to make sure that this isn't an empty string?!
-impl From<&str> for LogsTz {
- fn from(value: &str) -> Self {
- Self(value.split_inclusive(' ').take(1).collect::())
- }
-}
-
impl fmt::Display for LogsTz {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}
+impl LogsTz {
+ /// With a given &str, split into a logtz and content, so that we only need to `use split_once()` once
+ /// The docker log, which should always contain a timestamp, is in the format `2023-01-14T19:13:30.783138328Z Lorem ipsum dolor sit amet`
+ pub fn splitter(input: &str) -> (Self, String) {
+ let (tz, content) = input.split_once(' ').unwrap_or_default();
+ (Self(tz.to_owned()), content.to_owned())
+ }
+
+ /// Display the timestamp in a given format, and if provided, with a timezone offset
+ pub fn display_with_formatter(&self, tz: Option<&TimeZone>, format: &str) -> Option {
+ self.0.parse::().map_or(None, |t| {
+ if let Some(tz) = tz.as_ref() {
+ let tz = tz.iana_name()?;
+ let z = t.in_tz(tz).ok()?;
+ Some(z.strftime(format).to_string())
+ } else {
+ Some(t.strftime(format).to_string())
+ }
+ })
+ }
+}
+
/// Store the logs alongside a HashSet, each log *should* generate a unique timestamp,
/// so if we store the timestamp separately in a HashSet, we can then check if we should insert a log line into the
/// stateful list dependent on whethere the timestamp is in the HashSet or not
@@ -745,15 +760,18 @@ impl Columns {
}
#[cfg(test)]
+#[allow(clippy::unwrap_used)]
mod tests {
+
+ use jiff::tz::TimeZone;
use ratatui::widgets::ListItem;
use crate::{
- app_data::{ContainerImage, Logs, RunningState},
+ app_data::{ContainerImage, Logs, LogsTz, RunningState},
ui::log_sanitizer,
};
- use super::{ByteStats, ContainerName, ContainerStatus, CpuStats, LogsTz, State};
+ use super::{ByteStats, ContainerName, ContainerStatus, CpuStats, State};
#[test]
/// Display CpuStats as a string
@@ -813,11 +831,76 @@ mod tests {
assert_eq!(result, "name_01_name_01_name_01_name_01_");
}
+ #[test]
+ /// LogzTz correctly splits a line by timestamp
+ fn test_container_state_logz_splitter() {
+ let input = "2023-01-14T12:01:20.012345678Z Lorem ipsum dolor sit amet";
+ let log_tz = LogsTz::splitter(input);
+
+ assert_eq!(
+ log_tz.0,
+ super::LogsTz("2023-01-14T12:01:20.012345678Z".to_owned())
+ );
+ assert_eq!(log_tz.1, "Lorem ipsum dolor sit amet");
+ }
+
+ #[test]
+ /// LogsTz display correctly formats with a given timestamp string
+ fn test_container_state_logz_display() {
+ let input = "2023-01-14T12:01:20.012345678Z Lorem ipsum dolor sit amet";
+ let log_tz = LogsTz::splitter(input);
+
+ let result = log_tz
+ .0
+ .display_with_formatter(None, "%Y-%m-%dT%H:%M:%S.%8f");
+ assert!(result.is_some());
+ let result = result.unwrap();
+ assert_eq!(result, "2023-01-14T12:01:20.01234567");
+
+ let result = log_tz.0.display_with_formatter(None, "%Y-%m-%d %H:%M:%S");
+ assert!(result.is_some());
+ let result = result.unwrap();
+ assert_eq!(result, "2023-01-14 12:01:20");
+
+ let result = log_tz.0.display_with_formatter(None, "%Y-%j");
+ assert!(result.is_some());
+ let result = result.unwrap();
+
+ assert_eq!(result, "2023-014");
+ }
+
+ #[test]
+ /// LogsTz display correctly formats with a given timestamp string & timezone
+ fn test_container_state_logz_display_with_timezone() {
+ let input = "2023-01-14T12:01:20.012345678Z Lorem ipsum dolor sit amet";
+ let log_tz = LogsTz::splitter(input);
+
+ let timezone = Some(TimeZone::get("Asia/Tokyo").unwrap());
+ let result = log_tz
+ .0
+ .display_with_formatter(timezone.as_ref(), "%Y-%m-%dT%H:%M:%S.%8f");
+ assert!(result.is_some());
+ let result = result.unwrap();
+ assert_eq!(result, "2023-01-14T21:01:20.01234567");
+
+ let result = log_tz
+ .0
+ .display_with_formatter(timezone.as_ref(), "%Y-%m-%d %H:%M:%S");
+ assert!(result.is_some());
+ let result = result.unwrap();
+ assert_eq!(result, "2023-01-14 21:01:20");
+
+ let result = log_tz.0.display_with_formatter(timezone.as_ref(), "%Y-%j");
+ assert!(result.is_some());
+ let result = result.unwrap();
+ assert_eq!(result, "2023-014");
+ }
+
#[test]
/// Logs can only contain 1 entry per LogzTz
fn test_container_state_logz() {
let input = "2023-01-14T19:13:30.783138328Z Lorem ipsum dolor sit amet";
- let tz = LogsTz::from(input);
+ let (tz, _) = LogsTz::splitter(input);
let mut logs = Logs::default();
let line = log_sanitizer::remove_ansi(input);
@@ -828,7 +911,7 @@ mod tests {
assert_eq!(logs.logs.items.len(), 1);
let input = "2023-01-15T19:13:30.783138328Z Lorem ipsum dolor sit amet";
- let tz = LogsTz::from(input);
+ let (tz, _) = LogsTz::splitter(input);
let line = log_sanitizer::remove_ansi(input);
logs.insert(ListItem::new(line.clone()), tz.clone());
diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs
index 1822cb8..731c818 100644
--- a/src/app_data/mod.rs
+++ b/src/app_data/mod.rs
@@ -585,7 +585,7 @@ impl AppData {
/// Get the title for log panel for selected container, will be either
/// 1) "logs x/x - container_name - container_image"
/// 2) "logs - container_name - container_image" when no logs found
- /// 3) "" no container currently selected - aka no containers on system
+ /// 3) " " no container currently selected - aka no containers on system
pub fn get_log_title(&self) -> String {
self.get_selected_container()
.map_or_else(String::new, |ci| {
@@ -879,18 +879,27 @@ impl AppData {
pub fn update_log_by_id(&mut self, logs: Vec, id: &ContainerId) {
let color = self.config.color_logs;
let raw = self.config.raw_logs;
+ let format = self.config.timestamp_format.clone();
+ let config_tz = self.config.timezone.clone();
- let timestamp = self.config.show_timestamp;
+ let show_timestamp = self.config.show_timestamp;
if let Some(container) = self.get_any_container_by_id(id) {
if !container.is_oxker {
container.last_updated = Self::get_systemtime();
let current_len = container.logs.len();
-
for mut i in logs {
- let tz = LogsTz::from(i.as_str());
- if !timestamp {
- i = i.replace(&tz.to_string(), "");
+ let (log_tz, log_content) = LogsTz::splitter(i.as_str());
+ if show_timestamp {
+ i = format!(
+ "{} {}",
+ log_tz
+ .display_with_formatter(config_tz.as_ref(), &format)
+ .unwrap_or_else(|| log_tz.to_string()),
+ log_content
+ );
+ } else {
+ i = log_content;
}
let lines = if color {
log_sanitizer::colorize_logs(&i)
@@ -899,7 +908,7 @@ impl AppData {
} else {
log_sanitizer::remove_ansi(&i)
};
- container.logs.insert(ListItem::new(lines), tz);
+ container.logs.insert(ListItem::new(lines), log_tz);
}
// Set the logs selected row for each container
@@ -1819,7 +1828,7 @@ mod tests {
assert_eq!(result, " - container_1 - image_1");
// On last line of logs
- let logs = (1..=3).map(|i| format!("{i}")).collect::>();
+ let logs = (1..=3).map(|i| format!("{i} {i}")).collect::>();
app_data.update_log_by_id(logs, &ids[0]);
let result = app_data.get_log_title();
assert_eq!(result, " 3/3 - container_1 - image_1");
@@ -1851,7 +1860,7 @@ mod tests {
assert_eq!(result, " - container_2 - image_2");
// On last line of logs
- let logs = (1..=3).map(|i| format!("{i}")).collect::>();
+ let logs = (1..=3).map(|i| format!("{i} {i}")).collect::>();
app_data.update_log_by_id(logs, &ids[1]);
let result = app_data.get_log_title();
assert_eq!(result, " 3/3 - container_2 - image_2");
diff --git a/src/config/color_parser.rs b/src/config/color_parser.rs
index bdf7f82..a591cbd 100644
--- a/src/config/color_parser.rs
+++ b/src/config/color_parser.rs
@@ -172,6 +172,12 @@ impl From