Skip to content

Commit

Permalink
feat(static): Display time in the log message viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
etu committed Jun 8, 2024
1 parent 2283003 commit 15c6fbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ <h1 @click="selectedServer = null">goprocmgr</h1>
<div x-show="selectedServer && getServer(selectedServer)?.running">
<ul id="logs-wrapper">
<template x-for="line in [...getServer(selectedServer)?.logs ?? []].reverse()">
<li :class="{ 'stdout': line.output === 'stdout', 'stderr': line.output === 'stderr' }" x-text="line.message"></li>
<li :class="{ 'stdout': line.output === 'stdout', 'stderr': line.output === 'stderr' }">
<span x-text="formatTimestamp(line.timestamp)" class="timestamp"></span>
<span x-text="line.message" class="message"></span>
</li>
</template>
</ul>
</div>
Expand Down
9 changes: 9 additions & 0 deletions static/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ document.addEventListener('alpine:init', () => {
countLogsByOutput(name, output) {
return this.getServer(name).logs.filter(log => log.output === output).length
},
formatTimestamp(timestamp) {
// Format the timestamp to HH:MM:SS
return new Date(timestamp).toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false
});
},
handleKeyEvents() {
if (this.keyEvent.key === 'Escape') {
this.selectedServer = null
Expand Down
4 changes: 4 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ body {
padding: 0;
}

#app div#content ul#logs-wrapper li span.timestamp {
font-weight: bold;
}

#app div#content ul#logs-wrapper li.stdout {
background-color: var(--stdout-bg-color);
}
Expand Down

0 comments on commit 15c6fbb

Please sign in to comment.