当前位置: 首页>>代码示例>>Python>>正文


Python log.getLogger函数代码示例

本文整理汇总了Python中st2common.log.getLogger函数的典型用法代码示例。如果您正苦于以下问题:Python getLogger函数的具体用法?Python getLogger怎么用?Python getLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getLogger函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    _parse_config()
    if CONF.verbose:
        _setup_logging()
        output = logging.getLogger(__name__).info
    else:
        output = pprint.pprint
    _setup_db()
    _refire_trigger_instance(trigger_instance_id=CONF.trigger_instance_id,
                             log_=logging.getLogger(__name__))
    output('Trigger re-fired')
    db_teardown()
开发者ID:lyandut,项目名称:st2,代码行数:12,代码来源:trigger_re_fire.py

示例2: __init__

    def __init__(self, pack, file_path, class_name, trigger_types,
                 poll_interval=None, parent_args=None):
        """
        :param pack: Name of the pack this sensor belongs to.
        :type pack: ``str``

        :param file_path: Path to the sensor module file.
        :type file_path: ``str``

        :param class_name: Sensor class name.
        :type class_name: ``str``

        :param trigger_types: A list of references to trigger types which
                                  belong to this sensor.
        :type trigger_types: ``list`` of ``str``

        :param poll_interval: Sensor poll interval (in seconds).
        :type poll_interval: ``int`` or ``None``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """
        self._pack = pack
        self._file_path = file_path
        self._class_name = class_name
        self._trigger_types = trigger_types or []
        self._poll_interval = poll_interval
        self._parent_args = parent_args or []
        self._trigger_names = {}

        # 1. Parse the config with inherited parent args
        try:
            config.parse_args(args=self._parent_args)
        except Exception:
            pass

        # 2. Establish DB connection
        username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None
        password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None
        db_setup_with_retry(cfg.CONF.database.db_name, cfg.CONF.database.host,
                            cfg.CONF.database.port, username=username, password=password)

        # 3. Instantiate the watcher
        self._trigger_watcher = TriggerWatcher(create_handler=self._handle_create_trigger,
                                               update_handler=self._handle_update_trigger,
                                               delete_handler=self._handle_delete_trigger,
                                               trigger_types=self._trigger_types,
                                               queue_suffix='sensorwrapper_%s_%s' %
                                               (self._pack, self._class_name),
                                               exclusive=True)

        # 4. Set up logging
        self._logger = logging.getLogger('SensorWrapper.%s.%s' %
                                         (self._pack, self._class_name))
        logging.setup(cfg.CONF.sensorcontainer.logging)

        if '--debug' in parent_args:
            set_log_level_for_all_loggers()

        self._sensor_instance = self._get_sensor_instance()
开发者ID:cdminigun,项目名称:st2,代码行数:60,代码来源:sensor_wrapper.py

示例3: __init__

    def __init__(self, pack, file_path, parameters=None, parent_args=None):
        """
        :param pack: Name of the pack this action belongs to.
        :type pack: ``str``

        :param file_path: Path to the action module.
        :type file_path: ``str``

        :param parameters: action parameters.
        :type parameters: ``dict`` or ``None``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """

        self._pack = pack
        self._file_path = file_path
        self._parameters = parameters or {}
        self._parent_args = parent_args or []
        self._class_name = None
        self._logger = logging.getLogger('PythonActionWrapper')

        try:
            config.parse_args(args=self._parent_args)
        except Exception:
            pass
        else:
            db_setup()
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:28,代码来源:python_action_wrapper.py

示例4: get_logger

 def get_logger(self, name):
     """
     Retrieve an instance of a logger to be used by the sensor class.
     """
     logger_name = '%s.%s' % (self._sensor_wrapper._logger.name, name)
     logger = logging.getLogger(logger_name)
     logger.propagate = True
     return logger
开发者ID:jonico,项目名称:st2,代码行数:8,代码来源:sensor_wrapper.py

示例5: test_log_audit

 def test_log_audit(self):
     """Test that AUDIT log entry goes to the audit log."""
     logging.setup(self.cfg_path)
     log = logging.getLogger(__name__)
     msg = uuid.uuid4().hex
     log.audit(msg)
     info_log_entries = open(self.info_log_path).read()
     self.assertIn(msg, info_log_entries)
     audit_log_entries = open(self.audit_log_path).read()
     self.assertIn(msg, audit_log_entries)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:10,代码来源:test_logger.py

示例6: test_log_critical

 def test_log_critical(self):
     """Test that CRITICAL log entry does not go to the audit log."""
     logging.setup(self.cfg_path)
     log = logging.getLogger(__name__)
     msg = uuid.uuid4().hex
     log.critical(msg)
     info_log_entries = open(self.info_log_path).read()
     self.assertIn(msg, info_log_entries)
     audit_log_entries = open(self.audit_log_path).read()
     self.assertNotIn(msg, audit_log_entries)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:10,代码来源:test_logger.py

