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
$_filters
private
array<string|int, mixed>
$_filters
= []
$_format
private
IFormat
$_format
$_parent
private
ILogger|null
$_parent
= null
$_stdErr
private
mixed
$_stdErr
$_stdOut
private
mixed
$_stdOut
$applicationName
private
string|null
$applicationName
= null
$batchSize
private
int
$batchSize
$endPoint
private
string
$endPoint
$httpClient
private
IHttpClient
$httpClient
$logBatch
private
array<string|int, mixed>
$logBatch
= []
$timeout
private
int
$timeout
$token
private
string
$token
Methods
__construct()
public
__construct(IFormat $format) : mixed
Parameters
- $format : IFormat
addFilter()
Adds a logging filter.
public
addFilter(IFilter $filter) : bool
Parameters
- $filter : IFilter
Return values
boolclose()
Closes the destination and sends any remaining batched logs.
public
close() : void
getParent()
Gets the parent logger.
public
getParent() : ILogger
Return values
ILoggergetStdErr()
public
getStdErr() : mixed
getStdOut()
public
getStdOut() : mixed
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
Return values
bool —True if configuration is valid
removeFilter()
Removes a logging filter.
public
removeFilter(IFilter $removeFilter) : bool
Parameters
- $removeFilter : IFilter
Return values
boolsetFileHandles()
Maps STDERR and STDOUT to file handles in non-CLI environments.
public
setFileHandles() : void
setFormat()
Sets the formatter.
public
setFormat(IFormat $format) : void
Parameters
- $format : IFormat
setParent()
Sets the parent logger.
public
setParent(ILogger $logger) : void
Parameters
- $logger : ILogger
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
IFormatsendToNightwatch()
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