Change logging to do rollover() instead of rotate() (#55177)
* Change to rollover from rotate. * Remove test log files.
This commit is contained in:
parent
d984e137b8
commit
3a0a8da648
3 changed files with 8 additions and 3 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,7 +2,7 @@ config/*
|
||||||
config2/*
|
config2/*
|
||||||
|
|
||||||
tests/testing_config/deps
|
tests/testing_config/deps
|
||||||
tests/testing_config/home-assistant.log
|
tests/testing_config/home-assistant.log*
|
||||||
|
|
||||||
# hass-release
|
# hass-release
|
||||||
data/
|
data/
|
||||||
|
|
|
@ -332,7 +332,7 @@ def async_enable_logging(
|
||||||
not err_path_exists and os.access(err_dir, os.W_OK)
|
not err_path_exists and os.access(err_dir, os.W_OK)
|
||||||
):
|
):
|
||||||
|
|
||||||
err_handler: logging.FileHandler
|
err_handler: logging.handlers.RotatingFileHandler | logging.handlers.TimedRotatingFileHandler
|
||||||
if log_rotate_days:
|
if log_rotate_days:
|
||||||
err_handler = logging.handlers.TimedRotatingFileHandler(
|
err_handler = logging.handlers.TimedRotatingFileHandler(
|
||||||
err_log_path, when="midnight", backupCount=log_rotate_days
|
err_log_path, when="midnight", backupCount=log_rotate_days
|
||||||
|
@ -342,7 +342,7 @@ def async_enable_logging(
|
||||||
err_log_path, backupCount=1
|
err_log_path, backupCount=1
|
||||||
)
|
)
|
||||||
|
|
||||||
err_handler.rotate(err_log_path, f"{err_log_path[:-4]}.previous.log")
|
err_handler.doRollover()
|
||||||
err_handler.setLevel(logging.INFO if verbose else logging.WARNING)
|
err_handler.setLevel(logging.INFO if verbose else logging.WARNING)
|
||||||
err_handler.setFormatter(logging.Formatter(fmt, datefmt=datefmt))
|
err_handler.setFormatter(logging.Formatter(fmt, datefmt=datefmt))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
"""Test the bootstrapping."""
|
"""Test the bootstrapping."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
|
@ -69,6 +70,10 @@ async def test_async_enable_logging(hass):
|
||||||
log_file="test.log",
|
log_file="test.log",
|
||||||
)
|
)
|
||||||
mock_async_activate_log_queue_handler.assert_called_once()
|
mock_async_activate_log_queue_handler.assert_called_once()
|
||||||
|
for f in glob.glob("test.log*"):
|
||||||
|
os.remove(f)
|
||||||
|
for f in glob.glob("testing_config/home-assistant.log*"):
|
||||||
|
os.remove(f)
|
||||||
|
|
||||||
|
|
||||||
async def test_load_hassio(hass):
|
async def test_load_hassio(hass):
|
||||||
|
|
Loading…
Add table
Reference in a new issue