diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-25 18:00:12 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-27 19:33:28 +0200 |
commit | 9f95446a55533c8cdceec7c4430be5cad752ecb1 (patch) | |
tree | 4265c127ee9b2c5f1e038836ad2e7b92ea0cad80 /src/leap/bitmask/vpn/privilege.py | |
parent | 9a1548aa01996ce93febe0272f1f8e4dd5e130ff (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/privilege.py')
-rw-r--r-- | src/leap/bitmask/vpn/privilege.py | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/leap/bitmask/vpn/privilege.py b/src/leap/bitmask/vpn/privilege.py index 135acbb..9666a94 100644 --- a/src/leap/bitmask/vpn/privilege.py +++ b/src/leap/bitmask/vpn/privilege.py @@ -31,7 +31,7 @@ from abc import ABCMeta, abstractmethod from twisted.logger import Logger from twisted.python.procutils import which -logger = Logger() +log = Logger() flags_STANDALONE = False @@ -71,8 +71,8 @@ def is_missing_policy_permissions(): if not policy_checker: # it is true that we miss permission to escalate # privileges without asking for password each time. - logger.debug("we could not find a policy checker implementation " - "for %s" % (_system,)) + log.debug('we could not find a policy checker implementation ' + 'for %s' % (_system,)) return True return policy_checker().is_missing_policy_permissions() @@ -146,18 +146,15 @@ class LinuxPolicyChecker(PolicyChecker): time.sleep(2) if self.is_up(): pkexec_possibilities = which(self.PKEXEC_BIN) - # leap_assert(len(pkexec_possibilities) > 0, - # "We couldn't find pkexec") if not pkexec_possibilities: - logger.error("We couldn't find pkexec") raise Exception("We couldn't find pkexec") return pkexec_possibilities else: - logger.warn("No polkit auth agent found. pkexec " + - "will use its own auth agent.") + log.warn('No polkit auth agent found. pkexec ' + + 'will use its own auth agent.') raise NoPolkitAuthAgentAvailable() else: - logger.warn("System has no pkexec") + log.warn('System has no pkexec') raise NoPkexecAvailable() @classmethod @@ -178,11 +175,11 @@ class LinuxPolicyChecker(PolicyChecker): # will do "sh -c 'foo'", so if we do not quoute it we'll end # up with a invocation to the python interpreter. And that # is bad. - logger.debug("Trying to launch polkit agent") + log.debug('Trying to launch polkit agent') subprocess.call(["python -m leap.bitmask.util.polkit_agent"], shell=True, env=env) - except Exception as exc: - logger.error(str(exc)) + except Exception: + log.failure('Error while launching vpn') @classmethod def is_up(self): |