Skip to content

Commit

Permalink
Centralize all output handling into the output function
Browse files Browse the repository at this point in the history
To simplify the logging in general let's completely drop any log_file
functionality and simply require a single standard output_function
for all purposes. If users would like to stream the data or log it
into a file, they will provide a log function as an output_function
that implements this similarly to the way Avocado VT did. In this
way there also won't be confusion of whether to use a log file or
a function or both and there will only be one uniform approach to
session logging.

Signed-off-by: Plamen Dimitrov <plamen.dimitrov@intra2net.com>
  • Loading branch information
pevogam committed Dec 11, 2023
1 parent 6819552 commit c778d01
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 19 deletions.
18 changes: 0 additions & 18 deletions aexpect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False,
locale.getpreferredencoding())
"""
self.a_id = a_id or data_factory.generate_random_string(8)
self.log_file = None
self.log_file_fd = None
self.closed = False
if encoding is None:
self.encoding = locale.getpreferredencoding()
Expand Down Expand Up @@ -527,7 +525,6 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False,
# Add a reader and a close hook
self._add_reader("tail")
self._add_close_hook(Tail._join_thread)
self._add_close_hook(Tail._close_log_file)

# Init the superclass
super().__init__(command, a_id, auto_close, echo, linesep,
Expand Down Expand Up @@ -610,21 +607,6 @@ def set_output_prefix(self, output_prefix):
"""
self.output_prefix = output_prefix

def set_log_file(self, filepath, open_fd=False):
"""
Set a log file name for this tail instance.
:param filepath: complete file name and path of the log.
:param open_fd: whether to also open the log file
"""
self.log_file = filepath
if open_fd:
self.log_file_fd = open(filepath, encoding="utf-8") # pylint: disable=R1732

def _close_log_file(self):
if self.log_file_fd is not None:
self.log_file_fd.close()

def _tail(self): # speed optimization pylint: disable=too-many-branches,too-many-statements

def _print_line(text):
Expand Down
1 change: 0 additions & 1 deletion aexpect/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,6 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n",
prompt=prompt, status_test_command=status_test_command,
client=client, host=host, port=port,
username=username, password=password)
session.set_log_file(log_filename)
try:
handle_prompts(session, username, password, prompt, timeout)
except Exception:
Expand Down

0 comments on commit c778d01

Please sign in to comment.