• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python scalyr_logging.getLogger函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_module_with_different_metric_logs

    def test_module_with_different_metric_logs(self):
        monitor_one = ScalyrLoggingTest.FakeMonitor('testing one')
        monitor_two = ScalyrLoggingTest.FakeMonitor('testing two')

        metric_file_one = tempfile.mktemp('.log')
        metric_file_two = tempfile.mktemp('.log')

        logger_one = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(1)')
        logger_two = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(2)')

        logger_one.openMetricLogForMonitor(metric_file_one, monitor_one)
        logger_two.openMetricLogForMonitor(metric_file_two, monitor_two)

        logger_one.report_values({'foo': 5})
        logger_two.report_values({'bar': 4})

        # The value should only appear in the metric log file and not the main one.
        self.assertTrue(self.__log_contains('foo=5', file_path=metric_file_one))
        self.assertTrue(self.__log_contains('bar=4', file_path=metric_file_two))

        self.assertFalse(self.__log_contains('foo=5', file_path=metric_file_two))
        self.assertFalse(self.__log_contains('bar=4', file_path=metric_file_one))

        self.assertFalse(self.__log_contains('foo=5'))
        self.assertFalse(self.__log_contains('bar=4'))

        logger_one.closeMetricLog()
        logger_two.closeMetricLog()
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:28,代码来源:scalyr_logging_test.py


示例2: test_component_name

 def test_component_name(self):
     self.assertEquals(self.__logger.component, 'core')
     self.assertEquals(scalyr_logging.getLogger('scalyr_agent').component, 'core')
     self.assertEquals(scalyr_logging.getLogger('scalyr_agent.foo').component, 'core')
     self.assertEquals(scalyr_logging.getLogger('scalyr_agent.foo.bar').component, 'core')
     self.assertEquals(scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo').component, 'monitor:foo')
     self.assertEquals(scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(ok)').component,
                       'monitor:foo(ok)')
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:8,代码来源:scalyr_logging_test.py


示例3: test_pass_in_module_with_metric

    def test_pass_in_module_with_metric(self):
        monitor_instance = ScalyrLoggingTest.FakeMonitor('testing')
        metric_file_path = tempfile.mktemp('.log')

        monitor_logger = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(1)')
        monitor_logger.openMetricLogForMonitor(metric_file_path, monitor_instance)
        scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo').report_values({'foo': 5},
                                                                                    monitor=monitor_instance)

        # The value should only appear in the metric log file and not the main one.
        self.assertTrue(self.__log_contains('foo=5', file_path=metric_file_path))
        self.assertFalse(self.__log_contains('foo=5'))

        monitor_logger.closeMetricLog()
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:14,代码来源:scalyr_logging_test.py


示例4: test_run_udp_server

    def test_run_udp_server(self):
        config = {
            'module': 'scalyr_agent.builtin_monitors.syslog_monitor',
            'protocols': 'udp:5514',
        }
        self.monitor = SyslogMonitor(config, scalyr_logging.getLogger("syslog_monitor[test]"))
        self.monitor.open_metric_log()
        self.monitor.start()

        time.sleep(0.1)

        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.sockets.append(s)

        expected = "UDP Test %s" % (uuid.uuid4())
        s.sendto(expected, ('localhost', 5514))
        time.sleep(1)
        self.monitor.stop(wait_on_join=False)
        self.monitor = None
        f = open('agent_syslog.log')
        actual = f.read().strip()
        self.assertTrue(
            expected in actual,
            "Unable to find '%s' in output:\n\t %s" % (expected, actual)
        )
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:25,代码来源:syslog_monitor_test.py


示例5: build_monitor

    def build_monitor(monitor_config, additional_python_paths, default_sample_interval_secs, global_config ):
        """Builds an instance of a ScalyrMonitor for the specified monitor configuration.

        @param monitor_config: The monitor configuration object for the monitor that should be created.  It will
            have keys such as 'module' that specifies the module containing the monitor, as well as others.
        @param additional_python_paths: A list of paths (separate by os.pathsep) to add to the PYTHONPATH when
            instantiating the module in case it needs to packages in other directories.
        @param global_config: The global configuration object

        @type monitor_config: dict
        @type additional_python_paths: str

        @return:  The appropriate ScalyrMonitor instance as controlled by the configuration.
        @rtype: scalyr_monitor.ScalyrMonitor
        """
        # Set up the logs to do the right thing.
        module_name = monitor_config['module']
        monitor_id = monitor_config['id']

        # We have to update this variable before we create monitor instances so that it is used.
        ScalyrMonitor.DEFAULT_SAMPLE_INTERVAL_SECS = default_sample_interval_secs

        # Load monitor.
        monitor_class = MonitorsManager.load_monitor(module_name, additional_python_paths)

        # Instantiate and initialize it.
        return monitor_class(monitor_config, scalyr_logging.getLogger("%s(%s)" % (module_name, monitor_id)), global_config=global_config)
