-
-
Notifications
You must be signed in to change notification settings - Fork 842
Description
User Story
As a server admin, I want to be able to view timestamps for my server logs.
Basic info
- Distro: [Debian 11]
- Game: [Test on Rust, but probably applicable to others]
- Command: [Start]
- LinuxGSM version: [latest]
Implementation
I have tried to implement this after interacting with the Github mods gentlemen on Discord.
I have found that we can prepend all lines of log with the timestamp by modifying these lines:
LinuxGSM/lgsm/functions/command_start.sh
Line 95 in fdfeae1
tmux pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'" LinuxGSM/lgsm/functions/command_start.sh
Line 111 in fdfeae1
tmux pipe-pane -o -t "${sessionname}" "exec cat >> '${consolelog}'"
Should be changed to:
tmux pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | $add_ts\" >> '${consolelog}'"
With a global variable (using gawk
for readability)
add_ts='gawk '"'"'{ print strftime(\"[%Y-%m-%d %H:%M:%S]\"), \$0 }'"'"''
Or without gawk we can just put this script in a one liner:
while IFS= read -r line
do
printf "[%s] %s\n" "$(date '+%Y-%m-%d %H:%M:%S')" "$line";
done
I tested this on my rustserver, and the output:
Asset Warmup (1/9092)
Asset Warmup (408/9092)
Asset Warmup (434/9092)
Asset Warmup (1088/9092)
Becomes:
[2022-02-08 18:03:26] Asset Warmup (1/9092)
[2022-02-08 18:03:26] Asset Warmup (408/9092)
[2022-02-08 18:03:26] Asset Warmup (434/9092)
[2022-02-08 18:03:26] Asset Warmup (1088/9092)
I didn't add a check to manage lines with whitespaces because that would make the code too complex and unreadable.
We can also use ts
from moreutils
package but it adds dependencies:
tmux pipe-pane -o -t "${sessionname}" "exec bash -c \"cat | ts '[%Y-%m-%d %H:%M:%S]' \" >> '${consolelog}'"
We can also add a global variable to activate timestamps on certain games, not all. And a variable for the format.
Although this solution is not ideal, because the timestamp won't be precise for every line, but each time tmux dumps logs to the file, every line included in that dump will have the same timestamp of the moment the dump occurs. It still is much better than no timestamps at all in my opinion.
I'd like your feedback on this. Would you like something like this to be included in your code? Do you think there is something else I should add for this to be included in your codebase?
I'd like your feedback on this.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status