Neuron-PHP

DestinationBase
in package

AbstractYes

Abstract base class for all logging destinations in the Neuron logging system.

This class provides the foundation for implementing various logging outputs such as files, databases, remote services, or console output. It handles common functionality like formatting, filtering, and parent logger relationships.

Concrete implementations must implement the write() method to define how log data is actually output to their specific destination.

Key responsibilities:

  • Manages log formatters and filters
  • Handles parent logger relationships
  • Provides standard file handles for STDOUT/STDERR
  • Orchestrates the filtering and formatting pipeline
  • Defines the contract for destination-specific writing
Tags
example
class CustomDestination extends DestinationBase
{
    protected function write(string $text, Log\Data $data): void
    {
        // Custom implementation for writing log data
        file_put_contents('/var/log/custom.log', $text, FILE_APPEND);
    }
}

Table of Contents

Properties

$_filters  : array<string|int, mixed>
$_format  : IFormat
$_parent  : ILogger|null
$_stdErr  : mixed
$_stdOut  : mixed

Methods

__construct()  : mixed
addFilter()  : bool
Adds a logging filter.
close()  : void
Closes the destination if required.
getParent()  : ILogger
Gets the parent logger.
getStdErr()  : mixed
getStdOut()  : mixed
log()  : void
Handles writing the log data after filtering and formatting.
open()  : mixed
Opens the destination. Destinations may require parameters to be passed in.
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 the formatted log data to the specific destination.

Properties

Methods

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 destination. Destinations may require parameters to be passed in.

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

(PHPMD.UnusedFormalParameter)

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 the formatted log data to the specific destination.

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

This abstract method must be implemented by concrete destination classes to define how log data is actually written to their specific output target. The text has already been formatted and filtered when this method is called.

Parameters
$text : string

The formatted log message ready for output

$data : Data

The complete log data object containing metadata


        
On this page

Search results