Documentation

MessageFormatter
in package

Message formatter used in various places in the framework

Format messages using a template that can contain the the following variables:

  • {request}: Full HTTP request message
  • {response}: Full HTTP response message
  • {ts}: Timestamp
  • {host}: Host of the request
  • {method}: Method of the request
  • {url}: URL of the request
  • {host}: Host of the request
  • {protocol}: Request protocol
  • {version}: Protocol version
  • {resource}: Resource of the request (path + query + fragment)
  • {port}: Port of the request
  • {hostname}: Hostname of the machine that sent the request
  • {code}: Status code of the response (if available)
  • {phrase}: Reason phrase of the response (if available)
  • {curl_error}: Curl error message (if available)
  • {curl_code}: Curl error code (if available)
  • {curl_stderr}: Curl standard error (if available)
  • {connect_time}: Time in seconds it took to establish the connection (if available)
  • {total_time}: Total transaction time in seconds for last transfer (if available)
  • {req_header_*}: Replace * with the lowercased name of a request header to add to the message
  • {res_header_*}: Replace * with the lowercased name of a response header to add to the message
  • {req_body}: Request body
  • {res_body}: Response body

Table of Contents

Constants

DEBUG_FORMAT  = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{curl_stderr}"
DEFAULT_FORMAT  = "{hostname} {req_header_User-Agent} - [{ts}] \"{method} {resource} {protocol}/{version}\" {code} {res_header_Content-Length}"
SHORT_FORMAT  = '[{ts}] "{method} {resource} {protocol}/{version}" {code}'

Properties

$template  : string

Methods

__construct()  : mixed
format()  : string
Returns a formatted message
setTemplate()  : self
Set the template to use for logging

Constants

DEBUG_FORMAT

public mixed DEBUG_FORMAT = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{curl_stderr}"

DEFAULT_FORMAT

public mixed DEFAULT_FORMAT = "{hostname} {req_header_User-Agent} - [{ts}] \"{method} {resource} {protocol}/{version}\" {code} {res_header_Content-Length}"

SHORT_FORMAT

public mixed SHORT_FORMAT = '[{ts}] "{method} {resource} {protocol}/{version}" {code}'

Properties

$template

protected string $template

Template used to format log messages

Methods

__construct()

public __construct([string $template = self::DEFAULT_FORMAT ]) : mixed
Parameters
$template : string = self::DEFAULT_FORMAT

Log message template

format()

Returns a formatted message

public format(RequestInterface $request[, Response $response = null ][, CurlHandle $handle = null ][, array<string|int, mixed> $customData = array() ]) : string
Parameters
$request : RequestInterface

Request that was sent

$response : Response = null

Response that was received

$handle : CurlHandle = null

Curl handle associated with the message

$customData : array<string|int, mixed> = array()

Associative array of custom template data

Return values
string

setTemplate()

Set the template to use for logging

public setTemplate(string $template) : self
Parameters
$template : string

Log message template

Return values
self

        
On this page

Search results