Skip to content

Commit d5404ed

Browse files
postlundfrenck
authored andcommitted
Add documentation for system_log_event (home-assistant#4549)
* Add documentation for system_log_event * ✏️ Minor improvements
1 parent 809034c commit d5404ed

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

source/_components/system_log.markdown

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ha_category: Other
1212
ha_release: 0.58
1313
---
1414

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`.
1616

1717
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:
1818

@@ -35,3 +35,66 @@ max_entries:
3535

3636
To manually clear the system log, call this service.
3737

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:
41+
42+
| Field | Description |
43+
|------------------------------------------------------------------------------------------|
44+
| `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:
51+
52+
<img src='/images/components/system_log/system_log_entry.png' />
53+
54+
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 %}
100+
```

0 commit comments

Comments
 (0)