mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Move error log <ha-card> + color in log entries (#7382)
This commit is contained in:
parent
990ae10dc2
commit
3ee4c11a99
@ -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-icon-button
|
<ha-card>
|
||||||
icon="hass:refresh"
|
<ha-icon-button
|
||||||
@click=${this._refreshErrorLog}
|
icon="hass:refresh"
|
||||||
></ha-icon-button>
|
@click=${this._refreshErrorLog}
|
||||||
|
></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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user