Skip to content

Commit

Permalink
Use LoggingManager earlier in cli client
Browse files Browse the repository at this point in the history
This is to allow more of the init code to use the
logger. Adds logs to the DataRootManager tar
unpacker to report when errors occur.

Resolves: #739
  • Loading branch information
dosaboy committed Oct 6, 2023
1 parent 7fd2a5c commit 8e6f4dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
68 changes: 34 additions & 34 deletions hotsos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,45 +257,38 @@ def cli(data_root, version, defs_path, templates_path, all_logs, debug,
host.
""" # noqa

minimal_mode = None
if short:
minimal_mode = 'short'
elif very_short:
minimal_mode = 'very-short'

HotSOSConfig.force_mode = force
repo_info = get_repo_info()
if repo_info:
HotSOSConfig.repo_info = repo_info

_version = get_version()
HotSOSConfig.hotsos_version = _version
HotSOSConfig.command_timeout = command_timeout

if version:
print(_version)
return

with DataRootManager(data_root, sos_unpack_dir=sos_unpack_dir) as drm:
if is_snap() and drm.data_root == '/':
print(SNAP_ERROR_MSG)
sys.exit(1)

HotSOSConfig.set(use_all_logs=all_logs, plugin_yaml_defs=defs_path,
templates_path=templates_path,
data_root=drm.data_root,
event_tally_granularity=event_tally_granularity,
max_logrotate_depth=max_logrotate_depth,
max_parallel_tasks=max_parallel_tasks,
machine_readable=machine_readable)

if debug and quiet:
sys.stderr.write('ERROR: cannot use both --debug and '
'--quiet\n')
return

HotSOSConfig.debug_mode = debug
with LoggingManager() as logmanager:
config = {'repo_info': get_repo_info(),
'force_mode': force,
'hotsos_version': _version,
'command_timeout': command_timeout,
'use_all_logs': all_logs,
'plugin_yaml_defs': defs_path,
'templates_path': templates_path,
'event_tally_granularity': event_tally_granularity,
'max_logrotate_depth': max_logrotate_depth,
'max_parallel_tasks': max_parallel_tasks,
'machine_readable': machine_readable,
'debug_mode': debug}
HotSOSConfig.set(**config)

with LoggingManager() as logmanager:
with DataRootManager(data_root,
sos_unpack_dir=sos_unpack_dir) as drm:
HotSOSConfig.data_root = drm.data_root
if is_snap() and drm.data_root == '/':
print(SNAP_ERROR_MSG)
sys.exit(1)

if debug and quiet:
sys.stderr.write('ERROR: cannot use both --debug and '
'--quiet\n')
return

# Set a name so that logs have this until real plugins are run.
log.name = 'hotsos.cli'

Expand Down Expand Up @@ -345,6 +338,13 @@ def cli(data_root, version, defs_path, templates_path, all_logs, debug,
output_path=output_path)
sys.stdout.write("INFO: output saved to {}\n".format(path))
else:
if short:
minimal_mode = 'short'
elif very_short:
minimal_mode = 'very-short'
else:
minimal_mode = None

out = summary.get(fmt=output_format,
html_escape=html_escape,
minimal_mode=minimal_mode)
Expand Down
3 changes: 3 additions & 0 deletions hotsos/core/root_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from hotsos.core.config import HotSOSConfig
from hotsos.core.host_helpers import CLIHelper
from hotsos.core.log import log


class DataRootManager(object):
Expand Down Expand Up @@ -75,6 +76,8 @@ def data_root(self):
try:
tar.extractall(self.tmpdir)
except Exception:
log.exception("error occured while unpacking "
"sosreport:")
# some members might fail to extract e.g. permission
# denied but we dont want that to cause the whole run
# to fail so we just log a message and ignore them.
Expand Down

0 comments on commit 8e6f4dc

Please sign in to comment.