Python logging.NullHandler() Examples

The following are 30 code examples for showing how to use logging.NullHandler(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module logging , or try the search function .

Example 1
Project: python-zhmcclient   Author: zhmcclient   File: utils.py    License: Apache License 2.0 6 votes vote down vote up
def setup_logger(log_comp, handler, level):
    """
    Setup the logger for the specified log component to add the specified
    handler (removing a possibly present NullHandler) and to set it to the
    specified log level. The handler is also set to the specified log level
    because the default level of a handler is 0 which causes it to process all
    levels.
    """

    name = LOGGER_NAMES[log_comp]
    logger = logging.getLogger(name)

    for h in logger.handlers:
        if isinstance(h, logging.NullHandler):
            logger.removeHandler(h)

    handler.setLevel(level)
    logger.addHandler(handler)
    logger.setLevel(level) 
Example 2
Project: stem   Author: torproject   File: log.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def test_is_tracing(self):
    logger = log.get_logger()
    original_handlers = logger.handlers
    logger.handlers = [log._NullHandler()]

    try:
      self.assertFalse(log.is_tracing())

      handler = logging.NullHandler()
      handler.setLevel(log.DEBUG)
      logger.addHandler(handler)

      self.assertFalse(log.is_tracing())

      handler = logging.NullHandler()
      handler.setLevel(log.TRACE)
      logger.addHandler(handler)

      self.assertTrue(log.is_tracing())
    finally:
      logger.handlers = original_handlers 
Example 3
Project: python-sdk   Author: optimizely   File: logger.py    License: Apache License 2.0 6 votes vote down vote up
def adapt_logger(logger):
    """
  Adapt our custom logger.BaseLogger object into a standard logging.Logger object.

  Adaptations are:
    - NoOpLogger turns into a logger with a single NullHandler.
    - SimpleLogger turns into a logger with a StreamHandler and level.

  Args:
    logger: Possibly a logger.BaseLogger, or a standard python logging.Logger.

  Returns: a standard python logging.Logger.

  """
    if isinstance(logger, logging.Logger):
        return logger

    # Use the standard python logger created by these classes.
    if isinstance(logger, (SimpleLogger, NoOpLogger)):
        return logger.logger

    # Otherwise, return whatever we were given because we can't adapt.
    return logger 
Example 4
Project: python-sdk   Author: optimizely   File: test_logger.py    License: Apache License 2.0 6 votes vote down vote up
def test_adapt_logger__noop(self):
        """Test that adapt_logger returns a standard python logger from a NoOpLogger."""
        noop_logger = _logger.NoOpLogger()
        standard_logger = _logger.adapt_logger(noop_logger)

        # adapt_logger knows about the loggers attached to this class.
        self.assertIs(noop_logger.logger, standard_logger)

        # Verify properties of the logger
        self.assertIsInstance(standard_logger, logging.Logger)
        self.assertEqual('optimizely.logger.NoOpLogger', standard_logger.name)
        self.assertEqual(logging.NOTSET, standard_logger.level)

        # Should have a single NullHandler (with a default formatter).
        self.assertEqual(1, len(standard_logger.handlers))
        handler = standard_logger.handlers[0]
        self.assertIsInstance(handler, logging.NullHandler)
        self.assertEqual(
            '%(levelname)-8s %(asctime)s %(filename)s:%(lineno)s:%(message)s', handler.formatter._fmt,
        ) 
Example 5
Project: ms_deisotope   Author: mobiusklein   File: process.py    License: Apache License 2.0 6 votes vote down vote up
def _silence_loggers(self):
        nologs = ["deconvolution_scan_processor"]
        if not self.deconvolute:
            nologs.append("deconvolution")

        debug_mode = os.getenv("MS_DEISOTOPE_DEBUG")
        if debug_mode:
            handler = logging.FileHandler("ms-deisotope-deconvolution-debug-%s.log" % (os.getpid()), 'w')
            fmt = logging.Formatter(
                "%(asctime)s - %(name)s:%(filename)s:%(lineno)-4d - %(levelname)s - %(message)s",
                "%H:%M:%S")
            handler.setFormatter(fmt)
        for logname in nologs:
            logger_to_silence = logging.getLogger(logname)
            if debug_mode:
                logger_to_silence.setLevel("DEBUG")
                logger_to_silence.addHandler(handler)
            else:
                logger_to_silence.propagate = False
                logger_to_silence.setLevel("CRITICAL")
                logger_to_silence.addHandler(logging.NullHandler()) 
Example 6
Project: teleport   Author: tp4a   File: log.py    License: Apache License 2.0 6 votes vote down vote up
def format_ldap_message(message, prefix):
    if isinstance(message, LDAPMessage):
        try:  # pyasn1 prettyprint raises exception in version 0.4.3
            formatted = message.prettyPrint().split('\n')  # pyasn1 pretty print
        except Exception as e:
            formatted = ['pyasn1 exception', str(e)]
    else:
        formatted = pformat(message).split('\n')

    prefixed = ''
    for line in formatted:
        if line:
            if _hide_sensitive_data and line.strip().lower().startswith(_sensitive_lines):  # _sensitive_lines is a tuple. startswith() method checks each tuple element
                tag, _, data = line.partition('=')
                if data.startswith("b'") and data.endswith("'") or data.startswith('b"') and data.endswith('"'):
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % (len(data) - 3, )
                else:
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % len(data)
            else:
                prefixed += '\n' + prefix + line
    return prefixed

# sets a logger for the library with NullHandler. It can be used by the application with its own logging configuration 
Example 7
Project: teleport   Author: tp4a   File: log.py    License: Apache License 2.0 6 votes vote down vote up
def format_ldap_message(message, prefix):
    if isinstance(message, LDAPMessage):
        try:  # pyasn1 prettyprint raises exception in version 0.4.3
            formatted = message.prettyPrint().split('\n')  # pyasn1 pretty print
        except Exception as e:
            formatted = ['pyasn1 exception', str(e)]
    else:
        formatted = pformat(message).split('\n')

    prefixed = ''
    for line in formatted:
        if line:
            if _hide_sensitive_data and line.strip().lower().startswith(_sensitive_lines):  # _sensitive_lines is a tuple. startswith() method checks each tuple element
                tag, _, data = line.partition('=')
                if data.startswith("b'") and data.endswith("'") or data.startswith('b"') and data.endswith('"'):
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % (len(data) - 3, )
                else:
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % len(data)
            else:
                prefixed += '\n' + prefix + line
    return prefixed

# sets a logger for the library with NullHandler. It can be used by the application with its own logging configuration 
Example 8
Project: teleport   Author: tp4a   File: log.py    License: Apache License 2.0 6 votes vote down vote up
def format_ldap_message(message, prefix):
    if isinstance(message, LDAPMessage):
        try:  # pyasn1 prettyprint raises exception in version 0.4.3
            formatted = message.prettyPrint().split('\n')  # pyasn1 pretty print
        except Exception as e:
            formatted = ['pyasn1 exception', str(e)]
    else:
        formatted = pformat(message).split('\n')

    prefixed = ''
    for line in formatted:
        if line:
            if _hide_sensitive_data and line.strip().lower().startswith(_sensitive_lines):  # _sensitive_lines is a tuple. startswith() method checks each tuple element
                tag, _, data = line.partition('=')
                if data.startswith("b'") and data.endswith("'") or data.startswith('b"') and data.endswith('"'):
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % (len(data) - 3, )
                else:
                    prefixed += '\n' + prefix + tag + '=<stripped %d characters of sensitive data>' % len(data)
            else:
                prefixed += '\n' + prefix + line
    return prefixed

# sets a logger for the library with NullHandler. It can be used by the application with its own logging configuration 
Example 9
Project: testinfra   Author: philpep   File: plugin.py    License: Apache License 2.0 6 votes vote down vote up
def pytest_configure(config):
    if config.option.verbose > 1:
        root = logging.getLogger()
        if not root.handlers:
            root.addHandler(logging.NullHandler())
        logging.getLogger("testinfra").setLevel(logging.DEBUG)
    if config.option.nagios:
        # disable & re-enable terminalreporter to write in a tempfile
        reporter = config.pluginmanager.getplugin('terminalreporter')
        if reporter:
            out = SpooledTemporaryFile(encoding=sys.stdout.encoding)
            config.pluginmanager.unregister(reporter)
            reporter = reporter.__class__(config, out)
            config.pluginmanager.register(reporter, 'terminalreporter')
            config.pluginmanager.register(NagiosReporter(out),
                                          'nagiosreporter') 
Example 10
Project: deepWordBug   Author: QData   File: ext_logging.py    License: Apache License 2.0 6 votes vote down vote up
def _setup_console_log(self):
        """Add a console log handler."""
        namespace = self._meta.namespace
        to_console = self.app.config.get(self._meta.config_section,
                                         'to_console')
        if is_true(to_console):
            console_handler = logging.StreamHandler()
            format = self._get_console_format()
            formatter = self._get_console_formatter(format)
            console_handler.setFormatter(formatter)
            console_handler.setLevel(getattr(logging, self.get_level()))
        else:
            console_handler = NullHandler()

        # FIXME: self._clear_loggers() should be preventing this but its not!
        for i in logging.getLogger("cement:app:%s" % namespace).handlers:
            if isinstance(i, logging.StreamHandler):
                self.backend.removeHandler(i)

        self.backend.addHandler(console_handler) 
Example 11
Project: addon-check   Author: xbmc   File: logger.py    License: GNU General Public License v3.0 6 votes vote down vote up
def create_logger(debug_filename, logger_name, enabled=False):
        """Creates a logger format for error logging
        :debug_filename: path and filename of the debug log
        :logger_name: name of the logger to create
        :enabled: enable to write the log to provided filename, otherwise uses a NullHandler
        """
        logger = logging.getLogger(logger_name)
        logger.setLevel(logging.DEBUG)
        logger.propagate = False
        formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s:%(name)s:%(funcName)s: %(message)s',
                                      datefmt='%Y-%m-%d %H:%M:%S')

        if enabled:
            # DEBUG log to 'kodi-addon-checker.log'
            debug_log_handler = logging.handlers.RotatingFileHandler(debug_filename, encoding='utf-8', mode="w")
            debug_log_handler.setLevel(logging.DEBUG)
            debug_log_handler.setFormatter(formatter)
            logger.addHandler(debug_log_handler)
        else:
            logger.addHandler(logging.NullHandler())

        return logger 
