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


Python glogging.Logger类代码示例

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


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

示例1: _sock_send

 def _sock_send(self, msg):
     try:
         if isinstance(msg, six.text_type):
             msg = msg.encode("ascii")
         if self.sock:
             self.sock.send(msg)
     except Exception:
         Logger.warning(self, "Error sending message to statsd", exc_info=True)
开发者ID:CollinsMuiruri,项目名称:Instagram,代码行数:8,代码来源:statsd.py

示例2: access

    def access(self, resp, req, environ, request_time):
        # health check endpoints are only logged in debug mode
        if (
            not os.environ.get('DEIS_DEBUG', False) and
            req.path in ['/readiness', '/healthz']
        ):
            return

        Logger.access(self, resp, req, environ, request_time)
开发者ID:HL70,项目名称:controller,代码行数:9,代码来源:logging.py

示例3: access

 def access(self, resp, req, environ, request_time):
     """Measure request duration
     request_time is a datetime.timedelta
     """
     Logger.access(self, resp, req, environ, request_time)
     duration_in_ms = request_time.seconds * 1000 + float(request_time.microseconds) / 10 ** 3
     self.histogram("gunicorn.request.duration", duration_in_ms)
     self.increment("gunicorn.requests", 1)
     self.increment("gunicorn.request.status.%d" % int(resp.status.split()[0]), 1)
开发者ID:AaronKazan1,项目名称:Django_Finance,代码行数:9,代码来源:statsd.py

示例4: __init__

 def __init__(self, cfg):
     """host, port: statsD server
     """
     Logger.__init__(self, cfg)
     try:
         host, port = cfg.statsd_host
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         self.sock.connect((host, int(port)))
     except Exception:
         self.sock = None
开发者ID:JasonRodriguez1,项目名称:django_hello_world,代码行数:10,代码来源:statsd.py

示例5: __init__

 def __init__(self, cfg):
     """host, port: statsD server
     """
     Logger.__init__(self, cfg)
     self.prefix = sub(r"^(.+[^.]+)\.*$", "\\g<1>.", cfg.statsd_prefix)
     try:
         host, port = cfg.statsd_host
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
         self.sock.connect((host, int(port)))
     except Exception:
         self.sock = None
开发者ID:CollinsMuiruri,项目名称:Instagram,代码行数:11,代码来源:statsd.py

示例6: test_atoms_defaults

def test_atoms_defaults():
    response = Mock(status='200', response_length=1024,
        headers=(('Content-Type', 'application/json'), ))
    request = Mock(headers=(('Accept', 'application/json'), ))
    environ = {'REQUEST_METHOD': 'GET', 'RAW_URI': 'http://my.uri',
        'SERVER_PROTOCOL': 'HTTP/1.1'}
    logger = Logger(Config())
    atoms = logger.atoms(response, request, environ,
        datetime.timedelta(seconds=1))
    t.istype(atoms, dict)
    t.eq(atoms['r'], 'GET http://my.uri HTTP/1.1')
    t.eq(atoms['{accept}i'], 'application/json')
    t.eq(atoms['{content-type}o'], 'application/json')
开发者ID:APAdmin,项目名称:gunicorn,代码行数:13,代码来源:test_006-logger.py

示例7: __init__

 def __init__(self, cfg):
     Logger.__init__(self, cfg)
     self.is_statsd = False
     statsd_server = os.environ.get("statsd")
     if statsd_server:
         try:
             host, port = statsd_server.split(":")
             self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
             self.sock.connect((host, int(port)))
         except Exception:
             self.sock = None
         else:
             self.is_statsd = True
开发者ID:wmttom,项目名称:gunicorn_thrift,代码行数:13,代码来源:thriftlogging.py

示例8: _sock_send

    def _sock_send(self, msg):
        try:
            if isinstance(msg, str):
                msg = msg.encode("ascii")

            # http://docs.datadoghq.com/guides/dogstatsd/#datagram-format
            if self.dogstatsd_tags:
                msg = msg + b"|#" + self.dogstatsd_tags.encode('ascii')

            if self.sock:
                self.sock.send(msg)
        except Exception:
            Logger.warning(self, "Error sending message to statsd", exc_info=True)
开发者ID:benoitc,项目名称:gunicorn,代码行数:13,代码来源:statsd.py

示例9: test_get_username_from_basic_auth_header

def test_get_username_from_basic_auth_header():
    request = SimpleNamespace(headers=())
    response = SimpleNamespace(
        status='200', response_length=1024, sent=1024,
        headers=(('Content-Type', 'text/plain'),),
    )
    environ = {
        'REQUEST_METHOD': 'GET', 'RAW_URI': 'http://my.uri',
        'SERVER_PROTOCOL': 'HTTP/1.1',
        'HTTP_AUTHORIZATION': 'Basic YnJrMHY6',
    }
    logger = Logger(Config())
    atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
    assert atoms['u'] == 'brk0v'
开发者ID:keakon,项目名称:gunicorn,代码行数:14,代码来源:test_logger.py

示例10: test_atoms_zero_bytes

def test_atoms_zero_bytes():
    response = SimpleNamespace(
        status='200', response_length=0,
        headers=(('Content-Type', 'application/json'),), sent=0,
    )
    request = SimpleNamespace(headers=(('Accept', 'application/json'),))
    environ = {
        'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
        'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
        'SERVER_PROTOCOL': 'HTTP/1.1',
    }
    logger = Logger(Config())
    atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
    assert atoms['b'] == '0'
    assert atoms['B'] == 0
开发者ID:benoitc,项目名称:gunicorn,代码行数:15,代码来源:test_logger.py

示例11: test_atoms_defaults

def test_atoms_defaults():
    response = SimpleNamespace(
        status='200', response_length=1024,
        headers=(('Content-Type', 'application/json'),), sent=1024,
    )
    request = SimpleNamespace(headers=(('Accept', 'application/json'),))
    environ = {
        'REQUEST_METHOD': 'GET', 'RAW_URI': 'http://my.uri',
        'SERVER_PROTOCOL': 'HTTP/1.1',
    }
    logger = Logger(Config())
    atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
    assert isinstance(atoms, dict)
    assert atoms['r'] == 'GET http://my.uri HTTP/1.1'
    assert atoms['{accept}i'] == 'application/json'
    assert atoms['{content-type}o'] == 'application/json'
开发者ID:keakon,项目名称:gunicorn,代码行数:16,代码来源:test_logger.py

示例12: test_get_username_handles_malformed_basic_auth_header

def test_get_username_handles_malformed_basic_auth_header():
    """Should catch a malformed auth header"""
    request = SimpleNamespace(headers=())
    response = SimpleNamespace(
        status='200', response_length=1024, sent=1024,
        headers=(('Content-Type', 'text/plain'),),
    )
    environ = {
        'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
        'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
        'SERVER_PROTOCOL': 'HTTP/1.1',
        'HTTP_AUTHORIZATION': 'Basic ixsTtkKzIpVTncfQjbBcnoRNoDfbnaXG',
    }
    logger = Logger(Config())

    atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
    assert atoms['u'] == '-'
开发者ID:manlan2,项目名称:gunicorn,代码行数:17,代码来源:test_logger.py

示例13: info

 def info(self, msg, *args, **kwargs):
     """Log a given statistic if metric, value and type are present
     """
     Logger.info(self, msg, *args, **kwargs)
     extra = kwargs.get("extra", None)
     if extra is not None:
         metric = extra.get(METRIC_VAR, None)
         value = extra.get(VALUE_VAR, None)
         typ = extra.get(MTYPE_VAR, None)
         if metric and value and typ:
             if typ == GAUGE_TYPE:
                 self.gauge(metric, value)
             elif typ == COUNTER_TYPE:
                 self.increment(metric, value)
             elif typ == HISTOGRAM_TYPE:
                 self.histogram(metric, value)
             else:
                 pass
开发者ID:JasonRodriguez1,项目名称:django_hello_world,代码行数:18,代码来源:statsd.py

示例14: test_atoms_defaults

def test_atoms_defaults():
    response = SimpleNamespace(
        status='200', response_length=1024,
        headers=(('Content-Type', 'application/json'),), sent=1024,
    )
    request = SimpleNamespace(headers=(('Accept', 'application/json'),))
    environ = {
        'REQUEST_METHOD': 'GET', 'RAW_URI': '/my/path?foo=bar',
        'PATH_INFO': '/my/path', 'QUERY_STRING': 'foo=bar',
        'SERVER_PROTOCOL': 'HTTP/1.1',
    }
    logger = Logger(Config())
    atoms = logger.atoms(response, request, environ, datetime.timedelta(seconds=1))
    assert isinstance(atoms, dict)
    assert atoms['r'] == 'GET /my/path?foo=bar HTTP/1.1'
    assert atoms['m'] == 'GET'
    assert atoms['U'] == '/my/path'
    assert atoms['q'] == 'foo=bar'
    assert atoms['H'] == 'HTTP/1.1'
    assert atoms['b'] == '1024'
    assert atoms['B'] == 1024
    assert atoms['{accept}i'] == 'application/json'
    assert atoms['{content-type}o'] == 'application/json'
开发者ID:BerlinK,项目名称:web,代码行数:23,代码来源:test_logger.py

示例15: log

    def log(self, lvl, msg, *args, **kwargs):
        """Log a given statistic if metric, value and type are present
        """
        try:
            extra = kwargs.get("extra", None)
            if extra is not None:
                metric = extra.get(METRIC_VAR, None)
                value = extra.get(VALUE_VAR, None)
                typ = extra.get(MTYPE_VAR, None)
                if metric and value and typ:
                    if typ == GAUGE_TYPE:
                        self.gauge(metric, value)
                    elif typ == COUNTER_TYPE:
                        self.increment(metric, value)
                    elif typ == HISTOGRAM_TYPE:
                        self.histogram(metric, value)
                    else:
                        pass

            # Log to parent logger only if there is something to say
            if msg:
                Logger.log(self, lvl, msg, *args, **kwargs)
        except Exception:
            Logger.warning(self, "Failed to log to statsd", exc_info=True)
开发者ID:CollinsMuiruri,项目名称:Instagram,代码行数:24,代码来源:statsd.py


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