开发者ID:imron,项目名称:scalyr-agent-2,代码行数:27,代码来源:monitors_manager.py


示例6: setUp

 def setUp(self):
     self.config_commandline = {
         "module": "scalyr_agent.builtin_monitors.linux_process_metrics",
         "id": "myapp",
         "commandline": ".foo.*",
     }
     self.monitor = ProcessMonitor(self.config_commandline, scalyr_logging.getLogger("syslog_monitor[test]"))
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:7,代码来源:linux_process_metrics_test.py


示例7: test_errors_for_monitor

    def test_errors_for_monitor(self):
        monitor_instance = ScalyrLoggingTest.FakeMonitor('testing')
        metric_file_path = tempfile.mktemp('.log')

        monitor_logger = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(1)')
        monitor_logger.openMetricLogForMonitor(metric_file_path, monitor_instance)
        monitor_logger.error('Foo')

        self.assertEquals(monitor_instance.errors, 1)

        monitor_logger.closeMetricLog()
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:11,代码来源:scalyr_logging_test.py


示例8: test_metric_logging_with_bad_name

    def test_metric_logging_with_bad_name(self):
        monitor_instance = ScalyrLoggingTest.FakeMonitor('testing')
        metric_file_path = tempfile.mktemp('.log')

        monitor_logger = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(1)')
        monitor_logger.openMetricLogForMonitor(metric_file_path, monitor_instance)

        self.assertRaises(scalyr_logging.BadMetricOrFieldName, monitor_logger.emit_value, '1name', 5)
        self.assertRaises(scalyr_logging.BadMetricOrFieldName, monitor_logger.emit_value, 'name+hi', 5)
        self.assertRaises(scalyr_logging.BadMetricOrFieldName, monitor_logger.emit_value, 'name', 5, {'hi+': 6})

        monitor_logger.closeMetricLog()
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:12,代码来源:scalyr_logging_test.py


示例9: test_run_multiple_servers

    def test_run_multiple_servers( self ):
        config = {
            'module': 'scalyr_agent.builtin_monitors.syslog_monitor',
            'protocols': 'udp:8000, tcp:8001, udp:8002, tcp:8003',
        }
        self.monitor = SyslogMonitor( config, scalyr_logging.getLogger( "syslog_monitor[test]" ) )
        self.monitor.open_metric_log()

        self.monitor.start()

        time.sleep( 0.01 )

        udp = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
        self.sockets.append( udp )

        tcp1 = socket.socket()
        self.sockets.append( tcp1 )

        tcp2 = socket.socket()
        self.sockets.append( tcp2 )

        self.connect( tcp1, ('localhost', 8001) )
        self.connect( tcp2, ('localhost', 8003) )


        expected_udp1 = "UDP Test"
        udp.sendto( expected_udp1, ('localhost', 8000) )

        expected_udp2 = "UDP2 Test"
        udp.sendto( expected_udp2, ('localhost', 8002) )

        expected_tcp1 = "TCP Test\n"
        tcp1.sendall( expected_tcp1 )

        expected_tcp2 = "TCP2 Test\n"
        tcp2.sendall( expected_tcp2 )

        time.sleep( 1 )

        self.monitor.stop( wait_on_join=False )
        self.monitor = None

        self.handler.flush()
        actual = self.stream.getvalue().strip()

        expected_tcp1 = expected_tcp1.strip()
        expected_tcp2 = expected_tcp2.strip()

        self.assertTrue( expected_udp1 in actual, "Unable to find '%s' in output:\n\t %s" % (expected_udp1, actual)  )
        self.assertTrue( expected_udp2 in actual, "Unable to find '%s' in output:\n\t %s" % (expected_udp2, actual)  )
        self.assertTrue( expected_tcp1 in actual, "Unable to find '%s' in output:\n\t %s" % (expected_tcp1, actual)  )
        self.assertTrue( expected_tcp2 in actual, "Unable to find '%s' in output:\n\t %s" % (expected_tcp2, actual)  )
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:52,代码来源:syslog_monitor_test.py