Example 12
Project: pykit   Author: bsc-s2   File: test_jobq.py    License: MIT License 6 votes vote down vote up
def test_exception(self):

        # Add a handler, or python complains "no handler assigned
        # to...."
        jl = logging.getLogger('pykit.jobq')
        jl.addHandler(logging.NullHandler())

        def err_on_even(args):
            if args % 2 == 0:
                raise Exception('even number')
            else:
                return args

        def collect(args):
            rst.append(args)

        rst = []
        jobq.run(range(10), [err_on_even, collect])
        self.assertEqual(list(range(1, 10, 2)), rst)

        # remove NullHandler
        jl.handlers = [] 
Example 13
Project: flask-restplus-server-example   Author: frol   File: __init__.py    License: MIT License 6 votes vote down vote up
def init_app(self, app):
        """
        Common Flask interface to initialize the logging according to the
        application configuration.
        """
        # We don't need the default Flask's loggers when using our invoke tasks
        # since we set up beautiful colorful loggers globally.
        for handler in list(app.logger.handlers):
            app.logger.removeHandler(handler)
        app.logger.propagate = True

        if app.debug:
            logging.getLogger('flask_oauthlib').setLevel(logging.DEBUG)
            app.logger.setLevel(logging.DEBUG)

        # We don't need the default SQLAlchemy loggers when using our invoke
        # tasks since we set up beautiful colorful loggers globally.
        # NOTE: This particular workaround is for the SQLALCHEMY_ECHO mode,
        # when all SQL commands get printed (without these lines, they will get
        # printed twice).
        sqla_logger = logging.getLogger('sqlalchemy.engine.base.Engine')
        for hdlr in list(sqla_logger.handlers):
            sqla_logger.removeHandler(hdlr)
        sqla_logger.addHandler(logging.NullHandler()) 
