summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/process.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-04-25 18:00:12 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-04-27 19:33:28 +0200
commit9f95446a55533c8cdceec7c4430be5cad752ecb1 (patch)
tree4265c127ee9b2c5f1e038836ad2e7b92ea0cad80 /src/leap/bitmask/vpn/process.py
parent9a1548aa01996ce93febe0272f1f8e4dd5e130ff (diff)
[bug] unify logging style using class attr
I changed most of the logger statements to use a class attribute, in this way it's easier to identify which class it's logging them. in some cases I leave a module-level logger, when we're either using functions or when the module it's too small. at the same time I did a general review and cleanup of the logging statements.
Diffstat (limited to 'src/leap/bitmask/vpn/process.py')
-rw-r--r--src/leap/bitmask/vpn/process.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index 6096a47..e136e5b 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -32,20 +32,21 @@ from leap.bitmask.vpn.utils import get_vpn_launcher
from leap.bitmask.vpn import _status
from leap.bitmask.vpn import _management
-logger = Logger()
-
# OpenVPN verbosity level - from flags.py
OPENVPN_VERBOSITY = 1
class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
+
"""
A ProcessProtocol class that can be used to spawn a process that will
launch openvpn and connect to its management interface to control it
programmatically.
"""
+ log = Logger()
+
# TODO do we really need the vpnconfig/providerconfig objects in here???
def __init__(self, vpnconfig, providerconfig, socket_host, socket_port,
@@ -123,7 +124,7 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
line = data[:-1]
if 'SIGTERM[soft,ping-restart]' in line:
self.restarting = True
- logger.info(line)
+ self.log.info(line)
self._status.watch(line)
def processExited(self, failure):
@@ -140,9 +141,9 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
elif err == internet_error.ProcessTerminated:
status, errmsg = 'failure', failure.value.exitCode
if errmsg:
- logger.debug("processExited, status %d" % (errmsg,))
+ self.log.debug('processExited, status %d' % (errmsg,))
else:
- logger.warn('%r' % failure.value)
+ self.log.warn('%r' % failure.value)
self._status.set_status(status, errmsg)
self._alive = False
@@ -156,9 +157,9 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
"""
exit_code = reason.value.exitCode
if isinstance(exit_code, int):
- logger.debug("processEnded, status %d" % (exit_code,))
+ self.log.debug('processEnded, status %d' % (exit_code,))
if self.restarting:
- logger.debug('Restarting VPN process')
+ self.log.debug('Restarting VPN process')
reactor.callLater(2, self._restartfun)
# polling
@@ -202,8 +203,8 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
if not isinstance(c, str):
command[i] = c.encode(encoding)
- logger.debug("Running VPN with command: ")
- logger.debug("{0}".format(" ".join(command)))
+ self.log.debug("Running VPN with command: ")
+ self.log.debug("{0}".format(" ".join(command)))
return command
def getGateways(self):
@@ -227,4 +228,4 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
try:
self.transport.signalProcess('KILL')
except internet_error.ProcessExitedAlready:
- logger.debug('Process Exited Already')
+ self.log.debug('Process Exited Already')