Started work on per-pass log handling in hw-diags
This commit is contained in:
parent
9b5d9e1186
commit
4e6b2cd4da
2 changed files with 36 additions and 5 deletions
|
|
@ -71,6 +71,7 @@ class State():
|
|||
def __init__(self):
|
||||
self.cpu = None
|
||||
self.disks = []
|
||||
self.log_dir = None
|
||||
self.panes = {}
|
||||
self.tests = OrderedDict({
|
||||
'CPU & Cooling': {
|
||||
|
|
@ -131,6 +132,27 @@ class State():
|
|||
self.fix_tmux_layout(forced=False)
|
||||
std.sleep(1)
|
||||
|
||||
def init_diags(self):
|
||||
"""Initialize diagnostic pass."""
|
||||
# Reset objects
|
||||
self.disks.clear()
|
||||
for test_data in self.tests.values():
|
||||
test_data['Objects'].clear()
|
||||
|
||||
# Set log
|
||||
self.log_dir = log.format_log_path()
|
||||
self.log_dir = pathlib.Path(
|
||||
f'{self.log_dir.parent}/'
|
||||
f'Hardware-Diagnostics_{time.strftime("%Y-%m-%d_%H%M%z")}/'
|
||||
)
|
||||
log.update_log_path(
|
||||
dest_dir=self.log_dir,
|
||||
dest_name='main',
|
||||
keep_history=False,
|
||||
timestamp=False,
|
||||
)
|
||||
std.print_info('Starting Hardware Diagnostics')
|
||||
|
||||
def init_tmux(self):
|
||||
"""Initialize tmux layout."""
|
||||
tmux.kill_all_panes()
|
||||
|
|
@ -367,6 +389,10 @@ def network_test():
|
|||
std.pause('Press Enter to return to main menu...')
|
||||
|
||||
|
||||
def run_diags(state):
|
||||
"""Run selected diagnostics."""
|
||||
|
||||
|
||||
def screensaver(name):
|
||||
"""Show screensaver"""
|
||||
LOG.info('Screensaver (%s)', name)
|
||||
|
|
|
|||
|
|
@ -115,12 +115,14 @@ def start(config=None):
|
|||
atexit.register(logging.shutdown)
|
||||
|
||||
|
||||
def update_log_path(dest_dir=None, dest_name=None, timestamp=True):
|
||||
def update_log_path(
|
||||
dest_dir=None, dest_name=None, keep_history=True, timestamp=True):
|
||||
"""Moves current log file to new path and updates the root logger."""
|
||||
root_logger = logging.getLogger()
|
||||
cur_handler = None
|
||||
cur_path = get_root_logger_path()
|
||||
new_path = format_log_path(dest_dir, dest_name, timestamp=timestamp)
|
||||
os.makedirs(new_path.parent, exist_ok=True)
|
||||
|
||||
# Get current logging file handler
|
||||
for handler in root_logger.handlers:
|
||||
|
|
@ -131,10 +133,13 @@ def update_log_path(dest_dir=None, dest_name=None, timestamp=True):
|
|||
raise RuntimeError('Logging FileHandler not found')
|
||||
|
||||
# Copy original log to new location
|
||||
if new_path.exists():
|
||||
raise FileExistsError(f'Refusing to clobber: {new_path}')
|
||||
os.makedirs(new_path.parent, exist_ok=True)
|
||||
shutil.move(cur_path, new_path)
|
||||
if keep_history:
|
||||
if new_path.exists():
|
||||
raise FileExistsError(f'Refusing to clobber: {new_path}')
|
||||
shutil.move(cur_path, new_path)
|
||||
|
||||
# Remove old log if empty
|
||||
remove_empty_log()
|
||||
|
||||
# Create new cur_handler (preserving formatter settings)
|
||||
new_handler = logging.FileHandler(new_path, mode='a')
|
||||
|
|
|
|||
Loading…
Reference in a new issue