Example 14
Project: GuidedLDA   Author: vi3k6i5   File: guidedlda.py    License: Mozilla Public License 2.0 6 votes vote down vote up
def __init__(self, n_topics, n_iter=2000, alpha=0.01, eta=0.01, random_state=None,
                 refresh=10):
        self.n_topics = n_topics
        self.n_iter = n_iter
        self.alpha = alpha
        self.eta = eta
        # if random_state is None, check_random_state(None) does nothing
        # other than return the current numpy RandomState
        self.random_state = random_state
        self.refresh = refresh

        if alpha <= 0 or eta <= 0:
            raise ValueError("alpha and eta must be greater than zero")

        # random numbers that are reused
        rng = guidedlda.utils.check_random_state(random_state)
        if random_state:
            random.seed(random_state)
        self._rands = rng.rand(1024**2 // 8)  # 1MiB of random variates

        # configure console logging if not already configured
        if len(logger.handlers) == 1 and isinstance(logger.handlers[0], logging.NullHandler):
            logging.basicConfig(level=logging.INFO) 
Example 15
Project: py-kms   Author: SystemRage   File: Etrigan.py    License: The Unlicense 6 votes vote down vote up
def setup_files(self):
                self.pidfile = os.path.abspath(self.pidfile)
                
                if self.logfile is not None:                     
                        self.logdaemon = logging.getLogger('logdaemon')
                        self.logdaemon.setLevel(self.loglevel)
                        
                        filehandler = logging.FileHandler(self.logfile)
                        filehandler.setLevel(self.loglevel)
                        formatter = logging.Formatter(fmt = '[%(asctime)s] [%(levelname)8s] --- %(message)s',
                                                      datefmt = '%Y-%m-%d %H:%M:%S')
                        filehandler.setFormatter(formatter)
                        self.logdaemon.addHandler(filehandler)
                else:
                        nullhandler = logging.NullHandler()
                        self.logdaemon.addHandler(nullhandler) 
Example 16
Project: LaSO   Author: leokarlin   File: engine.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, process_function):
        self._event_handlers = defaultdict(list)
        self._logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
        self._logger.addHandler(logging.NullHandler())
        self._process_function = process_function
        self.should_terminate = False
        self.should_terminate_single_epoch = False
        self.state = None
        self._allowed_events = []

        self.register_events(*Events)

        if self._process_function is None:
            raise ValueError("Engine must be given a processing function in order to run.")

        self._check_signature(process_function, 'process_function', None) 
