Neuron-PHP

Nightwatch extends DestinationBase
in package

Sends log data to Laravel Nightwatch monitoring service.

This destination transmits logs to the Laravel Nightwatch API for centralized monitoring and analysis. It supports authentication via API tokens, configurable endpoints, and optional log batching for improved performance.

Table of Contents

Constants

DEFAULT_ENDPOINT  = 'https://nightwatch.laravel.com/api/logs'
Default Nightwatch API endpoint

Properties

$_filters  : array<string|int, mixed>
$_format  : IFormat
$_parent  : ILogger|null
$_stdErr  : mixed
$_stdOut  : mixed
$applicationName  : string|null
$batchSize  : int
$endPoint  : string
$httpClient  : IHttpClient
$logBatch  : array<string|int, mixed>
$timeout  : int
$token  : string

Methods

__construct()  : mixed
addFilter()  : bool
Adds a logging filter.
close()  : void
Closes the destination and sends any remaining batched logs.
getParent()  : ILogger
Gets the parent logger.
getStdErr()  : mixed
getStdOut()  : mixed
log()  : void
Handles writing the log data after filtering and formatting.
open()  : bool
Opens the Nightwatch destination with configuration parameters.
removeFilter()  : bool
Removes a logging filter.
setFileHandles()  : void
Maps STDERR and STDOUT to file handles in non-CLI environments.
setFormat()  : void
Sets the formatter.
setParent()  : void
Sets the parent logger.
write()  : void
Writes log data to the Nightwatch service.
flushBatch()  : void
Sends accumulated logs to Nightwatch and clears the batch.
getFormat()  : IFormat
Gets the current format object.
sendToNightwatch()  : void
Sends log data to the Nightwatch API endpoint.

Constants

DEFAULT_ENDPOINT

Default Nightwatch API endpoint

private mixed DEFAULT_ENDPOINT = 'https://nightwatch.laravel.com/api/logs'

Properties

$applicationName

private string|null $applicationName = null

$logBatch

private array<string|int, mixed> $logBatch = []

Methods

close()

Closes the destination and sends any remaining batched logs.

public close() : void

log()

Handles writing the log data after filtering and formatting.

public log(mixed $text, mixed $level[, mixed $context = [] ]) : void
Parameters
$text : mixed
  • Output that has been run through the formatter.
$level : mixed
  • Text output level.
$context : mixed = []
  • Optional context array

open()

Opens the Nightwatch destination with configuration parameters.

public open(array<string|int, mixed> $params) : bool
Parameters
$params : array<string|int, mixed>

Configuration array with the following keys:

  • 'token' (required): Nightwatch API authentication token
  • 'endpoint' (optional): API endpoint URL (defaults to Nightwatch service)
  • 'batch_size' (optional): Number of logs to batch before sending (default: 1)
  • 'timeout' (optional): Request timeout in seconds (default: 10)
  • 'application_name' (optional): Application identifier
  • 'http_client' (optional): IHttpClient instance for testing
Tags
throws
Exception

If token is missing or endpoint URL is invalid

Return values
bool

True if configuration is valid

removeFilter()

Removes a logging filter.

public removeFilter(IFilter $removeFilter) : bool
Parameters
$removeFilter : IFilter
Return values
bool

setFileHandles()

Maps STDERR and STDOUT to file handles in non-CLI environments.

public setFileHandles() : void

write()

Writes log data to the Nightwatch service.

protected write(string $text, Data $data) : void

If batching is enabled, logs are accumulated until the batch size is reached before being sent. Otherwise, logs are sent immediately.

Parameters
$text : string

The formatted log text (typically JSON from Nightwatch format)

$data : Data

The original log data object

flushBatch()

Sends accumulated logs to Nightwatch and clears the batch.

private flushBatch() : void

getFormat()

Gets the current format object.

private getFormat() : IFormat

This is a helper method to access the private format property.

Return values
IFormat

sendToNightwatch()

Sends log data to the Nightwatch API endpoint.

private sendToNightwatch(array<string|int, mixed> $logs) : void
Parameters
$logs : array<string|int, mixed>

Array of JSON-formatted log entries


        
On this page

Search results