summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2016-09-26 18:09:30 -0400
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-26 18:09:30 -0400
commita61019a5d30502a06b3a0ef09ca32044b8d09e2b (patch)
treeaad1f84e8d539ab5b23609e71dcd17d529d6de87 /src
parent24e9d3bbc98232062a4233f7f5de4f00cc256242 (diff)
[feature] rotate logs
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/core/bitmaskd.tac4
-rw-r--r--src/leap/bitmask/core/launcher.py8
-rw-r--r--src/leap/bitmask/core/logs.py14
-rw-r--r--src/leap/bitmask/core/service.py3
4 files changed, 25 insertions, 4 deletions
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