ConsoleHandler

namespace

bhenk\logger\handle

predicates

Cloneable | Instantiable

implements

ResettableInterface | HandlerInterface

extends

AbstractHandler

hierarchy

ConsoleHandler -> AbstractHandler -> Handler

Handler class for displaying log output on console


Constructor

ConsoleHandler::__construct

predicates

public | constructor

Outputs log statements to console

This AbstractHandler is especially equipped to be used during development. See ConsoleLoggerTrait on how to switch logging to console for a particular TestCase.

The param $stack_match expects a regular expression. It can be used to suppress the amount of stacktrace elements of Throwables. Par example, the regex "/application\/(bhenk|unit)/i" will only print traces of files that have either /application/bhenk or /application/unit in their filename. Defaults to "/(.*?)/i" - all files.

The param $date_format defaults to a short “H:i:s:u”.

The param $color_scheme points to the (fully qualified) classname of a class implementing the ColorSchemeInterface and defaults to ColorSchemeDark, a dark scheme.

See also AbstractHandler.

public function __construct(
      Parameter #0 [ <optional> Monolog\Level|string|int $level = \Monolog\Level::Debug ]
      Parameter #1 [ <optional> bool $bubble = false ]
      Parameter #2 [ <optional> bool $white_line = true ]
      Parameter #3 [ <optional> ?string $stack_match = NULL ]
      Parameter #4 [ <optional> ?string $date_format = NULL ]
      Parameter #5 [ <optional> ?string $exclamation = NULL ]
      Parameter #6 [ <optional> ?string $color_scheme = NULL ]
 )
param Level | string | int $level - accepted minimum logging level
param bool $bubble - controls the bubbling process of the handler stack
param bool $white_line - print empty line above each log statement (default true)
param ?string $stack_match - reg-ex to match filenames in stack traces
param ?string $date_format - date format for printed log statements
param ?string $exclamation - thrown in when a throwable is reported
param ?string $color_scheme - color scheme for this handler

Methods

ConsoleHandler::getColorScheme

predicates

public

Get the color scheme used by this class

public function getColorScheme(): ColorSchemeInterface

ConsoleHandler::resetCount

predicates

public

Reset the log statement counter

public function resetCount(): void
return void

ConsoleHandler::handle

predicates

public

implements

HandlerInterface::handle

@inheritdoc

Handles a record

All records may be passed to this method, and the handler should discard those that it does not want to handle.

The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.

param AbstractHandler LogRecord - $record The record to handle
return bool - true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.

@inheritdoc from method HandlerInterface::handle

public function handle(
      Parameter #0 [ <required> Monolog\LogRecord $record ]
 ): bool
param LogRecord $record
return bool

ConsoleHandler::isHandling

predicates

public

implements

HandlerInterface::isHandling

inherited from

AbstractHandler::isHandling

@inheritdoc

Checks whether the given record will be handled by this handler

This is mostly done for performance reasons, to avoid calling processors for nothing.

Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.

param LogRecord $record - Partial log record having only a level initialized

@inheritdoc from method HandlerInterface::isHandling

public function isHandling(
      Parameter #0 [ <required> Monolog\LogRecord $record ]
 ): bool
param LogRecord $record
return bool

ConsoleHandler::setLevel

predicates

public

inherited from

AbstractHandler::setLevel

Sets minimum logging level at which this handler will be triggered

phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
public function setLevel(
      Parameter #0 [ <required> Monolog\Level|string|int $level ]
 ): self
param Level | string | int $level - Level or level name
return self

ConsoleHandler::getLevel

predicates

public

inherited from

AbstractHandler::getLevel

Gets minimum logging level at which this handler will be triggered

public function getLevel(): Level
return Level

ConsoleHandler::setBubble

predicates

public

inherited from

AbstractHandler::setBubble

Sets the bubbling behavior

public function setBubble(
      Parameter #0 [ <required> bool $bubble ]
 ): self
param bool $bubble - true means that this handler allows bubbling. false means that bubbling is not permitted.
return self

ConsoleHandler::getBubble

predicates

public

inherited from

AbstractHandler::getBubble

Gets the bubbling behavior

public function getBubble(): bool
return bool - true means that this handler allows bubbling. false means that bubbling is not permitted.

ConsoleHandler::reset

predicates

public

implements

ResettableInterface::reset

inherited from

AbstractHandler::reset

@inheritdoc

No DocComment found on method ResettableInterface::reset

public function reset(): void
return void

ConsoleHandler::handleBatch

predicates

public

implements

HandlerInterface::handleBatch

inherited from

Handler::handleBatch

@inheritdoc

Handles a set of records at once

@inheritdoc from method HandlerInterface::handleBatch

public function handleBatch(
      Parameter #0 [ <required> array $records ]
 ): void
param array $records
return void

ConsoleHandler::close

predicates

public

implements

HandlerInterface::close

inherited from

Handler::close

@inheritdoc

Closes the handler

Ends a log cycle and frees all resources used by the handler.

Closing a Handler means flushing all buffers and freeing any open resources/handles.

Implementations have to be idempotent (i.e. it should be possible to call close several times without breakage) and ideally handlers should be able to reopen themselves on handle() after they have been closed.

This is useful at the end of a request and will be called automatically when the object is destroyed if you extend MonologHandlerHandler.

If you are thinking of calling this method yourself, most likely you should be calling ResettableInterface::reset instead. Have a look.

@inheritdoc from method HandlerInterface::close

public function close(): void
return void

ConsoleHandler::__destruct

predicates

public

inherited from

Handler::__destruct

public function __destruct()

ConsoleHandler::__sleep

predicates

public

inherited from

Handler::__sleep

public function __sleep()

Sat, 29 Apr 2023 12:38:18 +0000