示例10: test_logging_to_metric_log

    def test_logging_to_metric_log(self):
        monitor_instance = ScalyrLoggingTest.FakeMonitor('testing')
        metric_file_path = tempfile.mktemp('.log')

        monitor_logger = scalyr_logging.getLogger('scalyr_agent.builtin_monitors.foo(1)')
        monitor_logger.openMetricLogForMonitor(metric_file_path, monitor_instance)
        monitor_logger.info('foobaz is fine', emit_to_metric_log=True)

        self.assertEquals(monitor_instance.reported_lines, 1)

        # The value should only appear in the metric log file and not the main one.
        self.assertTrue(self.__log_contains('foobaz is fine', file_path=metric_file_path))
        self.assertFalse(self.__log_contains('foobaz is fine'))

        monitor_logger.closeMetricLog()
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:15,代码来源:scalyr_logging_test.py


示例11: test_rate_limit

    def test_rate_limit(self):
        self.__log_path = tempfile.mktemp('.log')
        scalyr_logging.set_log_destination(use_disk=True, logs_directory=os.path.dirname(self.__log_path),
                                           agent_log_file_path=self.__log_path, max_write_burst=250, log_write_rate=0)
        self.__logger = scalyr_logging.getLogger('scalyr_agent.agent_main')

        string_300 = ''

        for i in range(300):
            string_300 = '%sa' % string_300

        self.__logger.info('First message')
        self.assertTrue(self.__log_contains('First message'))

        self.__logger.info('Dropped message %s', string_300)
        self.assertFalse(self.__log_contains('Dropped message'))

        self.__logger.info('Second message')
        self.assertTrue(self.__log_contains('Second message'))
        self.assertTrue(self.__log_contains('Warning, skipped writing 1 log lines'))
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:20,代码来源:scalyr_logging_test.py


示例12: test_limit_once_per_x_secs

    def test_limit_once_per_x_secs(self):
        log = scalyr_logging.getLogger('scalyr_agent.foo')
        log.info('First record', limit_once_per_x_secs=60.0, limit_key='foo', current_time=0.0)
        log.info('Second record', limit_once_per_x_secs=60.0, limit_key='foo', current_time=1.0)
        log.info('Third record', limit_once_per_x_secs=60.0, limit_key='foo', current_time=61.0)

        self.assertTrue(self.__log_contains('First record'))
        self.assertFalse(self.__log_contains('Second record'))
        self.assertTrue(self.__log_contains('Third record'))

        # Now test with different keys.
        log.info('First record', limit_once_per_x_secs=30.0, limit_key='foo', current_time=0.0)
        log.info('Second record', limit_once_per_x_secs=60.0, limit_key='bar', current_time=1.0)
        log.info('Third record', limit_once_per_x_secs=30.0, limit_key='foo', current_time=31.0)
        log.info('Fourth record', limit_once_per_x_secs=60.0, limit_key='bar', current_time=31.0)

        self.assertTrue(self.__log_contains('First record'))
        self.assertTrue(self.__log_contains('Second record'))
        self.assertTrue(self.__log_contains('Third record'))
        self.assertFalse(self.__log_contains('Fourth record'))
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:20,代码来源:scalyr_logging_test.py


示例13: build_monitor

    def build_monitor(monitor_config, additional_python_paths):
        """Builds an instance of a ScalyrMonitor for the specified monitor configuration.

        @param monitor_config: The monitor configuration object for the monitor that should be created.  It will
            have keys such as 'module' that specifies the module containing the monitor, as well as others.
        @param additional_python_paths: A list of paths (separate by os.pathsep) to add to the PYTHONPATH when
            instantiating the module in case it needs to packages in other directories.

        @type monitor_config: dict
        @type additional_python_paths: str

        @return:  The appropriate ScalyrMonitor instance as controlled by the configuration.
        @rtype: scalyr_monitor.ScalyrMonitor
        """
        # Set up the logs to do the right thing.
        module_name = monitor_config['module']
        monitor_id = monitor_config['id']

        # Augment the PYTHONPATH if requested to locate the module.
        original_path = list(sys.path)

        # Also add in scalyr_agent/../monitors/local and scalyr_agent/../monitors/contrib to the Python path to search
        # for monitors.  (They are always in the parent directory of the scalyr_agent package.
        path_to_package_parent = os.path.dirname(get_package_root())
        sys.path.append(os.path.join(path_to_package_parent, 'monitors', 'local'))
        sys.path.append(os.path.join(path_to_package_parent, 'monitors', 'contrib'))

        # Add in the additional paths.
        if additional_python_paths is not None and len(additional_python_paths) > 0:
            for x in additional_python_paths.split(os.pathsep):
                sys.path.append(x)

        # Load monitor.
        try:
            monitor_class = MonitorsManager.__load_class_from_module(module_name)
        finally:
            # Be sure to reset the PYTHONPATH
            sys.path = original_path

        # Instantiate and initialize it.
        return monitor_class(monitor_config, scalyr_logging.getLogger("%s(%s)" % (module_name, monitor_id)))
