summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core/logs.py
blob: 3258e575f61bdc3fd79d06a8523779eff568f35c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from os import makedirs
from os.path import abspath, join, isfile, isdir

from twisted.python import logfile

from leap.common.config import get_path_prefix


def getLogPath():
    configdir = abspath(join(get_path_prefix(), 'leap'))
    if not isdir(configdir):
        makedirs(configdir)
    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:
        _logfile.rotate()
    return _logfile