Log
MMO\core\events · 1 symbol · generated 30 Sep 2026
Log
Log.php:18A single log entry -- carries a level (one of the iLogLevel flags), a printf-style message + context, where it originated (file/line, and an optional call stack), and renders itself either as a plain apache-log-style line (__toString) or as a JSON-serializable structure (jsonSerialize).
- Namespace
MMO\core\events- Implements
- iEvent, iStoppableEvent, iLogLevel, JsonSerializable, Stringable
- Uses traits
- tEvent, tStoppableEvent
Index
| code readonly | ||
| context readonly | ||
| file readonly | ||
| line readonly | ||
| Listeners static | ||
| message readonly | ||
| num readonly | a unique, per-request, incrementing number (starts from 1), useful to tell same-timestamp entries apart. | |
| stopped | ||
| time readonly | unix timestamp (seconds) this entry was created at. | |
| time_ms readonly | the sub-second part of $time, in microseconds (0-999999) -- despite the name, NOT milliseconds. | |
| traces | ||
| AddListener($handler, $order) static | Register a listener directly (as opposed to ConnectListeners's attribute-based discovery). | |
| clearTraces() | Discard $traces (e.g. | |
| ConnectListeners($obj) static | Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. | |
| DisconnectListeners($obj) static | Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class. | |
| dispatch() | Invoke every GetListeners listener with $this. | |
| FromException($exception, $context, $level) static | Build a Log entry from a caught exception, using the exception's own message and stack trace. | |
| getLevel() | ||
| GetListeners() static | Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep … | |
| getMessage($withOrigin) | ||
| getOrigin() | ||
| getTraceAsString($separator) | ||
| HasListener($handler) static | ||
| isPropagationStopped() | ||
| jsonSerialize() | ||
| RemoveListener($handler) static | Remove the last added handler from the listeners. | |
| Send($args) static | Construct a new instance of this class with $args, then dispatch it to every listener. | |
| SetListenerOrder($handler, $order) static | Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here). | |
| stopPropagation() | Prevent any remaining listener in the current dispatch chain from being called. | |
| __clone() | A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance. | |
| __construct($code, $message, $context) | ||
| __toString() |
Properties11
code
readonly- Type
- int
context
readonly- Type
- array
file
readonly- Type
- string
line
readonly- Type
- int
Listeners
static- Type
- array
message
readonlynum
readonlya unique, per-request, incrementing number (starts from 1), useful to tell same-timestamp entries apart.
- Type
- int
stopped
time
readonlyunix timestamp (seconds) this entry was created at.
- Type
- int
time_ms
readonlythe sub-second part of $time, in microseconds (0-999999) -- despite the name, NOT milliseconds.
- Type
- int
traces
- Type
- array
Methods21
AddListener($handler, $order)
statictEvent.php:62Register a listener directly (as opposed to ConnectListeners's attribute-based discovery).
| $handler | callable | called as $handler($eventInstance) when this event class is Send / dispatch-ed |
| $order = 0 | int | listeners run in ascending order (lower first); listeners with an equal order run in the order they were added |
| returns | void |
clearTraces()
Log.php:182Discard $traces (e.g. to shrink a Log entry before storing/transmitting it).
| returns | void |
ConnectListeners($obj)
statictEvent.php:37Scan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class. connect does the actual reflection/registration.
DisconnectListeners($obj)
statictEvent.php:49Undo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.
dispatch()
tEvent.php:153Invoke every GetListeners listener with $this. If the class also implements PSR-14's StoppableEventInterface, dispatch stops early as soon as isPropagationStopped() becomes true.
| returns | static | $this, for chaining |
FromException($exception, $context, $level)
staticLog.php:121Build a Log entry from a caught exception, using the exception's own message and stack trace.
| $exception | Throwable | |
| $context = [] | extra context (e.g. ['origin' => $this]) -- 'exception' is set for you. | |
| $level = self::CRITICAL | the iLogLevel level to log at (TRACE is always added, to capture $exception's trace) | |
| returns | self |
getLevel()
Log.php:192GetListeners()
statictEvent.php:123Collect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep insertion order).
| returns | array | [[callable $handler, int $order], ...] |
getMessage($withOrigin)
Log.php:157| $withOrigin = true | bool | if true (default) and an 'origin' was given in the context, prefix the message with it. |
| returns | string | the message, resolved against $context (printf-style, via printfd) |
getOrigin()
Log.php:187getTraceAsString($separator)
Log.php:165HasListener($handler)
statictEvent.php:109| $handler | callable | object | either the exact callable passed to AddListener, or (for a [$obj, $methodName] listener registered via ConnectListeners) just the object, to check whether any of its methods are currently listening |
| returns | bool |
isPropagationStopped()
tStoppableEvent.php:21| returns | bool | true once stopPropagation has been called on this instance |
jsonSerialize()
Log.php:127| returns | mixed | the data used when this Log is JSON-encoded (level, num, time, file, line, message, traces). |
RemoveListener($handler)
statictEvent.php:91Remove the last added handler from the listeners.
Send($args)
statictEvent.php:143Construct a new instance of this class with $args, then dispatch it to every listener.
SetListenerOrder($handler, $order)
statictEvent.php:75Change the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).
stopPropagation()
tStoppableEvent.php:29Prevent any remaining listener in the current dispatch chain from being called.
| returns |
__clone()
tStoppableEvent.php:38A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.
| returns |
__construct($code, $message, $context)
Log.php:55| $code | a bitmask combining one iLogLevel level constant with any of its flags (e.g. TRACE) | |
| $message | string | a printf-style message (see printfd), resolved against $context |
| $context = [] | array | printf arguments, plus optional special keys: 'origin' (the object/string this log is about, used by getMessage/getOrigin), 'exception' (a \Throwable to build $traces from when TRACE is set), '$file'/'$line' (explicit origin location, overriding the auto-detected one) |
__toString()
Log.php:140| returns | string | this entry rendered as a single apache-log-style line (with a trailing newline). |
Inherited members (19)
| Constants | Declared by | Description | |
|---|---|---|---|
ALERT | iLogLevel | Alert: Action must be taken immediately. | |
ALL | iLogLevel | Mask for all | |
ALL_PLUS | iLogLevel | debug everything | |
BACKTRACE | iLogLevel | ||
CRITICAL | iLogLevel | Critical: Critical conditions. | |
DEBUG | iLogLevel | Debug: Detailed debug information. | |
DEEP | iLogLevel | debug everything with arguments | |
EMERGENCY | iLogLevel | Emergency: System is unusable. | |
ERROR | iLogLevel | Error: Runtime errors that do not require immediate action but should typically be logged and monitored. | |
ERROR_PLUS | iLogLevel | Mask for all error | |
FATAL | iLogLevel | Mask for all fatal error | |
INFO | iLogLevel | Info: Interesting events. | |
INFO_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
MEMORY | iLogLevel | include backtrace object | |
NOTICE | iLogLevel | Notice: Normal but significant events. | |
NOTICE_PLUS | iLogLevel | Mask for all errors/warning/notices/info | |
TRACE | iLogLevel | include backtrace as origins | |
WARNING | iLogLevel | Warning: Exceptional occurrences that are not errors. | |
WARNING_PLUS | iLogLevel | Mask for all errors and warnings |