# _________________________________________________________________________ # # Pyomo: Python Optimization Modeling Objects # Copyright (c) 2014 Sandia Corporation. # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, # the U.S. Government retains certain rights in this software. # This software is distributed under the BSD License. # _________________________________________________________________________ import logging from os.path import abspath, dirname, join, normpath pyomo_base = normpath(join(dirname(abspath(__file__)), '..', '..', '..')) from pyutilib.misc import LogHandler logger = logging.getLogger('pyomo.core') logger.setLevel( logging.WARNING ) logger.addHandler( LogHandler(pyomo_base, verbosity=lambda: logger.isEnabledFor(logging.DEBUG)) )
# Pyomo: Python Optimization Modeling Objects # Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC # Under the terms of Contract DE-NA0003525 with National Technology and # Engineering Solutions of Sandia, LLC, the U.S. Government retains certain # rights in this software. # This software is distributed under the 3-clause BSD License. # ___________________________________________________________________________ import logging from pyutilib.misc import LogHandler from os.path import abspath, dirname pyomo_base = dirname(dirname(dirname(dirname(dirname(abspath(__file__)))))) logger = logging.getLogger('pyomo.opt') logger.addHandler(LogHandler(pyomo_base)) logger.setLevel(logging.WARNING) class NullHandler(logging.Handler): def emit(self, record): #pragma:nocover """Do not generate logging record""" # TODO: move this into a pyomo.common project logger = logging.getLogger('pyomo') logger.addHandler(NullHandler()) logger.setLevel(logging.WARNING) logger = logging.getLogger('pyomo.solvers') logger.addHandler(LogHandler(pyomo_base))
from pyutilib.misc import LogHandler # __file__ fails if script is called in different ways on Windows # __file__ fails if someone does os.chdir() before # sys.argv[0] also fails because it doesn't not always contains the path from os.path import dirname as _dir, abspath as _abs import inspect _pyomo_base = _dir(_dir(_dir(_abs(inspect.getfile(inspect.currentframe()))))) # # Set up the root Pyomo namespace logger # _logger = logging.getLogger('pyomo') _logger.addHandler( LogHandler(_pyomo_base, verbosity=lambda: _logger.isEnabledFor(logging.DEBUG))) _logger.setLevel(logging.WARNING) class LoggingIntercept(object): """Context manager for intercepting messages sent to a log stream This class is designed to enable easy testing of log messages. The LoggingIntercept context manager will intercept messages sent to a log stream matching a specified level and send the messages to the specified output stream. Other handlers registered to the target logger will be temporarily removed and the logger will be set not to propagate messages up to higher-level loggers. Args:
# ___________________________________________________________________________ # # Utility classes for working with the logger # import logging from pyutilib.misc import LogHandler from pyomo.common.fileutils import PYOMO_ROOT_DIR # # Set up the root Pyomo namespace logger # _logger = logging.getLogger('pyomo') _logger.addHandler( LogHandler(PYOMO_ROOT_DIR, verbosity=lambda: _logger.isEnabledFor(logging.DEBUG))) _logger.setLevel(logging.WARNING) class LoggingIntercept(object): """Context manager for intercepting messages sent to a log stream This class is designed to enable easy testing of log messages. The LoggingIntercept context manager will intercept messages sent to a log stream matching a specified level and send the messages to the specified output stream. Other handlers registered to the target logger will be temporarily removed and the logger will be set not to propagate messages up to higher-level loggers. Args: