gi-soup-2.4.24: Libsoup bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellSafe-Inferred
LanguageHaskell2010

GI.Soup.Objects.Logger

Description

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 loggerNew, optionally configure it with loggerSetRequestFilter, loggerSetResponseFilter, and loggerSetPrinter, and then attach it to a session (or multiple sessions) with sessionAddFeature.

By default, the debugging output is sent to <literal>stdout</literal>, and looks something like:

<informalexample><screen> > POST /unauth HTTP/1.1 > Soup-Debug-Timestamp: 1200171744 > Soup-Debug: SoupSessionAsync 1 (0x612190), SoupMessage 1 (0x617000), SoupSocket 1 (0x612220) > Host: localhost > Content-Type: text/plain > Connection: close > > This is a test.

&lt; HTTP/1.1 201 Created &lt; Soup-Debug-Timestamp: 1200171744 &lt; Soup-Debug: SoupMessage 1 (0x617000) &lt; Date: Sun, 12 Jan 2008 21:02:24 GMT &lt; Content-Length: 0 </screen></informalexample>

The <literal>Soup-Debug-Timestamp</literal> line gives the time (as a <type>time_t</type>) when the request was sent, or the response fully received.

The <literal>Soup-Debug</literal> 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 starting signal), which means that if you have not made the complete request body available at that point, it will not be logged.

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 authenticate) will be emitted <emphasis>before</emphasis> 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 finished signal.

Synopsis

Exported types

newtype Logger Source #

Memory-managed wrapper type.

Constructors

Logger (ManagedPtr Logger) 

Instances

Instances details
Eq Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

Methods

(==) :: Logger -> Logger -> Bool #

(/=) :: Logger -> Logger -> Bool #

GObject Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

ManagedPtrNewtype Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

Methods

toManagedPtr :: Logger -> ManagedPtr Logger

TypedObject Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

Methods

glibType :: IO GType

HasParentTypes Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

IsGValue (Maybe Logger) Source #

Convert Logger to and from GValue. See toGValue and fromGValue.

Instance details

Defined in GI.Soup.Objects.Logger

Methods

gvalueGType_ :: IO GType

gvalueSet_ :: Ptr GValue -> Maybe Logger -> IO ()

gvalueGet_ :: Ptr GValue -> IO (Maybe Logger)

type ParentTypes Logger Source # 
Instance details

Defined in GI.Soup.Objects.Logger

type ParentTypes Logger = '[Object, SessionFeature]

class (GObject o, IsDescendantOf Logger o) => IsLogger o Source #

Type class for types which can be safely cast to Logger, for instance with toLogger.

Instances

Instances details
(GObject o, IsDescendantOf Logger o) => IsLogger o Source # 
Instance details

Defined in GI.Soup.Objects.Logger

toLogger :: (MonadIO m, IsLogger o) => o -> m Logger Source #

Cast to Logger, for types for which this is known to be safe. For general casts, use castTo.

Methods

attach

loggerAttach Source #

Arguments

:: (HasCallStack, MonadIO m, IsLogger a, IsSession b) 
=> a

logger: a Logger

-> b

session: a Session

-> m () 

Deprecated: Use sessionAddFeature instead.

Sets logger to watch session and print debug information for its messages.

(The session will take a reference on logger, which will be removed when you call loggerDetach, or when the session is destroyed.)

detach

loggerDetach Source #

Arguments

:: (HasCallStack, MonadIO m, IsLogger a, IsSession b) 
=> a

logger: a Logger

-> b

session: a Session

-> m () 

Deprecated: Use sessionRemoveFeature instead.

Stops logger from watching session.

new

loggerNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> LoggerLogLevel

level: the debug level

-> Int32

maxBodySize: the maximum body size to output, or -1

-> m Logger

Returns: a new Logger

Creates a new Logger with the given debug level. If level is LoggerLogLevelBody, maxBodySize gives the maximum number of bytes of the body that will be logged. (-1 means "no limit".)

If you need finer control over what message parts are and aren't logged, use loggerSetRequestFilter and loggerSetResponseFilter.

setPrinter

loggerSetPrinter Source #

Arguments

:: (HasCallStack, MonadIO m, IsLogger a) 
=> a

logger: a Logger

-> LoggerPrinter

printer: the callback for printing logging output

-> m () 

Sets up an alternate log printing routine, if you don't want the log to go to <literal>stdout</literal>.

setRequestFilter

loggerSetRequestFilter Source #

Arguments

:: (HasCallStack, MonadIO m, IsLogger a) 
=> a

logger: a Logger

-> LoggerFilter

requestFilter: the callback for request debugging

-> m () 

Sets up a filter to determine the log level for a given request. For each HTTP request logger will invoke requestFilter 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 loggerNew.)

setResponseFilter

loggerSetResponseFilter Source #

Arguments

:: (HasCallStack, MonadIO m, IsLogger a) 
=> a

logger: a Logger

-> LoggerFilter

responseFilter: the callback for response debugging

-> m () 

Sets up a filter to determine the log level for a given response. For each HTTP response logger will invoke responseFilter 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 loggerNew.)

Properties

level

The level of logging output

Since: 2.56

constructLoggerLevel :: (IsLogger o, MonadIO m) => LoggerLogLevel -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “level” property. This is rarely needed directly, but it is used by new.

getLoggerLevel :: (MonadIO m, IsLogger o) => o -> m LoggerLogLevel Source #

Get the value of the “level” property. When overloading is enabled, this is equivalent to

get logger #level

setLoggerLevel :: (MonadIO m, IsLogger o) => o -> LoggerLogLevel -> m () Source #

Set the value of the “level” property. When overloading is enabled, this is equivalent to

set logger [ #level := value ]

maxBodySize

If Logger:level is LoggerLogLevelBody, this gives the maximum number of bytes of the body that will be logged. (-1 means "no limit".)

Since: 2.56

constructLoggerMaxBodySize :: (IsLogger o, MonadIO m) => Int32 -> m (GValueConstruct o) Source #

Construct a GValueConstruct with valid value for the “max-body-size” property. This is rarely needed directly, but it is used by new.

getLoggerMaxBodySize :: (MonadIO m, IsLogger o) => o -> m Int32 Source #

Get the value of the “max-body-size” property. When overloading is enabled, this is equivalent to

get logger #maxBodySize

setLoggerMaxBodySize :: (MonadIO m, IsLogger o) => o -> Int32 -> m () Source #

Set the value of the “max-body-size” property. When overloading is enabled, this is equivalent to

set logger [ #maxBodySize := value ]