From c8eba064959310e44bdc2a4f0df49a534e761d04 Mon Sep 17 00:00:00 2001 From: drebs Date: Thu, 13 Oct 2016 12:08:46 -0300 Subject: [bug] use twisted.logger and fix logging namespace --- src/leap/bitmask/core/bitmaskd.tac | 15 ++++++++++----- src/leap/bitmask/core/launcher.py | 6 ++++-- src/leap/bitmask/core/logs.py | 9 +++++++-- src/leap/bitmask/mail/imap/account.py | 3 +-- src/leap/bitmask/mail/incoming/service.py | 2 +- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/leap/bitmask/core/bitmaskd.tac b/src/leap/bitmask/core/bitmaskd.tac index eba2530..ac7e138 100644 --- a/src/leap/bitmask/core/bitmaskd.tac +++ b/src/leap/bitmask/core/bitmaskd.tac @@ -2,14 +2,19 @@ # Run as: twistd -n -y bitmaskd.tac # from twisted.application import service -from twisted.python.log import ILogObserver, FileLogObserver +from twisted.logger import ILogObserver +from twisted.logger import FileLogObserver +from twisted.logger import formatEventAsClassicLogText as formatEvent from leap.bitmask.core.service import BitmaskBackend -from leap.bitmask.core.logs import loggerFactory - -logger = loggerFactory() +from leap.bitmask.core.logs import logFileFactory bb = BitmaskBackend() application = service.Application("bitmaskd") -application.setComponent(ILogObserver, FileLogObserver(logger).emit) + +# configure logging +log_file = logFileFactory() +observer = FileLogObserver(log_file, formatEvent) +application.setComponent(ILogObserver, observer) + bb.setServiceParent(application) diff --git a/src/leap/bitmask/core/launcher.py b/src/leap/bitmask/core/launcher.py index 45acde2..cbe4064 100644 --- a/src/leap/bitmask/core/launcher.py +++ b/src/leap/bitmask/core/launcher.py @@ -24,6 +24,7 @@ from twisted.scripts.twistd import run from leap.bitmask import core from leap.bitmask.core import flags +from leap.bitmask.core.logs import getLogPath from leap.common.config import get_path_prefix pid = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.pid')) @@ -48,11 +49,12 @@ def run_bitmaskd(): # from the bitmask_cli for (index, arg) in enumerate(sys.argv): if arg == '--backend': - flags.BACKEND = argv[index + 1] + flags.BACKEND = sys.argv[index + 1] sys.argv[1:] = [ '-y', join(here(core), "bitmaskd.tac"), '--pidfile', pid, - '--umask=0022', + '--umask', '0022', + '--logfile', getLogPath(), ] print '[+] launching bitmaskd...' run() diff --git a/src/leap/bitmask/core/logs.py b/src/leap/bitmask/core/logs.py index 1418fd5..3258e57 100644 --- a/src/leap/bitmask/core/logs.py +++ b/src/leap/bitmask/core/logs.py @@ -6,11 +6,16 @@ from twisted.python import logfile from leap.common.config import get_path_prefix -def loggerFactory(): +def getLogPath(): configdir = abspath(join(get_path_prefix(), 'leap')) if not isdir(configdir): makedirs(configdir) - log_path = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.log')) + log_path = join(configdir, 'bitmaskd.log') + return log_path + + +def logFileFactory(): + log_path = getLogPath() rotate = isfile(log_path) _logfile = logfile.LogFile.fromFullPath(log_path, maxRotatedFiles=5) if rotate: diff --git a/src/leap/bitmask/mail/imap/account.py b/src/leap/bitmask/mail/imap/account.py index 8ee0cbf..63d214e 100644 --- a/src/leap/bitmask/mail/imap/account.py +++ b/src/leap/bitmask/mail/imap/account.py @@ -24,7 +24,6 @@ from functools import partial from twisted.internet import defer from twisted.logger import Logger from twisted.mail import imap4 -from twisted.logger import Logger from zope.interface import implements from leap.common.check import leap_assert, leap_assert_type @@ -40,7 +39,7 @@ PROFILE_CMD = os.environ.get('LEAP_PROFILE_IMAPCMD', False) if PROFILE_CMD: def _debugProfiling(result, cmdname, start): took = (time.time() - start) * 1000 - log.msg("CMD " + cmdname + " TOOK: " + str(took) + " msec") + logger.debug("CMD " + cmdname + " TOOK: " + str(took) + " msec") return result diff --git a/src/leap/bitmask/mail/incoming/service.py b/src/leap/bitmask/mail/incoming/service.py index ddbdd2a..38a2290 100644 --- a/src/leap/bitmask/mail/incoming/service.py +++ b/src/leap/bitmask/mail/incoming/service.py @@ -49,7 +49,7 @@ from leap.soledad.common.crypto import ENC_SCHEME_KEY, ENC_JSON_KEY from leap.soledad.common.errors import InvalidAuthTokenError -logger = Logger(__name__) +logger = Logger() MULTIPART_ENCRYPTED = "multipart/encrypted" MULTIPART_SIGNED = "multipart/signed" -- cgit v1.2.3