Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add timestamps to logs that don't support them #3778

Closed
DrissiReda opened this issue Feb 8, 2022 · 2 comments · Fixed by #3795
Closed

[FEATURE] Add timestamps to logs that don't support them #3778

DrissiReda opened this issue Feb 8, 2022 · 2 comments · Fixed by #3795

Comments

@DrissiReda
Copy link
Contributor

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:

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.

@Claiyc
Copy link
Member

Claiyc commented Feb 16, 2022

Imo, generally a good idea, but not a priority atm. Feel free to create a pull request if you feel like you're able to implement it yourself.

@h3o66 h3o66 linked a pull request Feb 17, 2022 that will close this issue
13 tasks
@dgibbs64 dgibbs64 added type: feature request New feature or request and removed feature labels Feb 9, 2023
@dgibbs64 dgibbs64 added this to the v23.2.0 milestone Mar 28, 2023
@dgibbs64 dgibbs64 closed this as completed Apr 3, 2023
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants