Ejemplo n.º 1
0
 def _populate_parser(self, parser):
     default = bxiparserconf.getdefaultvalue(
         parser,
         ['My Section'],
         'variable',
         bxilog.getLogger('config'),
         'Default_Value',
         None,
     )
     parser.add_argument(
         '--variable',
         default=default,
         envvar='VAR',
         help="Do something with variable. Current: %(default)s.")
     default = bxiparserconf.getdefaultvalue(
         parser,
         ['My Section'],
         'stuff',
         bxilog.getLogger('config'),
         'Default_stuff',
         None,
     )
     parser.add_argument(
         '--stuff',
         default=default,
         help="Do something with stuff. Current: %(default)s.")
Ejemplo n.º 2
0
    def test_config_file(self):
        """Test logging with configuration items"""

        orig_size = os.stat(FILENAME).st_size if os.path.exists(
            FILENAME) else 0

        conf = {
            'handlers': ['out', 'null'],
            'setsighandler': True,
            'out': {
                'module': 'bxi.base.log.file_handler',
                'filters': ':output,foo:debug,foo.bar:trace',
                'path': FILENAME,
                'append': True
            },
            'null': {
                'module': 'bxi.base.log.null_handler',
                'filters': ':off,foo:fine,foo.bar:debug',
            },
        }
        bxilog.set_config(configobj.ConfigObj(conf))
        # It is required to initialize the library for the configuration to be used
        bxilog.init()

        foo = bxilog.getLogger('foo')
        self.assertEqual(foo.level, bxilog.FINE)
        bar = bxilog.getLogger('foo.bar')
        self.assertEqual(bar.level, bxilog.TRACE)
        any = bxilog.getLogger('bebopalula')
        self.assertEqual(any.level, bxilog.OUTPUT)

        any.info('This message must not appear in file %s', FILENAME)
        bxilog.flush()
        newsize = os.stat(FILENAME).st_size
        self.assertEquals(newsize, orig_size)
        bar.lowest('This message must also not appear in file %s', FILENAME)
        bxilog.flush()
        newsize = os.stat(FILENAME).st_size
        self.assertEquals(newsize, orig_size)
        foo.fine('This message must not appear in file %s', FILENAME)
        bxilog.flush()
        newsize = os.stat(FILENAME).st_size
        self.assertEquals(newsize, orig_size)

        self._check_log_produced(FILENAME, any.output,
                                 'This message must appear in file %s',
                                 FILENAME)
        self._check_log_produced(FILENAME, bar.trace,
                                 'This message must also appear in file %s',
                                 FILENAME)
        self._check_log_produced(FILENAME, foo.debug,
                                 'This message must also appear in file %s',
                                 FILENAME)
        self._check_log_produced(FILENAME, bxilog.output,
                                 "This message must also appear in file %s",
                                 FILENAME)
Ejemplo n.º 3
0
    def test_basic_log(self):
        """Test normal logging"""
        def _produce_logs(logger, level):
            self._check_log_produced(FILENAME, getattr(logger, level),
                                     "Some stuff with noarg")
            self._check_log_produced(FILENAME, getattr(logger, level),
                                     "Some stuff with args: %d %f %s", 2, 3.14,
                                     'a string')
            self._check_log_produced(
                FILENAME, getattr(logger, level),
                "Some stuff with no args but special characters: %d %f %s")

        logger1 = bxilog.getLogger("foo")
        for level in bxilog.LEVEL_NAMES:
            _produce_logs(logger1, level)

        logger2 = bxilog.getLogger("bar")
        for level in bxilog.LEVEL_NAMES:
            _produce_logs(logger2, level)

        logger3 = bxilog.getLogger("foo.bar")
        for level in bxilog.LEVEL_NAMES:
            _produce_logs(logger3, level)

        self._check_log_produced(
            FILENAME,
            logger1.exception,
            "When no exception was raised - inner message: '%s'",
            "Who care?",
            level=bxilog.ERROR)

        self._check_log_produced(
            FILENAME,
            logger1.exception,
            "When no exception was raised - special char but no args: '%s'",
            level=bxilog.ERROR)

        try:
            raise ValueError("Exception raised: inner message: '%s'" %
                             "And so what?")
        except ValueError as ve:
            self._check_log_produced(FILENAME,
                                     logger1.exception,
                                     "Exception catched: inner message: '%s'",
                                     "Kilroy was here",
                                     level=bxilog.ERROR)

        try:
            raise ValueError("Exception raised: inner message: '%s'" %
                             "And so what again?")
        except ValueError as ve:
            self._check_log_produced(
                FILENAME,
                logger1.exception,
                "Exception catched - special char but no args: '%s'",
                level=bxilog.CRITICAL)
