Exemplo n.º 1
0
def configure_logging():
    '''
      This function configures logging for the SILPA applications using Flask's
      internal logger.

      For now log file will be rotated 7 days once and 4 backups will be kept.
      This can't be modified using configuration file as of now.

      Default logging level will be ERROR and can be modified from
      configuration file. Log folder and file name can also be configured using
      configuration file but make sure the path  you give is writable for
      Webserver user, otherwise this will lead to an error.
    '''
    log_level = loadconfig.get('log_level')
    log_folder = loadconfig.get('log_folder')
    log_name = loadconfig.get('log_name')
    filename = os.path.join(log_folder, log_name)

    handler = handlers.TimedRotatingFileHandler(filename,
                                                when='D',
                                                interval=7,
                                                backupCount=4)

    level = logging.ERROR

    if log_level == "debug":
        level = logging.DEBUG
    elif log_level == "info":
        level = logging.INFO
    elif log_level == "warn":
        level = logging.WARNING
    elif log_level == "error":
        level = logging.ERROR

    handler.setLevel(level)
    handler.setFormatter(
        Formatter('%(asctime)s %(levelname)s: %(message)s \
                                   [in %(pathname)s %(lineno)d]'))

    app.logger.setLevel(level)
    app.logger.addHandler(handler)
Exemplo n.º 2
0
def configure_logging():
    '''
      This function configures logging for the SILPA applications using Flask's
      internal logger.

      For now log file will be rotated 7 days once and 4 backups will be kept.
      This can't be modified using configuration file as of now.

      Default logging level will be ERROR and can be modified from
      configuration file. Log folder and file name can also be configured using
      configuration file but make sure the path  you give is writable for
      Webserver user, otherwise this will lead to an error.
    '''
    log_level = loadconfig.get('log_level')
    log_folder = loadconfig.get('log_folder')
    log_name = loadconfig.get('log_name')
    filename = os.path.join(log_folder, log_name)

    handler = handlers.TimedRotatingFileHandler(filename, when='D',
                                                interval=7, backupCount=4)

    level = logging.ERROR

    if log_level == "debug":
        level = logging.DEBUG
    elif log_level == "info":
        level = logging.INFO
    elif log_level == "warn":
        level = logging.WARNING
    elif log_level == "error":
        level = logging.ERROR

    handler.setLevel(level)
    handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s \
                                   [in %(pathname)s %(lineno)d]'))

    app.logger.setLevel(level)
    app.logger.addHandler(handler)
Exemplo n.º 3
0
'''
  Purpose of this file is to hold variables which is used
  across the application so that these variables don't get
  initialized multiple times
'''

_all_ = ['MODULES', 'modules', 'modulenames', 'enabled_modules', \
        'load_modules', 'BASEURL']

import loadconfig
import sys


MODULES = {}
BASEURL = loadconfig.get('baseurl')

modules = loadconfig.get('modules')
modulenames = loadconfig.get('modules_display')

enabled_modules = [modulenames[x] for x in modules.keys() \
        if modules[x] == "yes"]


def load_modules():
    '''
      Load the modules enabled in the configuration file
      by user. This function initializes global variable
      MODULES which is a dictionary having module name as
      key and module itself as value. Which can be used later
      to process requests coming for the modules.
    '''
Exemplo n.º 4
0
'''
  Purpose of this file is to hold variables which is used
  across the application so that these variables don't get
  initialized multiple times
'''

_all_ = ['MODULES', 'modules', 'modulenames', 'enabled_modules', \
        'load_modules', 'BASEURL']

import loadconfig
import sys

MODULES = {}
BASEURL = loadconfig.get('baseurl')

modules = loadconfig.get('modules')
modulenames = loadconfig.get('modules_display')

enabled_modules = [modulenames[x] for x in modules.keys() \
        if modules[x] == "yes"]


def load_modules():
    '''
      Load the modules enabled in the configuration file
      by user. This function initializes global variable
      MODULES which is a dictionary having module name as
      key and module itself as value. Which can be used later
      to process requests coming for the modules.
    '''
Exemplo n.º 5
0
"""
  Purpose of this file is to hold variables which is used
  across the application so that these variables don't get
  initialized multiple times
"""

_all_ = ["MODULES", "modules", "modulenames", "enabled_modules", "load_modules", "BASEURL"]

import loadconfig
import sys


MODULES = {}
BASEURL = loadconfig.get("baseurl")

modules = loadconfig.get("modules")
modulenames = loadconfig.get("modules_display")

enabled_modules = [modulenames[x] for x in modules.keys() if modules[x] == "yes"]


def load_modules():
    """
      Load the modules enabled in the configuration file
      by user. This function initializes global variable
      MODULES which is a dictionary having module name as
      key and module itself as value. Which can be used later
      to process requests coming for the modules.
    """

    # Already initialized the modules then don't do it again