Skip to content

Commit

Permalink
ui log scroll to bottom
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Feb 6, 2025
1 parent e018ed6 commit cd1a9c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- force browser cache-invalidate on page load
- use correct timezone for log display
- improve settings search behavior
- log scroll to bottom

## Update for 2025-02-05

Expand Down
20 changes: 17 additions & 3 deletions javascript/logger.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
const timeout = 30000;

const scrollBottom = async (el) => {
const lastChild = el.lastElementChild;
if (lastChild) lastChild.scrollIntoView({ behavior: 'smooth' });
};

const log = async (...msg) => {
const dt = new Date();
const ts = `${dt.getHours().toString().padStart(2, '0')}:${dt.getMinutes().toString().padStart(2, '0')}:${dt.getSeconds().toString().padStart(2, '0')}.${dt.getMilliseconds().toString().padStart(3, '0')}`;
if (window.logger) window.logger.innerHTML += window.logPrettyPrint(...msg);
if (window.logger) {
window.logger.innerHTML += window.logPrettyPrint(...msg);
scrollBottom(window.logger);
}
console.log(ts, ...msg); // eslint-disable-line no-console
};

const debug = async (...msg) => {
const dt = new Date();
const ts = `${dt.getHours().toString().padStart(2, '0')}:${dt.getMinutes().toString().padStart(2, '0')}:${dt.getSeconds().toString().padStart(2, '0')}.${dt.getMilliseconds().toString().padStart(3, '0')}`;
if (window.logger) window.logger.innerHTML += window.logPrettyPrint(...msg);
if (window.logger) {
window.logger.innerHTML += window.logPrettyPrint(...msg);
scrollBottom(window.logger);
}
console.debug(ts, ...msg); // eslint-disable-line no-console
};

const error = async (...msg) => {
const dt = new Date();
const ts = `${dt.getHours().toString().padStart(2, '0')}:${dt.getMinutes().toString().padStart(2, '0')}:${dt.getSeconds().toString().padStart(2, '0')}.${dt.getMilliseconds().toString().padStart(3, '0')}`;
if (window.logger) window.logger.innerHTML += window.logPrettyPrint(...msg);
if (window.logger) {
window.logger.innerHTML += window.logPrettyPrint(...msg);
scrollBottom(window.logger);
}
console.error(ts, ...msg); // eslint-disable-line no-console
// const txt = msg.join(' ');
// if (!txt.includes('asctime') && !txt.includes('xhr.')) xhrPost('/sdapi/v1/log', { error: txt }); // eslint-disable-line no-use-before-define
Expand Down

0 comments on commit cd1a9c5

Please sign in to comment.