Last updated: August 12th, 2023

Messages in the Stoic:PHP logging system are the basic structure that represents logging information. The PSR-3 methods all produce messages behind the scenes which are then fed to any appenders so they can be output.

Message Class

The Message class provides log message, level, and timestamp information to give necessary context for an entry in the logging system.


public string $level String value of message's log level public string $message Interpolated string value of log message private DateTimeInterface $timestamp Immutable DateTime value marking when the message was generated (incl. microseconds) private static array $validLevels Collection of valid level values for checking initialization values


public Message __construct(string $level, string $message) Instantiates a new Message object, validating the log level and marking the timestamp public DateTimeInterface getTimestamp() Returns the immutable timestamp value so it can't be overwritten public string[] __toArray() Returns the Message information as a simplified array public string __toJson() Returns the Message information as a simplified JSON string public string[] jsonSerialize() Returns array of Message information for json_encode public string __toString() Returns the Message information as a simplified string

MessageDispatch Class

The MessageDispatch class is used to provide collections of Message objects for consumption by appenders.


public Message[] $messages Collection of any messages returned by the Logger instance


public void initialize(Message[] $input) Initializes the dispatch message collection


For examples, please see the 'Messages' section of the Examples page.

Further Reading

Next Up

Continue to read about examples, or visit the Table of Contents.