Skip to content

Commit

Permalink
add log monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed Jun 28, 2023
1 parent c90e996 commit 5a341b1
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 9 deletions.
2 changes: 1 addition & 1 deletion extensions-builtin/clip-interrogator-ext
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions javascript/logMonitor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let logMonitorEl = null;

async function logMonitor() {
setTimeout(logMonitor, opts.logmonitor_refresh_period);
if (logMonitorEl) logMonitorEl.parentElement.style.display = opts.logmonitor_show ? 'block' : 'none';
if (!opts.logmonitor_show) return;
const res = await fetch('/sdapi/v1/log?clear=True');
if (res?.ok) {
if (!logMonitorEl) logMonitorEl = document.getElementById('logMonitorData');
if (!logMonitorEl) return;
logMonitorEl.parentElement.style.display = 'block';
const lines = await res.json();
for (const line of lines) {
const l = JSON.parse(line);
const row = document.createElement("tr");
row.style = 'padding: 10px; margin: 0;';
row.innerHTML = `<td>${new Date(1000 * l.created).toISOString()}</td><td>${l.level}</td><td>${l.facility}</td><td>${l.module}</td><td>${l.msg}</td>`;
logMonitorEl.appendChild(row);
while (logMonitorEl.childElementCount > 100) logMonitorEl.removeChild(logMonitorEl.firstChild);
logMonitorEl.scrollTop = logMonitorEl.scrollHeight
}
}
}

async function logMonitorCreate() {
const el = document.getElementsByTagName('footer')[0];
if (!el) return;
el.classList.add('log-monitor');
el.innerHTML = `
<table style="width: 100%">
<thead style="display: block; text-align: left; border-bottom: solid 1px var(--button-primary-border-color)">
<tr>
<th style="width: 170px">Time</th>
<th>Level</th>
<th style="width: 72px">Facility</th>
<th style="width: 124px">Module</th>
<th>Message</th>
</tr>
</thead>
<tbody id="logMonitorData" style="white-space: nowrap; height: 10vh; width: 100vw; display: block; overflow-x: hidden; overflow-y: scroll">
</tbody>
</table>
`;
logMonitor();
}
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion javascript/set-hints.js → javascript/setHints.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ async function setHints() {
];
if (elements.length === 0) return;
if (Object.keys(opts).length === 0) return;
if (!locale.el) tooltipCreate();
if (!locale.el) {
tooltipCreate();
logMonitorCreate();
}
let localized = 0;
let hints = 0;
locale.finished = true;
Expand Down
14 changes: 11 additions & 3 deletions javascript/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ button.custom-button{
text-align: center;
}

/* remove footer */
footer { display: none !important; }

/* themes */
.theme-preview { display: none; position: fixed; border: 4px solid var(--neutral-600); box-shadow: 2px 2px 2px 2px var(--neutral-700); top: 0; bottom: 0; left: 0; right: 0; margin: auto; max-width: 75vw; z-index: 999; }

Expand Down Expand Up @@ -668,3 +665,14 @@ div.controlnet_main_options { display: grid; grid-template-columns: 1fr 1fr; gri
#refresh_tac_refreshTempFiles { display: none; }
#train_tab { flex-flow: row-reverse; }
#models_tab { flex-flow: row-reverse; }

.log-monitor {
display: none;
justify-content: unset !important;
overflow: hidden;
padding: 0;
margin-top: auto;
font-family: monospace;
font-size: 0.85em;
}
.log-monitor td, .log-monitor th { padding-left: 1em; }
File renamed without changes.
9 changes: 7 additions & 2 deletions modules/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

errors.install()


def upscaler_to_index(name: str):
try:
return [x.name.lower() for x in shared.sd_upscalers].index(name.lower())
Expand Down Expand Up @@ -157,8 +158,12 @@ def auth(self, credentials: HTTPBasicCredentials = Depends(HTTPBasic())):
return True
raise HTTPException(status_code=401, detail="Unauthorized", headers={"WWW-Authenticate": "Basic"})

def get_log_buffer(self):
return shared.log.buffer

def get_log_buffer(self, req: models.LogRequest = Depends()):
lines = shared.log.buffer[:req.lines] if req.lines > 0 else shared.log.buffer.copy()
if req.clear:
shared.log.buffer.clear()
return lines

def get_selectable_script(self, script_name, script_runner):
if script_name is None or script_name == "":
Expand Down
4 changes: 4 additions & 0 deletions modules/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class PNGInfoResponse(BaseModel):
info: str = Field(title="Image info", description="A string with the parameters used to generate the image")
items: dict = Field(title="Items", description="An object containing all the info the image had")

class LogRequest(BaseModel):
lines: int = Field(default=100, title="Lines", description="How many lines to return")
clear: bool = Field(default=False, title="Clear", description="Should the log be cleared after returning the lines?")

class ProgressRequest(BaseModel):
skip_current_image: bool = Field(default=False, title="Skip current image", description="Skip current image serialization")

Expand Down
2 changes: 1 addition & 1 deletion modules/lycoris
4 changes: 3 additions & 1 deletion modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ def refresh_themes():
"show_progress_every_n_steps": OptionInfo(1, "Live preview display period", gr.Slider, {"minimum": -1, "maximum": 32, "step": 1}),
"show_progress_type": OptionInfo("Approximate NN", "Live preview method", gr.Radio, {"choices": ["Full VAE", "Approximate NN", "Approximate simple", "TAESD"]}),
"live_preview_content": OptionInfo("Combined", "Live preview subject", gr.Radio, {"choices": ["Combined", "Prompt", "Negative prompt"]}),
"live_preview_refresh_period": OptionInfo(250, "Progressbar/preview update period, in milliseconds")
"live_preview_refresh_period": OptionInfo(250, "Progressbar/preview update period, in milliseconds", gr.Slider, {"minimum": 0, "maximum": 5000, "step": 25}),
"logmonitor_show": OptionInfo(True, "Show log view"),
"logmonitor_refresh_period": OptionInfo(1000, "Log view update period, in milliseconds", gr.Slider, {"minimum": 0, "maximum": 5000, "step": 25}),
}))

options_templates.update(options_section(('sampler-params', "Sampler Settings"), {
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ select = [
# "PL",
]
exclude = [
"/usr/lib",
"extensions",
"extensions-builtin",
"modules/lora",
Expand Down

0 comments on commit 5a341b1

Please sign in to comment.