Option to purge the log

It would be nice to have a button to empty the log on the info page.

Add scripts and shell folders to homeassistant\

create empty_log.yaml

alias: Clear Log
sequence:
  - service: shell_command.clear_log

create clear_log.yaml
truncate /home/homeassistant/.homeassistant/home-assistant.log --size 0

add script.empty_log to configuration.yaml
or
if you using groups.yaml
add script.empty_log to groups.yaml

Include scripts and shell folders in configuration.yaml:

script: !include_dir_named scripts/
shell_command: !include_dir_named shell/

1

3 Likes

We already have a command line option for that: hass --log-rotate-days 5

2 Likes

Wow

Didn’t know about that option for auto rotate - I assume it can be added to the startup job for whatever flavour startup you use?

What if I restart hass from the hass config panel? How does the log-rotate-days get set?

This sounds great as I try and keep my system up and stable as much as possible.

How can you add command line options in Hassio?
Might as well just open the .log file, select all, delete and save it.

Thanks! That might indeed be an option.
Still a lot of work for something that simple, and a button on the info page would be beneficial to everybody.

2 Likes

I use the docker image. Is there a way to set this as an option during the container start?

Exactly what I was looking for. But can’t get it to work (Hassio 0,70)
Anny idea?

shellconfigscriptinclude

not sure about Hassio
can you see your home assistant folder structure if you ssh into your hassio?
i think at
cd /usr/local/share/hassio/homeassistant?

2

@Vlad this looks like Hassbian? if it is i dont think it’ll work in hassio

Using Hassio v 0.70.1

ok, my mistake

Changes for Hassio:

2

3

4

5

I am getting somewhere, but not there yet.
So made the error message when doing a config check go away by using my own defined text “system_log”.

dokscript

clearHA

Restarted Hassio (0.71) but no “Clear Log HA” appeard in my system. And I am not getting button “Activate”?
Do I have to bind the script/shell comands to a switch.And if so, please give an example of the code?

Create sensor:

6

Add to Automation:

7

1 Like

@Vlad
The shell commands:
clear_log_ha: rm home-assistant.log
create_log_ha: touch home-assistant.log
set_perm_ha: chmod 777 home-assistant.log

Your shell commands does delete and creates a new file. But HA (Hassio 0.71.0) cannot write log entries into the new file. The log file stays empty after activating the script. Have monitored it for days. And the log files are still empty.

Any ideas?

1 Like

rm is remove command.
Try to use truncate instead.
Like:
truncate home-assistant.log --size 0
or
truncate -s 0 home-assistant.log

1 Like

Thats a winner. The truncate worked fine!

ha_log_truncate: truncate -s 0 home-assistant.log

Reading this thread I’d like to point out that the myriad “answers” make a strong case for what was the original point made by the OP…

This shouldn’t be so stupid and difficult.

2 Likes