Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions src/panels/config/logs/error-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,29 @@ import { HomeAssistant } from "../../../types";
class ErrorLogCard extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;

@internalProperty() private _errorLog?: string;
@internalProperty() private _errorHTML!: TemplateResult[] | string;

protected render(): TemplateResult {
return html`
<p class="error-log-intro">
${this._errorLog
<div class="error-log-intro">
${this._errorHTML
? html`
<ha-icon-button
icon="hass:refresh"
@click=${this._refreshErrorLog}
></ha-icon-button>
<ha-card>
<ha-icon-button
icon="hass:refresh"
@click=${this._refreshErrorLog}
></ha-icon-button>
<div class="card-content error-log">
${this._errorHTML}
</div>
</ha-card>
`
: html`
<mwc-button raised @click=${this._refreshErrorLog}>
${this.hass.localize("ui.panel.config.logs.load_full_log")}
</mwc-button>
`}
</p>
<div class="error-log">${this._errorLog}</div>
</div>
`;
}

Expand All @@ -59,17 +63,42 @@ class ErrorLogCard extends LitElement {
.error-log {
@apply --paper-font-code)
clear: both;
white-space: pre-wrap;
margin: 16px;
text-align: left;
padding-top: 12px;
}

.error {
color: var(--error-color);
}

.warning {
color: var(--warning-color);
}
`;
}

private async _refreshErrorLog(): Promise<void> {
this._errorLog = this.hass.localize("ui.panel.config.logs.loading_log");
this._errorHTML = this.hass.localize("ui.panel.config.logs.loading_log");
const log = await fetchErrorLog(this.hass!);
this._errorLog =
log || this.hass.localize("ui.panel.config.logs.no_errors");

this._errorHTML = log
? log.split("\n").map((entry) => {
if (entry.includes("INFO"))
return html`<div class="info">${entry}</div>`;

if (entry.includes("WARNING"))
return html`<div class="warning">${entry}</div>`;

if (
entry.includes("ERROR") ||
entry.includes("FATAL") ||
entry.includes("CRITICAL")
)
return html`<div class="error">${entry}</div>`;

return html`<div>${entry}</div>`;
})
: this.hass.localize("ui.panel.config.logs.no_errors");
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/panels/config/logs/system-log-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export class SystemLogCard extends LitElement {
integrations[idx]!
)
: item.source[0]}
(${item.level})
${html`(<span class="${item.level.toLowerCase()}"
>${item.level}</span
>)`}
${item.count > 1
? html`
-
Expand Down Expand Up @@ -164,6 +166,14 @@ export class SystemLogCard extends LitElement {
align-items: center;
justify-content: center;
}

.error {
color: var(--error-color);
}

.warning {
color: var(--warning-color);
}
`;
}
}
Expand Down