Learn R Programming

log4r (version 0.5.0)

http_appender: Send logs over HTTP

Description

Send logs in the body of HTTP requests. Responses with status code 400 or above will trigger errors.

Requires the httr package.

Usage

http_appender(url, method = "POST", layout = default_log_layout(), ...)

Value

An appender: a function with the interface function(level, ...)

that submits its arguments to url and returns invisible(NULL).

Arguments

url

The URL to submit messages to.

method

The HTTP method to use, usually "POST" or "GET".

layout

A layout function taking a level parameter and additional arguments corresponding to the message.

...

Further arguments passed on to httr::POST().

See Also

appenders for more information on Appenders.

Examples

Run this code
if (FALSE) {
# POST messages to localhost.
appender <- http_appender("localhost")
appender("INFO", "Message.")

# POST JSON-encoded messages.
appender <- http_appender(
  "localhost", method = "POST", layout = default_log_layout(),
  httr::content_type_json()
)
appender("INFO", "Message.")
}

Run the code above in your browser using DataLab