Ejemplo n.º 4
0
 def display(self, level):
     """
     Display the errors at the provided level
     """
     for issue in self.errors[int(level)]:
         logger = bxilog.getLogger('bxi.report.%s' % self.logger_prefix)
         logger.log(level, "%s\t%s\t%s", issue.name, issue.msg,
                    issue.details)
Ejemplo n.º 5
0
 def test_error_log(self):
     """Test error while logging"""
     logger = bxilog.getLogger("foo")
     self.assertRaises(TypeError, logger.output,
                       "Testing not enough args: %d %d %s", 1)
     self.assertRaises(TypeError, logger.output,
                       "Testing too many args: %d %d %s", 1, 2, 3, 'toto',
                       'tata')
     self.assertRaises(TypeError, logger.output,
                       "Testing wrong types: %d %d %s", 'foo', 2.5, 3,
                       'toto')
Ejemplo n.º 6
0
           This is not Free or Open Source software.\n
           Please contact Bull SAS for details about its license.\n
           Bull - Rue Jean Jaurès - B.P. 68 - 78340 Les Clayes-sous-Bois
@namespace bxi.base.summary Python BXI Issues Summary

This module provides a summary of multiple issues.
The summary is made by dispatching issues on different loggers
and ordering those issues.
"""

import bxi.base.log as bxilog
import bxi.base.parserconf as bxiparserconf

DEFAULT_BXI_REPORT_ORDER = 'BXI_REPORT_ORDER'

_LOGGER = bxilog.getLogger(bxilog.LIB_PREFIX + 'bxibasesummary')


def addargs(parser, config=None):
    """
    Configure the arg parser with summary options.

    @param parser of the command line

    @return
    """

    default_value = bxiparserconf.getdefaultvalue(parser, ['Defaults'],
                                                  'reporting_order', _LOGGER,
                                                  'level', config)
Ejemplo n.º 7
0
@namespace bxi.base Python BXI Base module

"""
from __future__ import print_function
import re
import math
import sys
from pkgutil import extend_path
import bxi.base.log as bxilog

# Try to find other BXI packages in other folders
__path__ = extend_path(__path__, __name__)

from bxi.util.cffi_h import ffi

_LOGGER = bxilog.getLogger(bxilog.LIB_PREFIX + 'bxiutil')

__FFI__ = ffi
__CAPI__ = __FFI__.dlopen('libbxiutil.so')

# Used by smartdisplay
FILL_EMPTY_ENTRY = u'!#$_'
TRUNCATION_REF = u"..{%s}"
TRUNCATION_MAX_SIZE = len(TRUNCATION_REF)
REMOVE_UNSPECIFIED_COLUMNS = -1

# Use by replace_if_none
NONE_VALUE = unicode(None)


def get_ffi():
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
"""
@file err.py Defines all Python signal handling for all BXI modules
@authors Sébastien Miquée <*****@*****.**>
@copyright 2014  Bull S.A.S.  -  All rights reserved.\n
           This is not Free or Open Source software.\n
           Please contact Bull SAS for details about its license.\n
           Bull - Rue Jean Jaurès - B.P. 68 - 78340 Les Clayes-sous-Bois
@namespace bxi.base.sign Python BXI Signal handling

Signal handling"""

import signal
import bxi.base.log as bxilog

_LOGGER = bxilog.getLogger(bxilog.LIB_PREFIX + 'bxilog.signals')

SIGNALS = [
    'None',
    'SIGHUP',
    'SIGINT',
    'SIGQUIT',
    'SIGILL',
    'SIGTRAP',
    'SIGABRT',
    'SIGBUS',
    'SIGFPE',
    'SIGKILL',
    'SIGUSR1',
    'SIGSEGV',
    'SIGUSR2',