From a61019a5d30502a06b3a0ef09ca32044b8d09e2b Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Mon, 26 Sep 2016 18:09:30 -0400 Subject: [feature] rotate logs --- src/leap/bitmask/core/bitmaskd.tac | 4 ++++ src/leap/bitmask/core/launcher.py | 8 +++++--- src/leap/bitmask/core/logs.py | 14 ++++++++++++++ src/leap/bitmask/core/service.py | 3 ++- 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/leap/bitmask/core/logs.py diff --git a/src/leap/bitmask/core/bitmaskd.tac b/src/leap/bitmask/core/bitmaskd.tac index 3c9b1d8b..eba25307 100644 --- a/src/leap/bitmask/core/bitmaskd.tac +++ b/src/leap/bitmask/core/bitmaskd.tac @@ -2,10 +2,14 @@ # Run as: twistd -n -y bitmaskd.tac # from twisted.application import service +from twisted.python.log import ILogObserver, FileLogObserver from leap.bitmask.core.service import BitmaskBackend +from leap.bitmask.core.logs import loggerFactory +logger = loggerFactory() bb = BitmaskBackend() application = service.Application("bitmaskd") +application.setComponent(ILogObserver, FileLogObserver(logger).emit) bb.setServiceParent(application) diff --git a/src/leap/bitmask/core/launcher.py b/src/leap/bitmask/core/launcher.py index b8916a1e..27e5a26d 100644 --- a/src/leap/bitmask/core/launcher.py +++ b/src/leap/bitmask/core/launcher.py @@ -17,7 +17,7 @@ """ Run bitmask daemon. """ -from os.path import join +from os.path import join, abspath from sys import argv from twisted.scripts.twistd import run @@ -25,6 +25,9 @@ from twisted.scripts.twistd import run from leap.bitmask.util import here from leap.bitmask import core from leap.bitmask.core import flags +from leap.common.config import get_path_prefix + +pid = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.pid')) def run_bitmaskd(): @@ -35,8 +38,7 @@ def run_bitmaskd(): flags.BACKEND = argv[index + 1] argv[1:] = [ '-y', join(here(core), "bitmaskd.tac"), - '--pidfile', '/tmp/bitmaskd.pid', - '--logfile', '/tmp/bitmaskd.log', + '--pidfile', pid, '--umask=0022', ] print '[+] launching bitmaskd...' diff --git a/src/leap/bitmask/core/logs.py b/src/leap/bitmask/core/logs.py new file mode 100644 index 00000000..2b42d610 --- /dev/null +++ b/src/leap/bitmask/core/logs.py @@ -0,0 +1,14 @@ +from os.path import abspath, join, isfile + +from twisted.python import logfile + +from leap.common.config import get_path_prefix + + +def loggerFactory(): + log_path = abspath(join(get_path_prefix(), 'leap', 'bitmaskd.log')) + rotate = isfile(log_path) + _logfile = logfile.LogFile.fromFullPath(log_path, maxRotatedFiles=5) + if rotate: + _logfile.rotate() + return _logfile diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py index a3eb94e7..bfcf0f2d 100644 --- a/src/leap/bitmask/core/service.py +++ b/src/leap/bitmask/core/service.py @@ -19,9 +19,10 @@ Bitmask-core Service. """ import json import resource +from os.path import join, abspath from twisted.internet import reactor -from twisted.python import log +from twisted.python import log, logfile from leap.bitmask import __version__ from leap.bitmask.core import configurable -- cgit v1.2.3