Example 17
Project: LaSO   Author: leokarlin   File: early_stopping.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, patience, score_function, trainer):

        if not callable(score_function):
            raise TypeError("Argument score_function should be a function.")

        if patience < 1:
            raise ValueError("Argument patience should be positive integer.")

        if not isinstance(trainer, Engine):
            raise TypeError("Argument trainer should be an instance of Engine.")

        self.score_function = score_function
        self.patience = patience
        self.trainer = trainer
        self.counter = 0
        self.best_score = None
        self._logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
        self._logger.addHandler(logging.NullHandler()) 
Example 18
Project: learn_python3_spider   Author: wistbean   File: log.py    License: MIT License 6 votes vote down vote up
def _get_handler(settings):
    """ Return a log handler object according to settings """
    filename = settings.get('LOG_FILE')
    if filename:
        encoding = settings.get('LOG_ENCODING')
        handler = logging.FileHandler(filename, encoding=encoding)
    elif settings.getbool('LOG_ENABLED'):
        handler = logging.StreamHandler()
    else:
        handler = logging.NullHandler()

    formatter = logging.Formatter(
        fmt=settings.get('LOG_FORMAT'),
        datefmt=settings.get('LOG_DATEFORMAT')
    )
    handler.setFormatter(formatter)
    handler.setLevel(settings.get('LOG_LEVEL'))
    if settings.getbool('LOG_SHORT_NAMES'):
        handler.addFilter(TopLevelFormatter(['scrapy']))
    return handler 
Example 19
Project: learn_python3_spider   Author: wistbean   File: log.py    License: MIT License 6 votes vote down vote up
def _get_handler(settings):
    """ Return a log handler object according to settings """
    filename = settings.get('LOG_FILE')
    if filename:
        encoding = settings.get('LOG_ENCODING')
        handler = logging.FileHandler(filename, encoding=encoding)
    elif settings.getbool('LOG_ENABLED'):
        handler = logging.StreamHandler()
    else:
        handler = logging.NullHandler()

    formatter = logging.Formatter(
        fmt=settings.get('LOG_FORMAT'),
        datefmt=settings.get('LOG_DATEFORMAT')
    )
    handler.setFormatter(formatter)
    handler.setLevel(settings.get('LOG_LEVEL'))
    if settings.getbool('LOG_SHORT_NAMES'):
        handler.addFilter(TopLevelFormatter(['scrapy']))
    return handler 
