mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-31 13:07:49 +00:00
Add more info to system log (#4899)
* Add more info to system log * Add util, oops * Tweak UI
This commit is contained in:
parent
46a596ce34
commit
322eef1c0f
10
src/data/integration.ts
Normal file
10
src/data/integration.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { LocalizeFunc } from "../common/translations/localize";
|
||||||
|
|
||||||
|
export const integrationDocsUrl = (domain: string) =>
|
||||||
|
`https://www.home-assistant.io/integrations/${domain}`;
|
||||||
|
|
||||||
|
export const integrationIssuesUrl = (domain: string) =>
|
||||||
|
`https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+${domain}%22`;
|
||||||
|
|
||||||
|
export const domainToName = (localize: LocalizeFunc, domain: string) =>
|
||||||
|
localize(`domain.${domain}`) || domain;
|
@ -1,6 +1,7 @@
|
|||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
|
|
||||||
export interface LoggedError {
|
export interface LoggedError {
|
||||||
|
name: string;
|
||||||
message: string;
|
message: string;
|
||||||
level: string;
|
level: string;
|
||||||
source: string;
|
source: string;
|
||||||
@ -14,3 +15,8 @@ export interface LoggedError {
|
|||||||
|
|
||||||
export const fetchSystemLog = (hass: HomeAssistant) =>
|
export const fetchSystemLog = (hass: HomeAssistant) =>
|
||||||
hass.callApi<LoggedError[]>("GET", "error/all");
|
hass.callApi<LoggedError[]>("GET", "error/all");
|
||||||
|
|
||||||
|
export const getLoggedErrorIntegration = (item: LoggedError) =>
|
||||||
|
item.name.startsWith("homeassistant.components.")
|
||||||
|
? item.name.split(".")[2]
|
||||||
|
: undefined;
|
||||||
|
@ -9,6 +9,10 @@ import {
|
|||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
|
import {
|
||||||
|
integrationDocsUrl,
|
||||||
|
integrationIssuesUrl,
|
||||||
|
} from "../../../data/integration";
|
||||||
|
|
||||||
@customElement("integrations-card")
|
@customElement("integrations-card")
|
||||||
class IntegrationsCard extends LitElement {
|
class IntegrationsCard extends LitElement {
|
||||||
@ -28,18 +32,12 @@ class IntegrationsCard extends LitElement {
|
|||||||
<tr>
|
<tr>
|
||||||
<td>${domain}</td>
|
<td>${domain}</td>
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a href=${integrationDocsUrl(domain)} target="_blank">
|
||||||
href=${`https://www.home-assistant.io/integrations/${domain}`}
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Documentation
|
Documentation
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a
|
<a href=${integrationIssuesUrl(domain)} target="_blank">
|
||||||
href=${`https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+${domain}%22`}
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Issues
|
Issues
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
|
@ -14,6 +14,13 @@ import { SystemLogDetailDialogParams } from "./show-dialog-system-log-detail";
|
|||||||
import { PolymerChangedEvent } from "../../../polymer-types";
|
import { PolymerChangedEvent } from "../../../polymer-types";
|
||||||
import { haStyleDialog } from "../../../resources/styles";
|
import { haStyleDialog } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import {
|
||||||
|
integrationDocsUrl,
|
||||||
|
integrationIssuesUrl,
|
||||||
|
domainToName,
|
||||||
|
} from "../../../data/integration";
|
||||||
|
import { formatSystemLogTime } from "./util";
|
||||||
|
import { getLoggedErrorIntegration } from "../../../data/system_log";
|
||||||
|
|
||||||
class DialogSystemLogDetail extends LitElement {
|
class DialogSystemLogDetail extends LitElement {
|
||||||
@property() public hass!: HomeAssistant;
|
@property() public hass!: HomeAssistant;
|
||||||
@ -30,6 +37,8 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
}
|
}
|
||||||
const item = this._params.item;
|
const item = this._params.item;
|
||||||
|
|
||||||
|
const integration = getLoggedErrorIntegration(item);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-paper-dialog
|
<ha-paper-dialog
|
||||||
with-backdrop
|
with-backdrop
|
||||||
@ -44,7 +53,34 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</h2>
|
</h2>
|
||||||
<paper-dialog-scrollable>
|
<paper-dialog-scrollable>
|
||||||
<p>${new Date(item.timestamp * 1000)}</p>
|
<p>
|
||||||
|
Logger: ${item.name}
|
||||||
|
${integration
|
||||||
|
? html`
|
||||||
|
<br />
|
||||||
|
Integration: ${domainToName(this.hass.localize, integration)}
|
||||||
|
(<a href=${integrationDocsUrl(integration)} target="_blank"
|
||||||
|
>documentation</a
|
||||||
|
>,
|
||||||
|
<a href=${integrationIssuesUrl(integration)} target="_blank"
|
||||||
|
>issues</a
|
||||||
|
>)
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
<br />
|
||||||
|
${item.count > 0
|
||||||
|
? html`
|
||||||
|
First occured:
|
||||||
|
${formatSystemLogTime(
|
||||||
|
item.first_occured,
|
||||||
|
this.hass!.language
|
||||||
|
)}
|
||||||
|
(${item.count} occurences) <br />
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
Last logged:
|
||||||
|
${formatSystemLogTime(item.timestamp, this.hass!.language)}
|
||||||
|
</p>
|
||||||
${item.message
|
${item.message
|
||||||
? html`
|
? html`
|
||||||
<pre>${item.message}</pre>
|
<pre>${item.message}</pre>
|
||||||
@ -73,6 +109,15 @@ class DialogSystemLogDetail extends LitElement {
|
|||||||
ha-paper-dialog {
|
ha-paper-dialog {
|
||||||
direction: ltr;
|
direction: ltr;
|
||||||
}
|
}
|
||||||
|
a {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -15,20 +15,14 @@ import "../../../components/ha-card";
|
|||||||
import "../../../components/buttons/ha-call-service-button";
|
import "../../../components/buttons/ha-call-service-button";
|
||||||
import "../../../components/buttons/ha-progress-button";
|
import "../../../components/buttons/ha-progress-button";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { LoggedError, fetchSystemLog } from "../../../data/system_log";
|
import {
|
||||||
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
LoggedError,
|
||||||
import { formatTimeWithSeconds } from "../../../common/datetime/format_time";
|
fetchSystemLog,
|
||||||
|
getLoggedErrorIntegration,
|
||||||
|
} from "../../../data/system_log";
|
||||||
import { showSystemLogDetailDialog } from "./show-dialog-system-log-detail";
|
import { showSystemLogDetailDialog } from "./show-dialog-system-log-detail";
|
||||||
|
import { formatSystemLogTime } from "./util";
|
||||||
const formatLogTime = (date, language: string) => {
|
import { domainToName } from "../../../data/integration";
|
||||||
const today = new Date().setHours(0, 0, 0, 0);
|
|
||||||
const dateTime = new Date(date * 1000);
|
|
||||||
const dateTimeDay = new Date(date * 1000).setHours(0, 0, 0, 0);
|
|
||||||
|
|
||||||
return dateTimeDay < today
|
|
||||||
? formatDateTimeWithSeconds(dateTime, language)
|
|
||||||
: formatTimeWithSeconds(dateTime, language);
|
|
||||||
};
|
|
||||||
|
|
||||||
@customElement("system-log-card")
|
@customElement("system-log-card")
|
||||||
export class SystemLogCard extends LitElement {
|
export class SystemLogCard extends LitElement {
|
||||||
@ -42,6 +36,9 @@ export class SystemLogCard extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
|
const integrations = this._items
|
||||||
|
? this._items.map((item) => getLoggedErrorIntegration(item))
|
||||||
|
: [];
|
||||||
return html`
|
return html`
|
||||||
<div class="system-log-intro">
|
<div class="system-log-intro">
|
||||||
<ha-card>
|
<ha-card>
|
||||||
@ -61,25 +58,32 @@ export class SystemLogCard extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: this._items.map(
|
: this._items.map(
|
||||||
(item) => html`
|
(item, idx) => html`
|
||||||
<paper-item @click=${this._openLog} .logItem=${item}>
|
<paper-item @click=${this._openLog} .logItem=${item}>
|
||||||
<paper-item-body two-line>
|
<paper-item-body two-line>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
${item.message}
|
${item.message}
|
||||||
</div>
|
</div>
|
||||||
<div secondary>
|
<div secondary>
|
||||||
${formatLogTime(
|
${formatSystemLogTime(
|
||||||
item.timestamp,
|
item.timestamp,
|
||||||
this.hass!.language
|
this.hass!.language
|
||||||
)}
|
)}
|
||||||
${item.source} (${item.level})
|
–
|
||||||
|
${integrations[idx]
|
||||||
|
? domainToName(
|
||||||
|
this.hass!.localize,
|
||||||
|
integrations[idx]!
|
||||||
|
)
|
||||||
|
: item.source}
|
||||||
|
(${item.level})
|
||||||
${item.count > 1
|
${item.count > 1
|
||||||
? html`
|
? html`
|
||||||
-
|
-
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.developer-tools.tabs.logs.multiple_messages",
|
"ui.panel.developer-tools.tabs.logs.multiple_messages",
|
||||||
"time",
|
"time",
|
||||||
formatLogTime(
|
formatSystemLogTime(
|
||||||
item.first_occured,
|
item.first_occured,
|
||||||
this.hass!.language
|
this.hass!.language
|
||||||
),
|
),
|
||||||
|
13
src/panels/developer-tools/logs/util.ts
Normal file
13
src/panels/developer-tools/logs/util.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { formatDateTimeWithSeconds } from "../../../common/datetime/format_date_time";
|
||||||
|
|
||||||
|
import { formatTimeWithSeconds } from "../../../common/datetime/format_time";
|
||||||
|
|
||||||
|
export const formatSystemLogTime = (date, language: string) => {
|
||||||
|
const today = new Date().setHours(0, 0, 0, 0);
|
||||||
|
const dateTime = new Date(date * 1000);
|
||||||
|
const dateTimeDay = new Date(date * 1000).setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
return dateTimeDay < today
|
||||||
|
? formatDateTimeWithSeconds(dateTime, language)
|
||||||
|
: formatTimeWithSeconds(dateTime, language);
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user