ckha
(CK)
September 9, 2024, 3:41pm
1
Maybe someone finds this useful. Based on this thread from 2020
Create log_backups
inside the config
dir.
configuration.yaml
:
shell_command:
log_backup: >-
cp ./home-assistant.log ./config/log_backups/log-`date +"%Y%m%d%H%M%S"`.log
log_rotate: >-
cp ./home-assistant.log ./config/log_backups/log-`date +"%Y%m%d%H%M%S"`.log &&
truncate -s 0 ./home-assistant.log
Automation:
alias: Rotate log on shutdown and at midnight
description: ""
trigger:
- platform: homeassistant
event: shutdown
- platform: time
at: "00:00:00"
condition: []
action:
- action: shell_command.log_rotate
data: {}
mode: single
Not sure if any logging is lost during the operation (esp. the one invoked at midnight) but should be minimal and better than losing the log completely on restart.
Works on docker supervised.
Edwin_D
(Edwin D.)
September 9, 2024, 4:02pm
2
Without any special configuration there’s always the log of the previous session after the restart in homeassistant.log.1 so what are you losing after a restart?
ckha
(CK)
September 9, 2024, 4:34pm
3
My case was I wasn’t restarting and the log just grew.
What one’s loosing with last log is all the previous ones with multiple restarts.
petro
(Petro)
September 9, 2024, 5:07pm
4
HA always wipes the current log file on restart and it always saves the previous log file as .1 in your config folder.
What you’ve done here is created a rotating log based on the days.
You can also do this in HA without an automation depending on what install method you are using. If you’re using core or docker, you can modify the log rotation schedule without an automation.
You can probably do the same with supervised as well, but you might have to modify the setup files.
ckha
(CK)
September 9, 2024, 6:42pm
5
Yes, exactly.
Haven’t found anything about this. There is a flag you can pass with standalone install but not the supervised one. Happy to be pointed to a documentation or anything really as I haven’t found anything useful for Supervised.
petro
(Petro)
September 9, 2024, 6:45pm
6
There isn’t any documentation on this, I just know the code.
If you pass --log-rotate-days
with a number, you’ll get that behavior
metavar="package_names",
type=lambda arg: arg.split(","),
default=[],
help="Skip pip install of specific packages on startup",
)
parser.add_argument(
"-v", "--verbose", action="store_true", help="Enable verbose logging to file."
)
parser.add_argument(
"--log-rotate-days",
type=int,
default=None,
help="Enables daily log rotation and keeps up to the specified days",
)
parser.add_argument(
"--log-file",
type=str,
default=None,
help="Log file to write to. If not set, CONFIG/home-assistant.log is used",
)
EDIT: There might be documentation somewhere, but I’ve never bothered looking
ckha
(CK)
September 9, 2024, 7:07pm
7
This is what I found today too but AFAIK it’s not passed to the supervised:
Some other discussions:
Yeah , thats a big AO, people have to learn about the consequences of their actions, such as keeping backups forever, logging/writing every tiny details, in DB, and storing logfiles.
Actually such basic Info(knowledge) should be “punched” in (somehow/somewhere), as many new users , doesn’t know the impact or relevance
opened 04:08AM - 23 Dec 22 UTC
integration: system_log
### The problem
Running HA in Container on a host with 32GB SD memory.
At le… ast twice I observed an issue:
- log files became very large,
- no free space was left on SD,
- recorder stopped working.
Here the log file became > 6GB:
![image](https://user-images.githubusercontent.com/71872483/209268811-21c82857-ab85-4263-8ee8-c14c738eb619.png)
My config:
```
system_log:
max_entries: 200
fire_event: true
```
I believed that no more than 200 entries will be saved in the Log.
Seems that `max_entries` does not work.
Earlier I sometimes noticed too that amount of rows in Log is larger than 200; but it was not crucial for me - before I faced THIS HUGE amount.
It is clear that the Log should not be filled with such amount of errors/warnings - that I should find a reason of these errors/warnings in my setup. But the point of this issue is "Why max-enties does not work?".
### What version of Home Assistant Core has the issue?
2022.12.7
### What was the last working version of Home Assistant Core?
_No response_
### What type of installation are you running?
Home Assistant Container
### Integration causing the issue
System Log
### Link to integration documentation on our website
https://www.home-assistant.io/integrations/system_log/
### Diagnostics information
_No response_
### Example YAML snippet
_No response_
### Anything in the logs that might be useful for us?
_No response_
### Additional information
_No response_
I think the home assistant os should have this option natively (natively running an ssh server outside of the actual home assistant app), so that you don’t need to be a hacker. Or at least don’t clear the logs upon restart so that we less-hacky people can give them their logs when doing error reports.
I’ve found a lot of topics about limiting the size of this file, but most seem to only talk about command line options, like --log-rotate-days. I run HA from a docker-compose file, so AFAIK, I can’t use command line options.
So, to keep it short:
In 2023, running HA in a Docker container, how do we limit the size of the home-assistant.log file found in the config folder?
opened 09:04PM - 08 May 22 UTC
closed 12:06PM - 18 Jun 22 UTC
stale
### The problem
Every time i restart hass, a new logfile is created and the old… file is written (not attached) to a `home-assistant.log.yyyy-mm-dd` log.
My logiles at the moment:
![20220508_223449](https://user-images.githubusercontent.com/26381449/167314864-0129ea91-1bfa-4435-bb3f-7a203a56afb9.png)
The last 'good one' was
home-assistant.log.2022-05-05
```
start
2022-05-05 00:01:56 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for esph ...
...
2022-05-05 23:41:05 ERROR (MainThread) [homeassistant.components.co2signal] Error fetching co2signal ...
end
```
since then the daily logs start with the last restart time:
home-assistant.log.2022-05-06
```
start
2022-05-06 05:57:14 INFO (MainThread) [homeassistant.bootstrap] Config directory: /home/homeassi/.homeassistant
...
2022-05-06 23:35:02 WARNING (MainThread) [homeassistant.components.automation...
end
```
home-assistant.log.2022-05-07
```
start
2022-05-07 21:13:33 INFO (MainThread) [homeassistant.bootstrap] Config directory: /home/homeassi/.homeassistant
...
2022-05-07 23:45:14 WARNING (MainThread) [homeassistant.components.automation...
end
```
home-assistant.log.2022-05-08
```
start
2022-05-08 21:57:31 INFO (MainThread) [homeassistant.bootstrap] Config directory: /home/homeassi/.homeassistant
...
now
end
```
I'm not sure about the last working version, 2022.5.0b7 and 2022.5.0 was installed on 20220504.
Maybe it started wit 2022.5.1?
### What version of Home Assistant Core has the issue?
core-2022.5.3
### What was the last working version of Home Assistant Core?
core-2022.4.7
### What type of installation are you running?
Home Assistant Core
### Integration causing the issue
hass
### Link to integration documentation on our website
https://www.home-assistant.io/docs/tools/hass/
### Diagnostics information
_No response_
### Example YAML snippet
_No response_
### Anything in the logs that might be useful for us?
_No response_
### Additional information
_No response_
In my case, I have no logger entry in configuration.yaml. Nevertheless, there is a home-assistant.log file and it’s about 82 Kb. Whatever I see in there is also found in /var/log/syslog.
The home-assistant.log file is automatically purged after every restart whereas the duplicated entries in syslog are retained.
Anyway, that’s how it works on my system (version 0.89 in a venv).