OP requested a button to clear the logs in the info panel.
Now there is a button for that.
and a service system_log.clear
Haha, that button doesnât actually clear the log.
It does clear the log on that page
Just not the log file.
Just for full understanding, the truncate command makes the shell_commands
create_log
and
set_perm
obsolete. Truncate keeps the file in tact and deletes the contents of the logfile.
I have opposite problem. My log is being cleared each time Hassio spontaneously restarts. I would like to keep the log to diagnose the reason.
I find this useful but as a conclusion what are the steps/code for this to work?
Because I see truncate and from there I cannot understand anything.
If youâd like to clear the log just create a script called empty_log in the scripts.yaml file. The script calls the shell command. I have commented out the shell commands that are not needed if you use the truncate command:
# Empty the log file empty_log: alias: Clear log HA sequence: - service: shell_command.clear_log # - service: shell_command.create_log # - service: shell_command.set_perm
In fact, if you only have the one shell command, you can just use that in an automation, if you prefer.
Thank you.
I am only intrested in clearing the log, not delete the file (there is no use to delete it as long as the contents are emptied)
So this is the only entry to clear the logs? No other code in another yaml file?
(I see that clear_log.yaml with a command inside it)
That âservice: shell_command.clear_logâ is already embedded in HA?
# Empty the log file empty_log: alias: Clear log HA sequence: - service: shell_command.clear_log
edit:
I executed the script⌠no effect, the log file still has text in it.
2018-12-24 01:06:58 WARNING (MainThread) [homeassistant.core] Unable to find service shell_command/clear_log
edit 2:
For those noobs struggling like me, the full instructions:
-
create a folder âshellâ (in the same dir as configuration.yaml)
-
inside folder âshellâ create a file âclear_log.yamlâ and inside it put this line:
truncate -s 0 home-assistant.log
-
in âconfiguration.yamlâ put this line
shell_command: !include_dir_named shell/
-
in âscripts.yamlâ put this line (if you split the configuration.yaml) :
empty_log: alias: Clear log HA sequence: - service: shell_command.clear_log
The script calls the clear_log.yaml (actualy the command inside it) from the folder âshellâ .
See the new entry in the Scripts section of the UI. Click EXECUTE and will empty the log file (it takes 2-3 seconds).
ps.
Now if I could find instructions to do the same for database db or to find out what the command shell would be
Edit: Stupid reaction, recorder has nothing to do with the log.
whatever I try, i doesnât touch the database (or so it seems), which keeps growingâŚ
No idea how the purging actually works. Might need a restart to purge the db.
The suggestion of mine has nothing to do with the log, so itâs not helpful at all.
No idea why I posted that
Using the same logic in script, actually I managed to clear the database by deleting it using this command written in âclear_db.yamlâ in the âshellâ folder.
rm home-assistant_v2.db
It deletes the DB but for unknown reason HA recreates one back but no more than 4k in size and the log is pouring with errors because cannot write in the db any more.
A reboot fixes this and deleting the 4k db file.
I wonder id truncate command works on db file, since is not a text file like the log.
ps.
It is safe to delete db file while HA is On, it will recreate another fresh one.
great, thank you