Skip to content

Commit b748e8e

Browse files
nicolasunravelAutomatedTester
authored andcommitted
configurable log file
Signed-off-by: AutomatedTester <david.burns@theautomatedtester.co.uk>
1 parent 9840668 commit b748e8e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

browsermobproxy/server.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,34 @@ def __init__(self, path='browsermob-proxy', options=None):
8989
self.command = []
9090
self.command += [path, '--port=%s' % self.port]
9191

92-
def start(self):
92+
def start(self, options=None):
9393
"""
9494
This will start the browsermob proxy and then wait until it can
9595
interact with it
96+
:param options: Dictionary that can hold the path and filename
97+
of the log file with resp. keys of `log_path` and `log_file`
9698
"""
97-
self.log_file = open(os.path.abspath('server.log'), 'w')
99+
if options is None:
100+
options = {
101+
'log_path': os.getcwd(),
102+
'log_file': 'server.log',
103+
}
104+
log_path = options.get('log_path')
105+
log_file = options.get('log_file')
106+
log_path_name = os.path.join(log_path, os.path.sep, log_file)
107+
self.log_file = open(log_path_name, 'w')
108+
98109
self.process = subprocess.Popen(self.command,
99110
stdout=self.log_file,
100111
stderr=subprocess.STDOUT)
101112
count = 0
102113
while not self._is_listening():
103114
if self.process.poll():
104-
message = ("The Browsermob-Proxy server process failed to start. Check server.log "
105-
"for a helpful error message.")
115+
message = (
116+
"The Browsermob-Proxy server process failed to start. "
117+
"Check {0}"
118+
"for a helpful error message.".format(self.log_file))
119+
106120
raise Exception(message)
107121
time.sleep(0.5)
108122
count += 1

0 commit comments

Comments
 (0)