MessageFormatter
in package
implements
MessageFormatterInterface
Formats log messages using variable substitutions for requests, responses, and other transactional data.
The following variable substitutions are supported:
- {request}: Full HTTP request message
- {response}: Full HTTP response message
- {ts}: ISO 8601 date in GMT
- {date_iso_8601} ISO 8601 date in GMT
- {date_common_log} Apache common log date using the configured timezone.
- {host}: Host of the request
- {method}: Method of the request
- {uri}: URI of the request
- {version}: Protocol version
- {target}: Request target of the request (path + query + fragment)
- {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)
- {error}: Any error messages (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_headers}: Request headers
- {res_headers}: Response headers
- {req_body}: Request body
- {res_body}: Response body
Tags
Table of Contents
Interfaces
Constants
- CLF = '{hostname} {req_header_User-Agent} - [{date_common_log}] "{method} {target} HTTP/{version}" {code} {res_header_Content-Length}'
- Apache Common Log Format.
- DEBUG = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{error}"
- SHORT = '[{ts}] "{method} {target} HTTP/{version}" {code}'
Properties
- $template : string
Methods
- __construct() : mixed
- format() : string
- Returns a formatted message string.
- headers() : string
- Get headers from message as string
Constants
CLF
Apache Common Log Format.
public
string
CLF
= '{hostname} {req_header_User-Agent} - [{date_common_log}] "{method} {target} HTTP/{version}" {code} {res_header_Content-Length}'
Tags
DEBUG
public
mixed
DEBUG
= ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{error}"
SHORT
public
mixed
SHORT
= '[{ts}] "{method} {target} HTTP/{version}" {code}'
Properties
$template
private
string
$template
Template used to format log messages
Methods
__construct()
public
__construct([string $template = self::CLF ]) : mixed
Parameters
- $template : string = self::CLF
-
Log message template
format()
Returns a formatted message string.
public
format(RequestInterface $request[, ResponseInterface|null $response = null ][, Throwable|null $error = null ]) : string
Parameters
- $request : RequestInterface
-
Request that was sent
- $response : ResponseInterface|null = null
-
Response that was received
- $error : Throwable|null = null
-
Exception that was received
Return values
stringheaders()
Get headers from message as string
private
headers(MessageInterface $message) : string
Parameters
- $message : MessageInterface