當前位置: 首頁>>代碼示例>>Python>>正文


Python gen_log.error方法代碼示例

本文整理匯總了Python中tornado.log.gen_log.error方法的典型用法代碼示例。如果您正苦於以下問題:Python gen_log.error方法的具體用法?Python gen_log.error怎麽用?Python gen_log.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.log.gen_log的用法示例。


在下文中一共展示了gen_log.error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _handle_request_exception

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _handle_request_exception(self, e):
        if isinstance(e, Finish):
            # Not an error; just finish the request without logging.
            if not self._finished:
                self.finish(*e.args)
            return
        try:
            self.log_exception(*sys.exc_info())
        except Exception:
            # An error here should still get a best-effort send_error()
            # to avoid leaking the connection.
            app_log.error("Error in exception logger", exc_info=True)
        if self._finished:
            # Extra errors after the request has been finished should
            # be logged, but there is no reason to continue to try and
            # send a response.
            return
        if isinstance(e, HTTPError):
            if e.status_code not in httputil.responses and not e.reason:
                gen_log.error("Bad HTTP status code: %d", e.status_code)
                self.send_error(500, exc_info=sys.exc_info())
            else:
                self.send_error(e.status_code, exc_info=sys.exc_info())
        else:
            self.send_error(500, exc_info=sys.exc_info()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:27,代碼來源:web.py

示例2: log_exception

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def log_exception(self, typ, value, tb):
        """複寫來自定義未捕獲異常的日誌.

        默認情況下 `HTTPError` 的日誌實例作為警告(warning)沒有堆棧追蹤(在
        ``tornado.general`` logger), 其他作為錯誤(error)的異常帶有堆棧
        追蹤(在 ``tornado.application`` logger).

        .. versionadded:: 3.1
        """
        if isinstance(value, HTTPError):
            if value.log_message:
                format = "%d %s: " + value.log_message
                args = ([value.status_code, self._request_summary()] +
                        list(value.args))
                gen_log.warning(format, *args)
        else:
            app_log.error("Uncaught exception %s\n%r", self._request_summary(),
                          self.request, exc_info=(typ, value, tb)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:20,代碼來源:web.py

示例3: _run_read_callback

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _run_read_callback(self, size, streaming):
        if streaming:
            callback = self._streaming_callback
        else:
            callback = self._read_callback
            self._read_callback = self._streaming_callback = None
            if self._read_future is not None:
                assert callback is None
                future = self._read_future
                self._read_future = None
                future.set_result(self._consume(size))
        if callback is not None:
            assert (self._read_future is None) or streaming
            self._run_callback(callback, self._consume(size))
        else:
            # If we scheduled a callback, we will add the error listener
            # afterwards.  If we didn't, we have to do it now.
            self._maybe_add_error_listener() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:20,代碼來源:iostream.py

示例4: _handle_connect

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _handle_connect(self):
        err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
        if err != 0:
            self.error = socket.error(err, os.strerror(err))
            # IOLoop implementations may vary: some of them return
            # an error state before the socket becomes writable, so
            # in that case a connection failure would be handled by the
            # error path in _handle_events instead of here.
            if self._connect_future is None:
                gen_log.warning("Connect error on fd %s: %s",
                                self.socket.fileno(), errno.errorcode[err])
            self.close()
            return
        if self._connect_callback is not None:
            callback = self._connect_callback
            self._connect_callback = None
            self._run_callback(callback)
        if self._connect_future is not None:
            future = self._connect_future
            self._connect_future = None
            future.set_result(self)
        self._connecting = False 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:24,代碼來源:iostream.py

示例5: __init__

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def __init__(self, *args, **kwargs):
        """The ``ssl_options`` keyword argument may either be an
        `ssl.SSLContext` object or a dictionary of keywords arguments
        for `ssl.wrap_socket`
        """
        self._ssl_options = kwargs.pop('ssl_options', _client_ssl_defaults)
        super(SSLIOStream, self).__init__(*args, **kwargs)
        self._ssl_accepting = True
        self._handshake_reading = False
        self._handshake_writing = False
        self._ssl_connect_callback = None
        self._server_hostname = None

        # If the socket is already connected, attempt to start the handshake.
        try:
            self.socket.getpeername()
        except socket.error:
            pass
        else:
            # Indirectly start the handshake, which will run on the next
            # IOLoop iteration and then the real IO state will be set in
            # _handle_events.
            self._add_io_state(self.io_loop.WRITE) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:25,代碼來源:iostream.py

示例6: _run_callback

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _run_callback(self, callback):
        """Runs a callback with error handling.

        For use in subclasses.
        """
        try:
            ret = callback()
            if ret is not None:
                from tornado import gen
                # Functions that return Futures typically swallow all
                # exceptions and store them in the Future.  If a Future
                # makes it out to the IOLoop, ensure its exception (if any)
                # gets logged too.
                try:
                    ret = gen.convert_yielded(ret)
                except gen.BadYieldError:
                    # It's not unusual for add_callback to be used with
                    # methods returning a non-None and non-yieldable
                    # result, which should just be ignored.
                    pass
                else:
                    self.add_future(ret, lambda f: f.result())
        except Exception:
            self.handle_callback_exception(callback) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:26,代碼來源:ioloop.py

示例7: _server_request_loop

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _server_request_loop(self, delegate):
        try:
            while True:
                conn = HTTP1Connection(self.stream, False,
                                       self.params, self.context)
                request_delegate = delegate.start_request(self, conn)
                try:
                    ret = yield conn.read_response(request_delegate)
                except (iostream.StreamClosedError,
                        iostream.UnsatisfiableReadError):
                    return
                except _QuietException:
                    # This exception was already logged.
                    conn.close()
                    return
                except Exception:
                    gen_log.error("Uncaught exception", exc_info=True)
                    conn.close()
                    return
                if not ret:
                    return
                yield gen.moment
        finally:
            delegate.on_close(self) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:26,代碼來源:http1connection.py

示例8: log_request

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def log_request(self, handler):
        """寫一個完成的HTTP 請求到日誌中.

        默認情況下會寫到python 根(root)logger. 要改變這種行為
        無論是子類應用和複寫這個方法, 或者傳遞一個函數到應用的
        設置字典中作為 ``log_function``.
        """
        if "log_function" in self.settings:
            self.settings["log_function"](handler)
            return
        if handler.get_status() < 400:
            log_method = access_log.info
        elif handler.get_status() < 500:
            log_method = access_log.warning
        else:
            log_method = access_log.error
        request_time = 1000.0 * handler.request.request_time()
        log_method("%d %s %.2fms", handler.get_status(),
                   handler._request_summary(), request_time) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:web.py

示例9: close

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def close(self, exc_info=False):
        """Close this stream.

        If ``exc_info`` is true, set the ``error`` attribute to the current
        exception from `sys.exc_info` (or if ``exc_info`` is a tuple,
        use that instead of `sys.exc_info`).
        """
        if not self.closed():
            if exc_info:
                if not isinstance(exc_info, tuple):
                    exc_info = sys.exc_info()
                if any(exc_info):
                    self.error = exc_info[1]
            if self._read_until_close:
                if (self._streaming_callback is not None and
                        self._read_buffer_size):
                    self._run_read_callback(self._read_buffer_size, True)
                self._read_until_close = False
                self._run_read_callback(self._read_buffer_size, False)
            if self._state is not None:
                self.io_loop.remove_handler(self.fileno())
                self._state = None
            self.close_fd()
            self._closed = True
        self._maybe_run_close_callback() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:27,代碼來源:iostream.py

示例10: write_error

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def write_error(self, status_code: int, **kwargs: Any) -> None:
        """Override to implement custom error pages.

        ``write_error`` may call `write`, `render`, `set_header`, etc
        to produce output as usual.

        If this error was caused by an uncaught exception (including
        HTTPError), an ``exc_info`` triple will be available as
        ``kwargs["exc_info"]``.  Note that this exception may not be
        the "current" exception for purposes of methods like
        ``sys.exc_info()`` or ``traceback.format_exc``.
        """
        if self.settings.get("serve_traceback") and "exc_info" in kwargs:
            # in debug mode, try to send a traceback
            self.set_header("Content-Type", "text/plain")
            for line in traceback.format_exception(*kwargs["exc_info"]):
                self.write(line)
            self.finish()
        else:
            self.finish(
                "<html><title>%(code)d: %(message)s</title>"
                "<body>%(code)d: %(message)s</body></html>"
                % {"code": status_code, "message": self._reason}
            ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:26,代碼來源:web.py

示例11: log_request

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def log_request(self, handler: RequestHandler) -> None:
        """Writes a completed HTTP request to the logs.

        By default writes to the python root logger.  To change
        this behavior either subclass Application and override this method,
        or pass a function in the application settings dictionary as
        ``log_function``.
        """
        if "log_function" in self.settings:
            self.settings["log_function"](handler)
            return
        if handler.get_status() < 400:
            log_method = access_log.info
        elif handler.get_status() < 500:
            log_method = access_log.warning
        else:
            log_method = access_log.error
        request_time = 1000.0 * handler.request.request_time()
        log_method(
            "%d %s %.2fms",
            handler.get_status(),
            handler._request_summary(),
            request_time,
        ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:26,代碼來源:web.py

示例12: set_default_headers

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def set_default_headers(self):
        """複寫這個方法可以在請求開始的時候設置HTTP頭.

        例如, 在這裏可以設置一個自定義 ``Server`` 頭. 注意在一般的
        請求過程流裏可能不會實現你預期的效果, 因為頭部可能在錯誤處
        理(error handling)中被重置.
        """
        pass 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:web.py

示例13: send_error

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def send_error(self, status_code=500, **kwargs):
        """給瀏覽器發送給定的HTTP 錯誤碼.

        如果 `flush()` 已經被調用, 它是不可能發送錯誤的, 所以這個方法將終止
        響應. 如果輸出已經被寫但尚未flush, 它將被丟棄並被錯誤頁代替.

        複寫 `write_error()` 來自定義它返回的錯誤頁. 額外的關鍵字參數將
        被傳遞給 `write_error`.
        """
        if self._headers_written:
            gen_log.error("Cannot send error response after headers written")
            if not self._finished:
                # If we get an error between writing headers and finishing,
                # we are unlikely to be able to finish due to a
                # Content-Length mismatch. Try anyway to release the
                # socket.
                try:
                    self.finish()
                except Exception:
                    gen_log.error("Failed to flush partial response",
                                  exc_info=True)
            return
        self.clear()

        reason = kwargs.get('reason')
        if 'exc_info' in kwargs:
            exception = kwargs['exc_info'][1]
            if isinstance(exception, HTTPError) and exception.reason:
                reason = exception.reason
        self.set_status(status_code, reason=reason)
        try:
            self.write_error(status_code, **kwargs)
        except Exception:
            app_log.error("Uncaught exception in write_error", exc_info=True)
        if not self._finished:
            self.finish() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:38,代碼來源:web.py

示例14: _get_cached_version

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def _get_cached_version(cls, abs_path):
        with cls._lock:
            hashes = cls._static_hashes
            if abs_path not in hashes:
                try:
                    hashes[abs_path] = cls.get_content_version(abs_path)
                except Exception:
                    gen_log.error("Could not open static file %r", abs_path)
                    hashes[abs_path] = None
            hsh = hashes.get(abs_path)
            if hsh:
                return hsh
        return None 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:15,代碼來源:web.py

示例15: load_gettext_translations

# 需要導入模塊: from tornado.log import gen_log [as 別名]
# 或者: from tornado.log.gen_log import error [as 別名]
def load_gettext_translations(directory, domain):
    """從 `gettext` 的區域樹加載翻譯

    區域樹和係統的 ``/usr/share/locale`` 很類似, 例如::

        {directory}/{lang}/LC_MESSAGES/{domain}.mo

    讓你的應用程序翻譯有三步是必須的:

    1. 生成POT翻譯文件::

        xgettext --language=Python --keyword=_:1,2 -d mydomain file1.py file2.html etc

    2. 合並現有的POT文件::

        msgmerge old.po mydomain.po > new.po

    3. 編譯::

        msgfmt mydomain.po -o {directory}/pt_BR/LC_MESSAGES/mydomain.mo
    """
    import gettext
    global _translations
    global _supported_locales
    global _use_gettext
    _translations = {}
    for lang in os.listdir(directory):
        if lang.startswith('.'):
            continue  # skip .svn, etc
        if os.path.isfile(os.path.join(directory, lang)):
            continue
        try:
            os.stat(os.path.join(directory, lang, "LC_MESSAGES", domain + ".mo"))
            _translations[lang] = gettext.translation(domain, directory,
                                                      languages=[lang])
        except Exception as e:
            gen_log.error("Cannot load translation for '%s': %s", lang, str(e))
            continue
    _supported_locales = frozenset(list(_translations.keys()) + [_default_locale])
    _use_gettext = True
    gen_log.debug("Supported locales: %s", sorted(_supported_locales)) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:43,代碼來源:locale.py


注:本文中的tornado.log.gen_log.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。