Skip to content

Commit af9c3d9

Browse files
committed
Add toggle to show timestamps for the log messages
1 parent 14a8086 commit af9c3d9

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed

Assets/WebGLTemplates/Develop/debug-console.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
content: '🛑';
6969
}
7070

71+
#debugConsole .console-top-bar .timestamp-button .icon::before {
72+
content: '🕰️';
73+
}
74+
7175
#debugConsole .console-top-bar .separator {
7276
position: relative;
7377
flex-shrink: 0;
@@ -107,6 +111,14 @@
107111
display:none;
108112
}
109113

114+
#debugConsole .timestamplog {
115+
color: #888;
116+
}
117+
118+
#debugConsole.hidelogtimestamps .timestamplog {
119+
display: none;
120+
}
121+
110122
#debugConsole .entry.warn {
111123
color: rgb(82, 70, 3);
112124
background-color: rgba(231, 196, 41, 0.9);
@@ -131,6 +143,10 @@
131143
border-bottom: 3px solid yellowgreen;
132144
}
133145

146+
#debugConsole .timestamp-button.show {
147+
border-bottom: 3px solid yellowgreen;
148+
}
149+
134150
#debugConsole .bubble-click-indicator:before {
135151
content: attr(data-before);
136152
;

Assets/WebGLTemplates/Develop/debug-console.js

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ function getCookie(cname) {
3131
return "";
3232
}
3333

34-
var scrollToBottom = false; // Default to false, since continuous erros can overload the system
35-
if(getCookie("scrollToBottom") === "true") {
36-
scrollToBottom = true;
34+
var scrollToBottom = true;
35+
if(getCookie("scrollToBottom") === "false") {
36+
scrollToBottom = false;
37+
}
38+
var addTimestamp = true;
39+
if(getCookie("addTimestamp") === "false") {
40+
addTimestamp = false;
3741
}
3842

3943
function initialzeDebugConsole() {
@@ -74,6 +78,28 @@ function addDebugConsoleTopBar(debugConsole, consoleDiv) {
7478
separator.classList.add('separator');
7579
consoleTopBar.appendChild(separator);
7680

81+
// Add timestamp toggle
82+
var timestampButton = document.createElement('button');
83+
timestampButton.classList.add('timestamp-button', 'bubble-click-indicator');
84+
timestampButton.title = 'Add timestamp to logs';
85+
consoleTopBar.appendChild(timestampButton);
86+
87+
var timestampIcon = document.createElement('div');
88+
timestampIcon.classList.add('icon');
89+
timestampButton.appendChild(timestampIcon);
90+
applyTimestamp(timestampButton, consoleDiv);
91+
92+
timestampButton.addEventListener('click', function () {
93+
addTimestamp = !addTimestamp;
94+
setCookie("addTimestamp", addTimestamp, 365);
95+
applyTimestamp(timestampButton, consoleDiv);
96+
// Show copy feedback to the user
97+
timestampButton.classList.add('active');
98+
setTimeout(function () {
99+
timestampButton.classList.remove('active');
100+
}, 1500);
101+
});
102+
77103
// Clear logs button
78104
var clearButton = document.createElement('button');
79105
clearButton.classList.add('clear-button', 'bubble-click-indicator');
@@ -207,6 +233,18 @@ function applyScrollToBottom(toBottomButton, consoleDiv) {
207233
}
208234
}
209235

236+
function applyTimestamp(timestampButton, consoleDiv) {
237+
timestampButton.setAttribute('data-before', addTimestamp ? 'Show' : 'Hide');
238+
var debugConsole = document.getElementById('debugConsole');
239+
if (addTimestamp) {
240+
timestampButton.classList.add("show");
241+
debugConsole.classList.remove("hidelogtimestamps");
242+
} else {
243+
timestampButton.classList.remove("show");
244+
debugConsole.classList.add("hidelogtimestamps");
245+
}
246+
}
247+
210248
function setupConsoleLogPipe() {
211249
// Store actual console log functions
212250
let defaultConsoleLog = console.log;
@@ -293,10 +331,13 @@ function htmlLog(message, className) {
293331
consoleDiv.appendChild(entry);
294332

295333
var text = document.createElement('p');
296-
// Remove last line break if existing
297-
if (message.endsWith("\n")) {
298-
message = message.substring(0, message.length - "\n".length);
299-
}
334+
var time = new Date().toLocaleTimeString('en-US', {
335+
hour12: false,
336+
hour: "numeric",
337+
minute: "numeric",
338+
second: "numeric"}
339+
);
340+
message = "<span class='timestamplog'>[" + time + "] </span>" + message;
300341
message = message.replaceAll("\n", "<br />");
301342
text.innerHTML = message;
302343
entry.appendChild(text);

0 commit comments

Comments
 (0)