Soup.Logger

g GObject.GInterface GObject.GInterface Soup.SessionFeature Soup.SessionFeature GObject.GInterface->Soup.SessionFeature GObject.Object GObject.Object Soup.Logger Soup.Logger GObject.Object->Soup.Logger Soup.SessionFeature->Soup.Logger

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new (level)

get_max_body_size ()

set_max_body_size (max_body_size)

set_printer (printer, *printer_data)

set_request_filter (request_filter, *filter_data)

set_response_filter (response_filter, *filter_data)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Name

Type

Flags

Short Description

level

Soup.LoggerLogLevel

r/w

The level of logging output

max-body-size

int

r/w/c

The maximum body size to output

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Class Details

class Soup.Logger(**kwargs)
Bases:

GObject.Object, Soup.SessionFeature

Abstract:

No

Structure:

Soup.LoggerClass

Debug logging support

Soup.Logger watches a [class`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 Soup.Logger, and to determine the amount of debugging output.

To use Soup.Logger, first create a logger with [ctor`Logger`.new], optionally configure it with [method`Logger`.set_request_filter], [method`Logger`.set_response_filter], and [method`Logger`.set_printer], and then attach it to a session (or multiple sessions) with [method`Session`.add_feature].

By default, the debugging output is sent to stdout, and looks something like:

```

POST /unauth HTTP/1.1 Soup-Debug-Timestamp: 1200171744 Soup-Debug: Soup.Session 1 (0x612190), Soup.Message 1 (0x617000), Gio.Socket 1 (0x612220) Host: localhost Content-Type: text/plain Connection: close

< HTTP/1.1 201 Created < Soup-Debug-Timestamp: 1200171744 < Soup-Debug: Soup.Message 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 [class`Session`], [class`Message`], and [class`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 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 [signal`Message`:py:func:::starting<Soup.Logger.signals.starting>] signal).

The response is logged just after the last byte of the response body is read from the network (from the [signal`Message`:py:func:::got-body<Soup.Logger.signals.got_body>] or [signal`Message`:py:func:::got-informational<Soup.Logger.signals.got_informational>] signal), which means that the [signal`Message`:py:func:::got-headers<Soup.Logger.signals.got_headers>] signal, and anything triggered off it (such as Soup.Message ::authenticate) will be emitted *before* the response headers are actually logged.

If the response doesn’t happen to trigger the [signal`Message`:py:func:::got-body<Soup.Logger.signals.got_body>] nor [signal`Message`:py:func:::got-informational<Soup.Logger.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 [signal`Message`:py:func:::finished<Soup.Logger.signals.finished>] signal.

classmethod new(level)
Parameters:

level (Soup.LoggerLogLevel) – the debug level

Returns:

a new Soup.Logger

Return type:

Soup.Logger

Creates a new Soup.Logger with the given debug level.

If you need finer control over what message parts are and aren’t logged, use [method`Logger`.set_request_filter] and [method`Logger`.set_response_filter].

get_max_body_size()
Returns:

the maximum body size, or -1 if unlimited

Return type:

int

Get the maximum body size for self.

set_max_body_size(max_body_size)
Parameters:

max_body_size (int) – the maximum body size to log

Sets the maximum body size for self (-1 means no limit).

set_printer(printer, *printer_data)
Parameters:

Sets up an alternate log printing routine, if you don’t want the log to go to stdout.

set_request_filter(request_filter, *filter_data)
Parameters:
  • request_filter (Soup.LoggerFilter) – the callback for request debugging

  • filter_data (object or None) – data to pass to the callback

Sets up a filter to determine the log level for a given request.

For each HTTP request self will invoke request_filter to determine how much (if any) of that request to log. (If you do not set a request filter, self will just always log requests at the level passed to [ctor`Logger`.new].)

set_response_filter(response_filter, *filter_data)
Parameters:
  • response_filter (Soup.LoggerFilter) – the callback for response debugging

  • filter_data (object or None) – data to pass to the callback

Sets up a filter to determine the log level for a given response.

For each HTTP response self will invoke response_filter to determine how much (if any) of that response to log. (If you do not set a response filter, self will just always log responses at the level passed to [ctor`Logger`.new].)

Property Details

Soup.Logger.props.level
Name:

level

Type:

Soup.LoggerLogLevel

Default Value:

Soup.LoggerLogLevel.MINIMAL

Flags:

READABLE, WRITABLE

The level of logging output.

Soup.Logger.props.max_body_size
Name:

max-body-size

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE, CONSTRUCT

If [property`Logger`:py:data::level<Soup.Logger.props.level>] is Soup.LoggerLogLevel.BODY, this gives the maximum number of bytes of the body that will be logged. (-1 means “no limit”.)