final class LogChannel implements Channel

Notification channel that writes notifications to the application log.

This channel is useful for development or local environments where sending real notifications (e.g., email, SMS, Slack) is not desired. It serializes the notifiable entity and notification message into a JSON structure and writes it to the configured Logger.

Constants

private CONTROL_KEYS

The available control keys.

Methods

static array
configureLog(array $data, string $message, array $meta, string $notifiableClass, string $notificationClass)

Configures log array

static array
controlKeys()

Return the list of control keys that will be stripped from the data bag.

static array
logData(object $notifiable, Notification $notification, array $payloadArr)

Build the consolidated "data" bag for logging.

static string
logMessage(array $data, object $notifiable, string $notifiableClass, Notification $notification, string $notificationClass, string $payloadMessage)

Determine the human‑readable message to log.

static string
name()

Returns the canonical name of the channel.

static string
payloadMessage(array $payloadArr)

Extract a string message from the payload, if present.

void
send(object $notifiable, Notification $notification, mixed $payload)

Send the given notification to the log.

Details

at line 34
static private array configureLog(array $data, string $message, array $meta, string $notifiableClass, string $notificationClass)

Configures log array

Parameters

array $data

Information associated with notification.

string $message

Messages sent for logging.

array $meta

Any meta data that is available.

string $notifiableClass

The name of the notifiable class.

string $notificationClass

The name of the notification class.

Return Value

array

The log array.

at line 57
static private array controlKeys()

internal  Exposed for testing and reuse; not part of the public channel API.
 

Return the list of control keys that will be stripped from the data bag.

Return Value

array

at line 75
static private array logData(object $notifiable, Notification $notification, array $payloadArr)

Build the consolidated "data" bag for logging.

Strategy: 1) Start with the notification’s {\Core\Lib\Notifications\Notification::toArray()} result. 2) Merge in the payload array minus control keys, allowing payload to override keys from step 1 so per‑send overrides are visible.

Parameters

object $notifiable

The entity receiving the notification.

Notification $notification

The notification instance.

array $payloadArr

Payload provided to the channel.

Return Value

array

Final data bag to include under "data".

at line 111
static private string logMessage(array $data, object $notifiable, string $notifiableClass, Notification $notification, string $notificationClass, string $payloadMessage)

Determine the human‑readable message to log.

Priority: 1) Non‑null payload‑provided message (already normalized to string) 2) Notification‑provided {\Core\Lib\Notifications\Notification::toLog()} string 3) "data['message']" if present and string 4) A synthesized "Notification X for Y" fallback

Parameters

array $data

Final data bag (may contain 'message').

object $notifiable

The notifiable entity.

string $notifiableClass

Class name of the notifiable.

Notification $notification

The notification instance.

string $notificationClass

Class name of the notification.

string $payloadMessage

Message extracted from payload, if any.

Return Value

string

Human‑readable message to include in the log entry.

at line 138
static string name()

Returns the canonical name of the channel.

Used by the notification dispatcher to identify this channel when the notification's via() method includes "log".

Return Value

string

The name of the channel.

at line 152
static private string payloadMessage(array $payloadArr)

Extract a string message from the payload, if present.

Accepts either a string or any JSON‑serializable value under the "message" key. Non‑string values are JSON‑encoded with unicode and slashes preserved.

Parameters

array $payloadArr

The payload provided to the channel.

Return Value

string

A normalized message string or null if no message key exists.

at line 180
void send(object $notifiable, Notification $notification, mixed $payload)

Send the given notification to the log.

If the notification implements a toLog() method, its return value will be used as the log message. Otherwise, if the notification implements toArray(), the array will be logged. If neither method exists, the notifiable itself is cast to string.

The output is encoded as JSON and written at INFO level.

Parameters

object $notifiable

The user/entity receiving the notification.

Notification $notification

The notification instance.

mixed $payload

Usually the result of toX() (array/DTO)

Return Value

void