Example 20
Project: WazeRouteCalculator   Author: kovacsbalu   File: WazeRouteCalculator.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, start_address, end_address, region='EU', vehicle_type='', avoid_toll_roads=False, avoid_subscription_roads=False, avoid_ferries=False, log_lvl=None):
        self.log = logging.getLogger(__name__)
        self.log.addHandler(logging.NullHandler())
        if log_lvl:
            self.log.warning("log_lvl is deprecated please check example.py ")
        self.log.info("From: %s - to: %s", start_address, end_address)
        region = region.upper()
        if region == 'NA':  # North America
            region = 'US'
        self.region = region
        self.vehicle_type = ''
        if vehicle_type and vehicle_type in self.VEHICLE_TYPES:
            self.vehicle_type = vehicle_type.upper()
        self.route_options = ['AVOID_TRAILS']
        if avoid_toll_roads:
            self.route_options.append('AVOID_TOLL_ROADS')
        self.avoid_subscription_roads = avoid_subscription_roads
        if avoid_ferries:
            self.route_options.append('AVOID_FERRIES')
        if self.already_coords(start_address):  # See if we have coordinates or address to resolve
            self.start_coords = self.coords_string_parser(start_address)
        else:
            self.start_coords = self.address_to_coords(start_address)
        self.log.debug('Start coords: (%s, %s)', self.start_coords["lat"], self.start_coords["lon"])
        if self.already_coords(end_address):  # See if we have coordinates or address to resolve
            self.end_coords = self.coords_string_parser(end_address)
        else:
            self.end_coords = self.address_to_coords(end_address)
        self.log.debug('End coords: (%s, %s)', self.end_coords["lat"], self.end_coords["lon"]) 
Example 21
Project: vt-ida-plugin   Author: VirusTotal   File: plugin_loader.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, cfgfile):
    self.vt_cfgfile = cfgfile
    self.file_path = idaapi.get_input_file_path()
    self.file_name = idc.get_root_filename()

    logging.getLogger(__name__).addHandler(logging.NullHandler())

    if config.DEBUG:
      logging.basicConfig(
          stream=sys.stdout,
          level=logging.DEBUG,
          format='%(message)s'
          )
    else:
      logging.basicConfig(
          stream=sys.stdout,
          level=logging.INFO,
          format='%(message)s'
          )

    logging.info(
        '\n** VT Plugin for IDA Pro v%s (c) Google, 2020',
        VT_IDA_PLUGIN_VERSION
    )
    logging.info('** VirusTotal integration plugin for Hex-Ray\'s IDA Pro 7')

    logging.info('\n** Select an area in the Disassembly Window and right')
    logging.info('** click to search on VirusTotal. You can also select a')
    logging.info('** string in the Strings Window.\n') 
Example 22
Project: custodia   Author: latchset   File: test_secrets.py    License: GNU General Public License v3.0 5 votes vote down vote up
def setUpClass(cls):
        cls.parser = configparser.ConfigParser(
            interpolation=configparser.ExtendedInterpolation()
        )
        cls.parser.read_string(CONFIG)
        cls.log_handlers = log.auditlog.logger.handlers[:]
        log.auditlog.logger.handlers = [logging.NullHandler()]
        cls.secrets = Secrets(cls.parser, 'authz:secrets')
        cls.secrets.root.store = SqliteStore(cls.parser, 'store:sqlite')
        cls.authz = UserNameSpace(cls.parser, 'authz:user') 
Example 23
Project: python-zhmcclient   Author: zhmcclient   File: _logging.py    License: Apache License 2.0 5 votes vote down vote up
def get_logger(name):
    """
    Return a :class:`~py:logging.Logger` object with the specified name.

    A :class:`~py:logging.NullHandler` handler is added to the logger if it
    does not have any handlers yet and if it is not the Python root logger.
    This prevents the propagation of log requests up the Python logger
    hierarchy, and therefore causes this package to be silent by default.
    """
    logger = logging.getLogger(name)
    if name != '' and not logger.handlers:
        logger.addHandler(logging.NullHandler())
    return logger 
