Move error log <ha-card> + color in log entries (#7382)

This commit is contained in:
Philip Allgaier 2020-10-19 22:05:19 +02:00 committed by GitHub
parent 990ae10dc2
commit 3ee4c11a99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 15 deletions

View File

@ -15,25 +15,29 @@ import { HomeAssistant } from "../../../types";
class ErrorLogCard extends LitElement { class ErrorLogCard extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@internalProperty() private _errorLog?: string; @internalProperty() private _errorHTML!: TemplateResult[] | string;
protected render(): TemplateResult { protected render(): TemplateResult {
return html` return html`
<p class="error-log-intro"> <div class="error-log-intro">
${this._errorLog ${this._errorHTML
? html` ? html`
<ha-card>
<ha-icon-button <ha-icon-button
icon="hass:refresh" icon="hass:refresh"
@click=${this._refreshErrorLog} @click=${this._refreshErrorLog}
></ha-icon-button> ></ha-icon-button>
<div class="card-content error-log">
${this._errorHTML}
</div>
</ha-card>
` `
: html` : html`
<mwc-button raised @click=${this._refreshErrorLog}> <mwc-button raised @click=${this._refreshErrorLog}>
${this.hass.localize("ui.panel.config.logs.load_full_log")} ${this.hass.localize("ui.panel.config.logs.load_full_log")}
</mwc-button> </mwc-button>
`} `}
</p> </div>
<div class="error-log">${this._errorLog}</div>
`; `;
} }
@ -59,17 +63,42 @@ class ErrorLogCard extends LitElement {
.error-log { .error-log {
@apply --paper-font-code) @apply --paper-font-code)
clear: both; clear: both;
white-space: pre-wrap; text-align: left;
margin: 16px; padding-top: 12px;
}
.error {
color: var(--error-color);
}
.warning {
color: var(--warning-color);
} }
`; `;
} }
private async _refreshErrorLog(): Promise<void> { 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!); 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");
} }
} }

View File

@ -77,7 +77,9 @@ export class SystemLogCard extends LitElement {
integrations[idx]! integrations[idx]!
) )
: item.source[0]} : item.source[0]}
(${item.level}) ${html`(<span class="${item.level.toLowerCase()}"
>${item.level}</span
>)`}
${item.count > 1 ${item.count > 1
? html` ? html`
- -
@ -164,6 +166,14 @@ export class SystemLogCard extends LitElement {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.error {
color: var(--error-color);
}
.warning {
color: var(--warning-color);
}
`; `;
} }
} }