示例7: test_logger_set_level

 def test_logger_set_level(self):
     logging.setup(self.cfg_path)
     log = logging.getLogger(__name__)
     self.assertEqual(log.getEffectiveLevel(), logbase.DEBUG)
     log.setLevel(logbase.INFO)
     self.assertEqual(log.getEffectiveLevel(), logbase.INFO)
     log.setLevel(logbase.WARN)
     self.assertEqual(log.getEffectiveLevel(), logbase.WARN)
     log.setLevel(logbase.ERROR)
     self.assertEqual(log.getEffectiveLevel(), logbase.ERROR)
     log.setLevel(logbase.CRITICAL)
     self.assertEqual(log.getEffectiveLevel(), logbase.CRITICAL)
     log.setLevel(logbase.AUDIT)
     self.assertEqual(log.getEffectiveLevel(), logbase.AUDIT)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:14,代码来源:test_logger.py

示例8: __init__

    def __init__(self, pack, file_path, class_name, trigger_types,
                 poll_interval=None, parent_args=None):
        """
        :param pack: Name of the pack this sensor belongs to.
        :type pack: ``str``

        :param file_path: Path to the sensor module file.
        :type file_path: ``str``

        :param class_name: Sensor class name.
        :type class_name: ``str``

        :param trigger_types: A list of references to trigger types which
                                  belong to this sensor.
        :type trigger_types: ``list`` of ``str``

        :param poll_interval: Sensor poll interval (in seconds).
        :type poll_interval: ``int`` or ``None``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """
        self._pack = pack
        self._file_path = file_path
        self._class_name = class_name
        self._trigger_types = trigger_types or []
        self._poll_interval = poll_interval
        self._parent_args = parent_args or []
        self._trigger_names = {}

        # 1. Parse the config with inherited parent args
        try:
            config.parse_args(args=self._parent_args)
        except Exception:
            pass

        # 2. Instantiate the watcher
        self._trigger_watcher = TriggerWatcher(create_handler=self._handle_create_trigger,
                                               update_handler=self._handle_update_trigger,
                                               delete_handler=self._handle_delete_trigger,
                                               trigger_types=self._trigger_types)

        # 3. Set up logging
        self._logger = logging.getLogger('SensorWrapper.%s' %
                                         (self._class_name))
        logging.setup(cfg.CONF.sensorcontainer.logging)

        self._sensor_instance = self._get_sensor_instance()
开发者ID:nagyist,项目名称:StackStorm-st2,代码行数:48,代码来源:sensor_wrapper.py

示例9: get_logger_for_python_runner_action

def get_logger_for_python_runner_action(action_name):
    """
    Set up a logger which logs all the messages with level DEBUG and above to stderr.
    """
    logger_name = 'actions.python.%s' % (action_name)
    logger = logging.getLogger(logger_name)

    console = stdlib_logging.StreamHandler()
    console.setLevel(stdlib_logging.DEBUG)

    formatter = stdlib_logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
    console.setFormatter(formatter)
    logger.addHandler(console)
    logger.setLevel(stdlib_logging.DEBUG)

    return logger
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:16,代码来源:utils.py

示例10: _set_up_logger

    def _set_up_logger(self):
        """
        Set up a logger which logs all the messages with level DEBUG
        and above to stderr.
        """
        logger_name = "actions.python.%s" % (self.__class__.__name__)
        logger = logging.getLogger(logger_name)

        console = stdlib_logging.StreamHandler()
        console.setLevel(stdlib_logging.DEBUG)

        formatter = stdlib_logging.Formatter("%(name)-12s: %(levelname)-8s %(message)s")
        console.setFormatter(formatter)
        logger.addHandler(console)
        logger.setLevel(stdlib_logging.DEBUG)

        return logger
开发者ID:jonico,项目名称:st2,代码行数:17,代码来源:pythonrunner.py

示例11: __init__

    def __init__(self, pack, file_path, config=None, parameters=None, user=None, parent_args=None,
                 log_level=PYTHON_RUNNER_DEFAULT_LOG_LEVEL):
        """
        :param pack: Name of the pack this action belongs to.
        :type pack: ``str``

        :param file_path: Path to the action module.
        :type file_path: ``str``

        :param config: Pack config.
        :type config: ``dict``

        :param parameters: action parameters.
        :type parameters: ``dict`` or ``None``

        :param user: Name of the user who triggered this action execution.
        :type user: ``str``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """

        self._pack = pack
        self._file_path = file_path
        self._config = config or {}
        self._parameters = parameters or {}
        self._user = user
        self._parent_args = parent_args or []
        self._log_level = log_level

        self._class_name = None
        self._logger = logging.getLogger('PythonActionWrapper')

        try:
            st2common_config.parse_args(args=self._parent_args)
        except Exception as e:
            LOG.debug('Failed to parse config using parent args (parent_args=%s): %s' %
                      (str(self._parent_args), str(e)))

        # Note: We can only set a default user value if one is not provided after parsing the
        # config
        if not self._user:
            # Note: We use late import to avoid performance overhead
            from oslo_config import cfg
            self._user = cfg.CONF.system_user.user