Example 24
Project: python-zhmcclient   Author: zhmcclient   File: utils.py    License: Apache License 2.0 5 votes vote down vote up
def reset_logger(log_comp):
    """
    Reset the logger for the specified log component (unless it is the root
    logger) to add a NullHandler if it does not have any handlers. Having a
    handler prevents a log request to be propagated to the parent logger.
    """

    name = LOGGER_NAMES[log_comp]
    logger = logging.getLogger(name)

    if name != '' and not logger.handlers:
        logger.addHandler(logging.NullHandler()) 
Example 25
Project: terraform-templates   Author: PaloAltoNetworks   File: __init__.py    License: Apache License 2.0 5 votes vote down vote up
def getlogger(name=__name__):
    import types
    logger_instance = logging.getLogger(name)
    # Add nullhandler to prevent exceptions in python 2.6
    logger_instance.addHandler(logging.NullHandler())
    # Add convenience methods for logging
    logger_instance.debug1 = types.MethodType(
        lambda inst, msg, *args, **kwargs: inst.log(DEBUG1, msg, *args, **kwargs), logger_instance)
    logger_instance.debug2 = types.MethodType(
        lambda inst, msg, *args, **kwargs: inst.log(DEBUG2, msg, *args, **kwargs), logger_instance)
    logger_instance.debug3 = types.MethodType(
        lambda inst, msg, *args, **kwargs: inst.log(DEBUG3, msg, *args, **kwargs), logger_instance)
    logger_instance.debug4 = types.MethodType(
        lambda inst, msg, *args, **kwargs: inst.log(DEBUG4, msg, *args, **kwargs), logger_instance)
    return logger_instance 
Example 26
def __init__(self, process_function):
        self._event_handlers = defaultdict(list)
        self._logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
        self._logger.addHandler(logging.NullHandler())
        self._process_function = process_function
        self.should_terminate = False
        self.state = None

        if self._process_function is None:
            raise ValueError("Engine must be given a processing function in order to run")

        self._check_signature(process_function, 'process_function', None) 
Example 27
def __init__(self, patience, score_function, trainer):
        assert callable(score_function), "Argument score_function should be a function"
        assert patience > 0, "Argument patience should be positive"
        assert isinstance(trainer, Engine), "Argument trainer should be an instance of Engine"
        self.score_function = score_function
        self.patience = patience
        self.trainer = trainer
        self.counter = 0
        self.best_score = None
        self._logger = logging.getLogger(__name__ + "." + self.__class__.__name__)
        self._logger.addHandler(logging.NullHandler()) 
Example 28
Project: IDEA   Author: armor-ai   File: onlineLDA.py    License: MIT License 5 votes vote down vote up
def __init__(self, n_topics, n_iter=2000, random_state=None,
                 refresh=10, window_size=1, theta=0.5):
        self.n_topics = n_topics
        self.n_iter = n_iter
        self.window_size = window_size
        # if random_state is None, check_random_state(None) does nothing
        # other than return the current numpy RandomState
        self.random_state = random_state
        self.refresh = refresh
        self.alpha_m = None
        self.eta_m = None
        self.eta_l = None
        self.alpha_sum = None
        self.eta_sum = None
        self.theta = theta
        self.alpha = 0.1
        self.B = []
        self.A = []
        self.loglikelihoods_pred = []
        self.loglikelihoods_train = []
        self.ll = -1
        # random numbers that are reused
        rng = self.check_random_state(random_state)
        self._rands = rng.rand(1024**2 // 8)  # 1MiB of random variates

        # configure console logging if not already configured
        if len(logger.handlers) == 1 and isinstance(logger.handlers[0], logging.NullHandler):
            logging.basicConfig(level=logging.INFO) 
Example 29
Project: telemetry   Author: jupyter   File: test_traits.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_good_handlers_value():
    handlers = [
        logging.NullHandler(),
        logging.NullHandler()
    ]
    obj = HasHandlers(
        handlers=handlers
    )
    assert obj.handlers == handlers 
Example 30
Project: telemetry   Author: jupyter   File: test_traits.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_mixed_handlers_values():
    handlers = [
        logging.NullHandler(),
        1
    ]
    with pytest.raises(TraitError):
        HasHandlers(
            handlers=handlers
        )