Class Logger

All Implemented Interfaces:
SessionFeature, Proxy

@Generated("org.javagi.JavaGI") public final class Logger extends GObject implements SessionFeature

Debug logging support

Logger 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 Logger, and to determine the amount of debugging output.

To use Logger, first create a logger with Logger(), optionally configure it with setRequestFilter(LoggerFilter), setResponseFilter(LoggerFilter), and setPrinter(LoggerPrinter), and then attach it to a session (or multiple sessions) with Session.addFeature(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 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 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 Message::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.

  • Constructor Details

    • Logger

      public Logger(MemorySegment address)
      Create a Logger instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Logger

      public Logger(LoggerLogLevel level)

      Creates a new Logger with the given debug level.

      If you need finer control over what message parts are and aren't logged, use setRequestFilter(LoggerFilter) and setResponseFilter(LoggerFilter).

      Parameters:
      level - the debug level
    • Logger

      public Logger()
      Create a new Logger.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Logger class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Logger asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GObject
      Returns:
      the instance as if it were its parent type
    • getMaxBodySize

      public int getMaxBodySize()
      Get the maximum body size for 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

      public void setPrinter(@Nullable LoggerPrinter printer)
      Sets up an alternate log printing routine, if you don't want the log to go to stdout.
      Parameters:
      printer - the callback for printing logging output
    • setRequestFilter

      public void setRequestFilter(@Nullable LoggerFilter requestFilter)

      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 to Logger().)

      Parameters:
      requestFilter - the callback for request debugging
    • setResponseFilter

      public void setResponseFilter(@Nullable LoggerFilter responseFilter)

      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 to Logger().)

      Parameters:
      responseFilter - the callback for response debugging
    • builder

      public static Logger.Builder<? extends Logger.Builder> builder()
      A Logger.Builder object constructs a Logger with the specified properties. Use the various set...() methods to set properties, and finish construction with Logger.Builder.build().
      Returns:
      the builder object