开发者ID:lyandut,项目名称:st2,代码行数:45,代码来源:python_action_wrapper.py

示例12: __init__

    def __init__(self, pack, file_path, parameters=None, user=None, parent_args=None):
        """
        :param pack: Name of the pack this action belongs to.
        :type pack: ``str``

        :param file_path: Path to the action module.
        :type file_path: ``str``

        :param parameters: action parameters.
        :type parameters: ``dict`` or ``None``

        :param user: Name of the user who triggered this action execution.
        :type user: ``str``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """

        self._pack = pack
        self._file_path = file_path
        self._parameters = parameters or {}
        self._user = user
        self._parent_args = parent_args or []

        self._class_name = None
        self._logger = logging.getLogger('PythonActionWrapper')

        try:
            config.parse_args(args=self._parent_args)
        except Exception as e:
            LOG.debug('Failed to parse config using parent args (parent_args=%s): %s' %
                      (str(self._parent_args), str(e)))

        # We don't need to ensure indexes every subprocess because they should already be created
        # and ensured by other services
        db_setup(ensure_indexes=False)

        # Note: We can only set a default user value if one is not provided after parsing the
        # config
        if not self._user:
            self._user = cfg.CONF.system_user.user
开发者ID:Plexxi,项目名称:st2,代码行数:41,代码来源:python_action_wrapper.py

示例13: main

def main():
    args = _parse_args()
    if args.verbose:
        _setup_logging()
        output = logging.getLogger(__name__).info
    else:
        output = pprint.pprint

    rule_file_path = os.path.realpath(args.rule)
    trigger_instance_file_path = os.path.realpath(args.trigger_instance)

    tester = RuleTester(rule_file_path=rule_file_path,
                        trigger_instance_file_path=trigger_instance_file_path)
    matches = tester.evaluate()

    if matches:
        output('=== RULE MATCHES ===')
        sys.exit(0)
    else:
        output('=== RULE DOES NOT MATCH ===')
        sys.exit(1)
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:21,代码来源:rule_tester.py

示例14: __init__

    def __init__(self, pack, file_path, parameters=None, user=None, parent_args=None):
        """
        :param pack: Name of the pack this action belongs to.
        :type pack: ``str``

        :param file_path: Path to the action module.
        :type file_path: ``str``

        :param parameters: action parameters.
        :type parameters: ``dict`` or ``None``

        :param user: Name of the user who triggered this action execution.
        :type user: ``str``

        :param parent_args: Command line arguments passed to the parent process.
        :type parse_args: ``list``
        """

        self._pack = pack
        self._file_path = file_path
        self._parameters = parameters or {}
        self._user = user
        self._parent_args = parent_args or []
        self._class_name = None
        self._logger = logging.getLogger('PythonActionWrapper')

        try:
            config.parse_args(args=self._parent_args)
        except Exception:
            pass

        db_setup()

        # Note: We can only set a default user value if one is not provided after parsing the
        # config
        if not self._user:
            self._user = cfg.CONF.system_user.user
开发者ID:janjaapbos,项目名称:st2,代码行数:37,代码来源:python_action_wrapper.py

示例15: RuleFilter

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import six
from jsonpath_rw import parse

from st2common import log as logging
import st2common.operators as criteria_operators
from st2common.constants.rules import TRIGGER_PAYLOAD_PREFIX, RULE_TYPE_BACKSTOP
from st2common.constants.system import SYSTEM_KV_PREFIX
from st2common.services.keyvalues import KeyValueLookup
from st2common.util.templating import render_template_with_system_context


LOG = logging.getLogger('st2reactor.ruleenforcement.filter')


class RuleFilter(object):
    def __init__(self, trigger_instance, trigger, rule, extra_info=False):
        """
        :param trigger_instance: TriggerInstance DB object.
        :type trigger_instance: :class:`TriggerInstanceDB``

        :param trigger: Trigger DB object.
        :type trigger: :class:`TriggerDB`

        :param rule: Rule DB object.
        :type rule: :class:`RuleDB`
        """
        self.trigger_instance = trigger_instance
开发者ID:MohammadHabbab,项目名称:st2,代码行数:31,代码来源:filter.py


注:本文中的st2common.log.getLogger函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。