Skip to content

Commit

Permalink
overload log_path to accept tuple (path, mode)
Browse files Browse the repository at this point in the history
This change allows users to specify how they want
to open their log file with a fallback to `a+`
if nothing else is specified

Fixes SeleniumHQ#10703
  • Loading branch information
vringar committed Sep 29, 2022
1 parent 316f973 commit 0531e59
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions py/selenium/webdriver/firefox/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

from typing import List
from typing import List, Tuple

from selenium.webdriver.common import (service, utils)

Expand All @@ -28,7 +28,7 @@ class Service(service.Service):

def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
port: int = 0, service_args: List[str] = None,
log_path: str = "geckodriver.log", env: dict = None):
log_path: Union[str, Tuple[str, str]] = "geckodriver.log", env: dict = None):
"""Creates a new instance of the GeckoDriver remote service proxy.
GeckoDriver provides a HTTP interface speaking the W3C WebDriver
Expand All @@ -41,12 +41,14 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
:param service_args: Optional list of arguments to pass to the
GeckoDriver binary.
:param log_path: Optional path for the GeckoDriver to log to.
Defaults to _geckodriver.log_ in the current working directory.
Can also be called with (path_name, mode).
Defaults to _geckodriver.log_ in the current working directory and _a+_ respectively.
:param env: Optional dictionary of output variables to expose
in the services' environment.
"""
log_file = open(log_path, "a+", encoding='utf-8') if log_path else None

log_path, log_path_mode = (log_path[0], log_path[1]) if isinstance(log_path,Tuple) else (log_path, "a+")
log_file = open(log_path, log_path_mode, encoding='utf-8') if log_path else None

super().__init__(executable_path, port=port, log_file=log_file, env=env)
self.service_args = service_args or []
Expand Down

0 comments on commit 0531e59

Please sign in to comment.