Skip to content

Change logging to do rollover() instead of rotate() #55177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ config/*
config2/*

tests/testing_config/deps
tests/testing_config/home-assistant.log
tests/testing_config/home-assistant.log*

# hass-release
data/
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def async_enable_logging(
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:
err_handler = logging.handlers.TimedRotatingFileHandler(
err_log_path, when="midnight", backupCount=log_rotate_days
Expand All @@ -342,7 +342,7 @@ def async_enable_logging(
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.setFormatter(logging.Formatter(fmt, datefmt=datefmt))

Expand Down
5 changes: 5 additions & 0 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test the bootstrapping."""
# pylint: disable=protected-access
import asyncio
import glob
import os
from unittest.mock import Mock, patch

Expand Down Expand Up @@ -69,6 +70,10 @@ async def test_async_enable_logging(hass):
log_file="test.log",
)
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):
Expand Down