<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2016:
#   <NAME>, <EMAIL>
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp).  If not, see <http://www.gnu.org/licenses/>.

"""
    Application logs
"""

from logging import Formatter
from logging import DEBUG
from logging.handlers import TimedRotatingFileHandler
import os
import sys


def create_logger(logger):  # pragma: no cover
    """
    Create the logger for Alignak-App

    :param logger: the main logger.
    :type logger: :class:`~`
    """

    path = get_alignak_home() + '/alignak_app'

    filename = 'alignakapp.log'

    if not os.path.isdir(path):
        # noinspection PyBroadException
        try:  # pragma: no cover - not testable
            os.makedirs(path)
        except Exception:
            path = '.'

    if not os.access(path, os.W_OK):
        path = '.'

    formatter = Formatter('[%(asctime)s] - %(name)-12s - %(levelname)s - %(message)s')

    file_handler = TimedRotatingFileHandler(
        filename=os.path.join(path, filename),
        when="D",
        interval=1,
        backupCount=6
    )

    file_handler.setLevel(DEBUG)
    file_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.setLevel(DEBUG)


def get_alignak_home():  # pragma: no cover
    """
    Return user home.
    """

    # Get HOME and USER
    if 'linux' in sys.platform or 'sunos5' in sys.platform:
        alignak_home = os.environ['HOME']
        alignak_home += '/.local'
    elif 'win32' in sys.platform:
        alignak_home = os.environ['USERPROFILE']
        alignak_home += '\\AppData\\Roaming\\Python\\'
    else:
        sys.exit('Application can\'t find the user HOME.')

    # Prevent from root user
    if 'root' in alignak_home or not alignak_home:
        sys.exit('Application can\'t find the user HOME or maybe you are connected as ROOT.')

    alignak_home += '/.local'
    return alignak_home<commit_msg>Fix wrong path for alignak_home<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2015-2016:
#   <NAME>, <EMAIL>
#
# This file is part of (AlignakApp).
#
# (AlignakApp) is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# (AlignakApp) is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with (AlignakApp).  If not, see <http://www.gnu.org/licenses/>.

"""
    Application logs
"""

from logging import Formatter
from logging import DEBUG
from logging.handlers import TimedRotatingFileHandler
import os
import sys


def create_logger(logger):  # pragma: no cover
    """
    Create the logger for Alignak-App

    :param logger: the main logger.
    :type logger: :class:`~`
    """

    path = get_alignak_home() + '/alignak_app'

    filename = 'alignakapp.log'

    if not os.path.isdir(path):
        # noinspection PyBroadException
        try:  # pragma: no cover - not testable
            os.makedirs(path)
        except Exception:
            path = '.'

    if not os.access(path, os.W_OK):
        path = '.'

    formatter = Formatter('[%(asctime)s] - %(name)-12s - %(levelname)s - %(message)s')

    file_handler = TimedRotatingFileHandler(
        filename=os.path.join(path, filename),
        when="D",
        interval=1,
        backupCount=6
    )

    file_handler.setLevel(DEBUG)
    file_handler.setFormatter(formatter)

    logger.addHandler(file_handler)
    logger.setLevel(DEBUG)


def get_alignak_home():  # pragma: no cover
    """
    Return user home.
    """

    # Get HOME and USER
    if 'linux' in sys.platform or 'sunos5' in sys.platform:
        alignak_home = os.environ['HOME']
        alignak_home += '/.local'
    elif 'win32' in sys.platform:
        alignak_home = os.environ['USERPROFILE']
        alignak_home += '\\AppData\\Roaming\\Python\\'
    else:
        sys.exit('Application can\'t find the user HOME.')

    # Prevent from root user
    if 'root' in alignak_home or not alignak_home:
        sys.exit('Application can\'t find the user HOME or maybe you are connected as ROOT.')

    return alignak_home
{'fraction_non_alphanumeric': 0.1071849234393404, 'fraction_numerical': 0.006674519042010208, 'mean_word_length': 2.9252696456086285, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '616715', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1536, 'n_words': 517}