:right-sidebar: True Logger =================================================================== .. currentmodule:: gi.repository.Soup .. class:: Logger(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Implemented Interfaces: :class:`~gi.repository.Soup.SessionFeature` Debug logging support :obj:`~gi.repository.Soup.Logger` watches a :obj:`~gi.repository.Soup.Session` and logs the HTTP traffic that it generates, for debugging purposes. Many applications use an environment variable to determine whether or not to use :obj:`~gi.repository.Soup.Logger`\, and to determine the amount of debugging output. To use :obj:`~gi.repository.Soup.Logger`\, first create a logger with :obj:`~gi.repository.Logger.new`\, optionally configure it with :obj:`~gi.repository.Logger.set_request_filter`\, :obj:`~gi.repository.Logger.set_response_filter`\, and :obj:`~gi.repository.Logger.set_printer`\, and then attach it to a session (or multiple sessions) with :obj:`~gi.repository.Session.add_feature`\. By default, the debugging output is sent to ``stdout``\, and looks something like: .. code-block:: :dedent: > POST /unauth HTTP/1.1 > Soup-Debug-Timestamp: 1200171744 > Soup-Debug: SoupSession 1 (0x612190), SoupMessage 1 (0x617000), GSocket 1 (0x612220) > Host: localhost > Content-Type: text/plain > Connection: close < HTTP/1.1 201 Created < Soup-Debug-Timestamp: 1200171744 < Soup-Debug: SoupMessage 1 (0x617000) < Date: Sun, 12 Jan 2008 21:02:24 GMT < Content-Length: 0 The ``Soup-Debug-Timestamp`` line gives the time (as a ``time_t``\) when the request was sent, or the response fully received. The ``Soup-Debug`` line gives further debugging information about the :obj:`~gi.repository.Soup.Session`\, :obj:`~gi.repository.Soup.Message`\, and :obj:`~gi.repository.Gio.Socket` involved; the hex numbers are the addresses of the objects in question (which may be useful if you are running in a debugger). The decimal IDs are simply counters that uniquely identify objects across the lifetime of the :obj:`~gi.repository.Soup.Logger`\. In particular, this can be used to identify when multiple messages are sent across the same connection. Currently, the request half of the message is logged just before the first byte of the request gets written to the network (from the :obj:`~gi.repository.Soup.Message.signals.starting` signal). The response is logged just after the last byte of the response body is read from the network (from the :obj:`~gi.repository.Soup.Message.signals.got_body` or :obj:`~gi.repository.Soup.Message.signals.got_informational` signal), which means that the :obj:`~gi.repository.Soup.Message.signals.got_headers` signal, and anything triggered off it (such as :obj:`~gi.repository.Soup.Message`\::authenticate) will be emitted *before* the response headers are actually logged. If the response doesn't happen to trigger the :obj:`~gi.repository.Soup.Message.signals.got_body` nor :obj:`~gi.repository.Soup.Message.signals.got_informational` signals due to, for example, a cancellation before receiving the last byte of the response body, the response will still be logged on the event of the :obj:`~gi.repository.Soup.Message.signals.finished` signal. Constructors ------------ .. rst-class:: interim-class .. class:: Logger :no-index: .. classmethod:: new(level: ~gi.repository.Soup.LoggerLogLevel) -> ~gi.repository.Soup.Logger Creates a new :obj:`~gi.repository.Soup.Logger` with the given debug level. If you need finer control over what message parts are and aren't logged, use :obj:`~gi.repository.Logger.set_request_filter` and :obj:`~gi.repository.Logger.set_response_filter`\. :param level: the debug level Methods ------- .. rst-class:: interim-class .. class:: Logger :no-index: .. method:: get_max_body_size() -> int Get the maximum body size for ``logger``\. .. method:: set_max_body_size(max_body_size: int) -> None Sets the maximum body size for ``logger`` (-1 means no limit). :param max_body_size: the maximum body size to log .. method:: set_printer(printer: ~typing.Callable[[~gi.repository.Soup.Logger, ~gi.repository.Soup.LoggerLogLevel, int, str, ~typing.Any], None], printer_data: ~typing.Any = None) -> None Sets up an alternate log printing routine, if you don't want the log to go to ``stdout``\. :param printer: the callback for printing logging output :param printer_data: data to pass to the callback .. method:: set_request_filter(request_filter: ~typing.Callable[[~gi.repository.Soup.Logger, ~gi.repository.Soup.Message, ~typing.Any], ~gi.repository.Soup.LoggerLogLevel], filter_data: ~typing.Any = None) -> None Sets up a filter to determine the log level for a given request. For each HTTP request ``logger`` will invoke ``request_filter`` to determine how much (if any) of that request to log. (If you do not set a request filter, ``logger`` will just always log requests at the level passed to :obj:`~gi.repository.Logger.new`\.) :param request_filter: the callback for request debugging :param filter_data: data to pass to the callback .. method:: set_response_filter(response_filter: ~typing.Callable[[~gi.repository.Soup.Logger, ~gi.repository.Soup.Message, ~typing.Any], ~gi.repository.Soup.LoggerLogLevel], filter_data: ~typing.Any = None) -> None Sets up a filter to determine the log level for a given response. For each HTTP response ``logger`` will invoke ``response_filter`` to determine how much (if any) of that response to log. (If you do not set a response filter, ``logger`` will just always log responses at the level passed to :obj:`~gi.repository.Logger.new`\.) :param response_filter: the callback for response debugging :param filter_data: data to pass to the callback Properties ---------- .. rst-class:: interim-class .. class:: Logger :no-index: .. attribute:: props.level :type: ~gi.repository.Soup.LoggerLogLevel The type of the None singleton. .. attribute:: props.max_body_size :type: int The type of the None singleton.