You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/_components/system_log.markdown
+64-1Lines changed: 64 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ ha_category: Other
12
12
ha_release: 0.58
13
13
---
14
14
15
-
The `system_log` component stores information about all logged errors and warnings in Home Assistant. All collected information is accessible directly in the frontend, just navigate to the `Info` section under `Developer Tools`. In order to not overload Home Assistant with log data, only the 50 last errors and warnings will be stored. Older entries are automatically discarded from the log. It is possible to change the amount of stored log entries using the parameter `max_entries`.
15
+
The `system_log` component stores information about all logged errors and warnings in Home Assistant. All collected information is accessible directly in the frontend, just navigate to the `Info` section under `Developer Tools`. In order to not overload Home Assistant with log data, only the 50 last errors and warnings will be stored. Older entries are automatically discarded from the log. It is possible to change the number of stored log entries using the parameter `max_entries`.
16
16
17
17
This component is automatically loaded by the `frontend` (so no need to do anything if you are using the frontend). If you are not doing so, or if you wish to change a parameter, add the following section to your `configuration.yaml` file:
18
18
@@ -35,3 +35,66 @@ max_entries:
35
35
36
36
To manually clear the system log, call this service.
37
37
38
+
## {% linkable_title Events %}
39
+
40
+
Errors and warnings are posted as the event `system_log_event`, so it is possible to write automations that trigger whenever a warning or error occurs. The following information is included in each event:
| `level` | Either `WARNING` or `ERROR` depending on severity. |
45
+
| `source` | File that triggered the error, e.g., `core.py` or `media_player/yamaha.py`. |
46
+
| `exception` | Full stack trace if available, otherwise empty string. |
47
+
| `message` | Descriptive message of the error, e.g., "Error handling request". |
48
+
| `timestamp` | Unix timestamp with as a double, e.g., 1517241010.237416. |
49
+
50
+
Live examples of these events can be found in the Home Assistant log file or by just looking in the system log. An example could, for instance, look like this:
The message ("Unable to find service..."), source (`core.py`) and level (`WARNING`) can easily be extracted from the image. Exact timestamp and stack trace is shown if the entry is selected.
55
+
56
+
## {% linkable_title Examples %}
57
+
58
+
Here are some examples using the events posted by `system_log`.
59
+
60
+
### {% linkable_title Counting Number of Warnings %}
61
+
62
+
This will create a `counter` that increases every time a warning is logged:
63
+
64
+
```yaml
65
+
counter:
66
+
warning_counter:
67
+
name: Warnings
68
+
icon: mdi:alert
69
+
70
+
automation:
71
+
- alias: Count warnings
72
+
trigger:
73
+
platform: event
74
+
event_type: system_log_event
75
+
event_data:
76
+
level: WARNING
77
+
action:
78
+
service: counter.increment
79
+
entity_id: counter.warning_counter
80
+
```
81
+
82
+
### {% linkable_title Conditional Messages %}
83
+
84
+
This automation will create a persistent notification whenever an error or warning is logged that has the word "service" in the message:
85
+
86
+
```yaml
87
+
automation:
88
+
- alias: Create notifications for "service" errors
89
+
trigger:
90
+
platform: event
91
+
event_type: system_log_event
92
+
condition:
93
+
condition: template
94
+
value_template: {% raw %}'{{ "service" in trigger.event.data.message }}'{% endraw %}
95
+
action:
96
+
service: persistent_notification.create
97
+
data_template:
98
+
title: Something bad happened
99
+
message: {% raw %}'{{ trigger.event.data.message }}'{% endraw %}
0 commit comments