开发者ID:mariolameiras,项目名称:scalyr-agent-2,代码行数:41,代码来源:monitors_manager.py


示例14: build_monitor

    def build_monitor(monitor_config, additional_python_paths):
        """Builds an instance of a ScalyrMonitor for the specified monitor configuration.

        @param monitor_config: The monitor configuration object for the monitor that should be created.  It will
            have keys such as 'module' that specifies the module containing the monitor, as well as others.
        @param additional_python_paths: A list of paths (separate by os.pathsep) to add to the PYTHONPATH when
            instantiating the module in case it needs to packages in other directories.

        @type monitor_config: dict
        @type additional_python_paths: str

        @return:  The appropriate ScalyrMonitor instance as controlled by the configuration.
        @rtype: scalyr_monitor.ScalyrMonitor
        """
        # Set up the logs to do the right thing.
        module_name = monitor_config['module']
        monitor_id = monitor_config['id']

        # Load monitor.
        monitor_class = MonitorsManager.load_monitor(module_name, additional_python_paths)

        # Instantiate and initialize it.
        return monitor_class(monitor_config, scalyr_logging.getLogger("%s(%s)" % (module_name, monitor_id)))
开发者ID:GitSullied,项目名称:scalyr-agent-2,代码行数:23,代码来源:monitors_manager.py


示例15: test_config_port_too_high

 def test_config_port_too_high(self):
     config = {
         'module': 'scalyr_agent.builtin_monitors.syslog_monitor',
         'protocols': 'udp:70000'
     }
     self.assertRaises(Exception, lambda: SyslogMonitor(config, scalyr_logging.getLogger("syslog_monitor[test]")))
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:6,代码来源:syslog_monitor_test.py


示例16: test_config_protocol_invalid

 def test_config_protocol_invalid(self):
     config = {
         'module': 'scalyr_agent.builtin_monitors.syslog_monitor',
         'protocols': 'XXX'
     }
     self.assertRaises(Exception, lambda: SyslogMonitor(config, scalyr_logging.getLogger("syslog_monitor[test]")))
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:6,代码来源:syslog_monitor_test.py


示例17: test_config_protocol_multiple_two

 def test_config_protocol_multiple_two(self):
     config = {
         'module': 'scalyr_agent.builtin_monitors.syslog_monitor',
         'protocols': 'tcp, udp'
     }
     self.assertNoException(lambda: SyslogMonitor(config, scalyr_logging.getLogger("syslog_monitor[test]")))
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:6,代码来源:syslog_monitor_test.py


示例18: CopyingParameters

__author__ = '[email protected]'

import os
import threading
import time
import sys

import scalyr_agent.scalyr_logging as scalyr_logging
import scalyr_agent.util as scalyr_util

from scalyr_agent import json_lib
from scalyr_agent.util import StoppableThread
from scalyr_agent.log_processing import LogMatcher, LogFileProcessor
from scalyr_agent.agent_status import CopyingManagerStatus

log = scalyr_logging.getLogger(__name__)


class CopyingParameters(object):
    """Tracks the copying parameters that should be used for sending requests to Scalyr and adjusts them over time
    according to success and failures of requests.

    The copying parameters boil down to two parameters:  the maximum number of bytes that can be sent to Scalyr
    in a request (self.current_bytes_allowed_to_send), and the minimum amount of time to wait between requests
    (self.current_sleep_interval).

    This implements a truncated binary backoff algorithm.
    """
    def __init__(self, configuration):
        """Initialize the parameters based on the thresholds defined in the configuration file.
开发者ID:GitSullied,项目名称:scalyr-agent-2,代码行数:30,代码来源:copying_manager.py


示例19: test_initialize_monitor

 def test_initialize_monitor(self):
     monitor = ProcessMonitor(self.config_commandline, scalyr_logging.getLogger("syslog_monitor[test]"))
     self.assertEqual(monitor._ProcessMonitor__metrics_history, defaultdict(dict))
     self.assertEqual(monitor._ProcessMonitor__aggregated_metrics, {})
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:4,代码来源:linux_process_metrics_test.py


示例20: test_sibling_modules

 def test_sibling_modules(self):
     child = scalyr_logging.getLogger('external_package.my_monitor')
     child.info('Sibling statement')
     self.assertTrue(self.__log_contains('Sibling statement'))
开发者ID:ReturnPath,项目名称:scalyr-agent-2,代码行数:4,代码来源:scalyr_logging_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python scandir.scandir函数代码示例发布时间:2022-05-27
下一篇:
Python helper.exc_info函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap