Class Logger
- All Implemented Interfaces:
Proxy
,SessionFeature
SoupLogger
watches a 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
SoupLogger
, and to determine the amount of debugging output.
To use SoupLogger
, first create a logger with Logger(org.gnome.soup.LoggerLogLevel)
, optionally
configure it with setRequestFilter(org.gnome.soup.LoggerFilter)
,
setResponseFilter(org.gnome.soup.LoggerFilter)
, and setPrinter(org.gnome.soup.LoggerPrinter)
, and
then attach it to a session (or multiple sessions) with
Session.addFeature(org.gnome.soup.SessionFeature)
.
By default, the debugging output is sent to stdout
, and looks something
like:
> 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
Session
, Message
, and 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 SoupLogger
. 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
Message::starting
signal).
The response is logged just after the last byte of the response body is read
from the network (from the Message::got-body
or
Message::got-informational
signal), which means that the
Message::got-headers
signal, and anything triggered off it (such as
SoupMessage
::authenticate) will be emitted before the response headers are
actually logged.
If the response doesn't happen to trigger the Message::got-body
nor
Message::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 Message::finished
signal.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Logger.Builder<B extends Logger.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.soup.SessionFeature
SessionFeature.SessionFeatureImpl, SessionFeature.SessionFeatureInterface
-
Constructor Summary
ConstructorDescriptionLogger
(MemorySegment address) Create a Logger proxy instance for the provided memory address.Logger
(LoggerLogLevel level) Creates a newSoupLogger
with the given debug level. -
Method Summary
Modifier and TypeMethodDescriptionprotected Logger
asParent()
Returns this instance as if it were its parent type.static Logger.Builder
<? extends Logger.Builder> builder()
ALogger.Builder
object constructs aLogger
with the specified properties.int
Get the maximum body size for this Logger.static Type
getType()
Get the GType of the Logger classvoid
setMaxBodySize
(int maxBodySize) Sets the maximum body size for this Logger (-1 means no limit).void
setPrinter
(LoggerPrinter printer) Sets up an alternate log printing routine, if you don't want the log to go tostdout
.void
setRequestFilter
(LoggerFilter requestFilter) Sets up a filter to determine the log level for a given request.void
setResponseFilter
(LoggerFilter responseFilter) Sets up a filter to determine the log level for a given response.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Logger
Create a Logger proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Logger
Creates a newSoupLogger
with the given debug level.If you need finer control over what message parts are and aren't logged, use
setRequestFilter(org.gnome.soup.LoggerFilter)
andsetResponseFilter(org.gnome.soup.LoggerFilter)
.- Parameters:
level
- the debug level- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
getMaxBodySize
public int getMaxBodySize()Get the maximum body size for this Logger.- Returns:
- the maximum body size, or -1 if unlimited
-
setMaxBodySize
public void setMaxBodySize(int maxBodySize) Sets the maximum body size for this Logger (-1 means no limit).- Parameters:
maxBodySize
- the maximum body size to log
-
setPrinter
Sets up an alternate log printing routine, if you don't want the log to go tostdout
.- Parameters:
printer
- the callback for printing logging output
-
setRequestFilter
Sets up a filter to determine the log level for a given request.For each HTTP request this Logger will invoke
requestFilter
to determine how much (if any) of that request to log. (If you do not set a request filter, this Logger will just always log requests at the level passed toLogger(org.gnome.soup.LoggerLogLevel)
.)- Parameters:
requestFilter
- the callback for request debugging
-
setResponseFilter
Sets up a filter to determine the log level for a given response.For each HTTP response this Logger will invoke
responseFilter
to determine how much (if any) of that response to log. (If you do not set a response filter, this Logger will just always log responses at the level passed toLogger(org.gnome.soup.LoggerLogLevel)
.)- Parameters:
responseFilter
- the callback for response debugging
-
builder
ALogger.Builder
object constructs aLogger
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withLogger.Builder.build()
.
-