From f7ea762073d548d60dd09733da3c4b1f3e2bf3b9 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sun, 3 Mar 2024 19:53:47 -0500 Subject: [PATCH] improve log monitor --- CHANGELOG.md | 1 + installer.py | 1 + javascript/logMonitor.js | 40 +++++++++++++++++++++++++++++++++------- javascript/sdnext.css | 18 ++++++++++++++---- javascript/ui.js | 4 ++++ modules/theme.py | 5 ++++- modules/ui_javascript.py | 2 ++ 7 files changed, 59 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 226baf180..ffcc634fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ - *interrogate* tab is now merged into *process* tab - *image viewer* now displays image metadata - *themes* improve on-the-fly switching + - *log monitor* flag server warnings/errors and overall improve display - **Fixes** - improve *model cpu offload* compatibility - improve *model sequential offload* compatibility diff --git a/installer.py b/installer.py index f9668aaf2..24bf70864 100644 --- a/installer.py +++ b/installer.py @@ -67,6 +67,7 @@ def setup_logging(): self.formatter = logging.Formatter('{ "asctime":"%(asctime)s", "created":%(created)f, "facility":"%(name)s", "pid":%(process)d, "tid":%(thread)d, "level":"%(levelname)s", "module":"%(module)s", "func":"%(funcName)s", "msg":"%(message)s" }') def emit(self, record): + record.msg = record.msg.replace('"', "'") msg = self.format(record) # self.buffer.append(json.loads(msg)) self.buffer.append(msg) diff --git a/javascript/logMonitor.js b/javascript/logMonitor.js index af744aee1..e872c567c 100644 --- a/javascript/logMonitor.js +++ b/javascript/logMonitor.js @@ -1,5 +1,20 @@ let logMonitorEl = null; let logMonitorStatus = true; +let logWarnings = 0 +let logErrors = 0 + +function dateToStr(ts) { + const dt = new Date(1000 * ts); + const year = dt.getFullYear(); + const mo = String(dt.getMonth() + 1).padStart(2, '0'); + const day = String(dt.getDate()).padStart(2, '0'); + const hour = String(dt.getHours()).padStart(2, '0'); + const min = String(dt.getMinutes()).padStart(2, '0'); + const sec = String(dt.getSeconds()).padStart(2, '0'); + const ms = String(dt.getMilliseconds()).padStart(3, '0'); + const s = `${year}-${mo}-${day} ${hour}:${min}:${sec}.${ms}`; + return s +} async function logMonitor() { if (logMonitorStatus) setTimeout(logMonitor, opts.logmonitor_refresh_period); @@ -24,14 +39,23 @@ async function logMonitor() { try { const l = JSON.parse(line); const row = document.createElement('tr'); - row.style = 'padding: 10px; margin: 0;'; - row.innerHTML = `${new Date(1000 * l.created).toISOString()}${l.level}${l.facility}${l.module}${l.msg}`; + // row.style = 'padding: 10px; margin: 0;'; + const level = `${l.level}`; + if (l.level == 'WARNING') logWarnings++; + if (l.level == 'ERROR') logErrors++; + const module = `${l.module}`; + row.innerHTML = `${dateToStr(l.created)}${level}${l.facility}${module}${l.msg}`; logMonitorEl.appendChild(row); - } catch {} + } catch (e) { + console.log('logMonitor', e); + console.error('logMonitor line', line); + } } while (logMonitorEl.childElementCount > 100) logMonitorEl.removeChild(logMonitorEl.firstChild); if (at_bottom) logMonitorEl.scrollTop = logMonitorEl.scrollHeight; else if (lines?.length > 0) logMonitorEl.parentElement.style = 'border-bottom: 2px solid var(--highlight-color);'; + document.getElementById('logWarnings').innerText = logWarnings; + document.getElementById('logErrors').innerText = logErrors; } } @@ -47,14 +71,16 @@ async function initLogMonitor() { - + - - + + + + - +
TimeTime LevelFacilityModuleModule MessageWarnings 0Errors 0
`; diff --git a/javascript/sdnext.css b/javascript/sdnext.css index 1ce794633..6cd176164 100644 --- a/javascript/sdnext.css +++ b/javascript/sdnext.css @@ -1,11 +1,18 @@ @font-face { font-family: 'NotoSans'; font-display: swap; font-style: normal; font-weight: 100; src: local('NotoSans'), url('notosans-nerdfont-regular.ttf') } -:root { --left-column: 520px; } +:root { + --left-column: 520px; + --color-trace: #666666; + --color-debug: #7F7F7F; + --color-info: #D4D4D4; + --color-warning: #FF9900; + --color-error: #BE0000 +} a { font-weight: bold; cursor: pointer; } h2 { margin-top: 1em !important; font-size: var(--text-xxl) !important; } footer { display: none; margin-top: 0 !important;} table { overflow-x: auto !important; overflow-y: auto !important; } -td { border-bottom: none !important; padding: 0.1em 0.5em !important; } -tr { border-bottom: none !important; padding: 0.1em 0.5em !important; } +td { border-bottom: none !important; padding: 0 0.5em !important; } +tr { border-bottom: none !important; padding: 0 0.5em !important; } textarea { overflow-y: auto !important; } span { font-size: var(--text-md) !important; } button { font-size: var(--text-lg) !important; } @@ -21,6 +28,9 @@ input[type='color'] { width: 64px; height: 32px; } .hidden { display: none; } .tabitem { padding: 0 !important; } +/* color elements */ + + .gradio-dropdown, .block.gradio-slider, .block.gradio-checkbox, .block.gradio-textbox, .block.gradio-radio, .block.gradio-checkboxgroup, .block.gradio-number, .block.gradio-colorpicker { border-width: 0 !important; box-shadow: none !important;} .gradio-accordion { padding-top: var(--spacing-md) !important; padding-right: 0 !important; padding-bottom: 0 !important; color: var(--body-text-color); } .gradio-accordion .label-wrap .icon { color: var(--button-primary-border-color); } @@ -248,7 +258,7 @@ table.settings-value-table td { padding: 0.4em; border: 1px solid #ccc; max-widt #pnginfo_html_info .gradio-html > div { margin: 0.5em; } /* log monitor */ -.log-monitor { display: none; justify-content: unset !important; overflow: hidden; padding: 0; margin-top: auto; font-family: monospace; font-size: var(--text-xs); } +.log-monitor { display: none; justify-content: unset !important; overflow: hidden; padding: 0; margin-top: auto; font-family: monospace; font-size: var(--text-xxs); } .log-monitor td, .log-monitor th { padding-left: 1em; } /* changelog */ diff --git a/javascript/ui.js b/javascript/ui.js index c30c19f6d..782487f41 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -70,6 +70,10 @@ async function setTheme(val, old) { old = old.replace('modern/', ''); val = val.replace('modern/', ''); const links = Array.from(document.getElementsByTagName('link')).filter((l) => l.href.includes(old)); + if (links.length === 0) { + log('setTheme: current theme not matched', old); + return; + } for (const link of links) { const href = link.href.replace(old, val); const res = await fetch(href); diff --git a/modules/theme.py b/modules/theme.py index eb594834e..04fd3dda4 100644 --- a/modules/theme.py +++ b/modules/theme.py @@ -43,11 +43,12 @@ def list_themes(): if 'sdnext-ui-ux' in extensions: ext = next((e for e in modules.extensions.extensions if e.name == 'sdnext-ui-ux'), None) folder = os.path.join(ext.path, 'themes') - engines.append('modern/default') if os.path.exists(folder): for f in os.listdir(folder): if f.endswith('.css'): engines.append(f'modern/{os.path.splitext(f)[0]}') + if len(engines) == 0: + engines.append('modern/sdxl_alpha') if 'sd-webui-lobe-theme' in extensions: modules.shared.log.info('Theme: installed="lobe"') engines.append('lobe') @@ -68,6 +69,8 @@ def reload_gradio_theme(theme_name=None): theme_name = theme_name or modules.shared.cmd_opts.theme or modules.shared.opts.gradio_theme if theme_name == 'default': theme_name = 'black-teal' + if theme_name == 'modern': + theme_name = 'modern/sdxl_alpha' modules.shared.opts.data['gradio_theme'] = theme_name default_font_params = { 'font':['Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'], diff --git a/modules/ui_javascript.py b/modules/ui_javascript.py index b6201c3cb..c8edb20c7 100644 --- a/modules/ui_javascript.py +++ b/modules/ui_javascript.py @@ -60,6 +60,8 @@ def html_css(is_builtin: bool): theme_name = modules.shared.cmd_opts.theme or modules.shared.opts.gradio_theme or '' if theme_name == 'default': theme_name = 'black-teal' + if theme_name == 'modern' or theme_name == 'modern/default': + theme_name = 'modern/sdxl_alpha' if theme_name.startswith('modern/'): theme_name = theme_name[7:] theme_folder = next((e.path for e in modules.extensions.extensions if e.name == 'sdnext-ui-ux'), None)