Sections

Abstract Class Phalcon\Logger\AbstractLogger

Source on GitHub

Namespace Phalcon\Logger   Uses DateTimeImmutable, DateTimeZone, Exception, Phalcon\Logger\Exception, Phalcon\Logger\Adapter\AdapterInterface

Abstract Logger Class

Abstract logger class, providing common functionality. A formatter interface is available as well as an adapter one. Adapters can be created easily using the built in AdapterFactory. A LoggerFactory is also available that allows developers to create new instances of the Logger or load them from config files (see Phalcon\Config\Config object).

Constants

const ALERT = 2;
const CRITICAL = 1;
const CUSTOM = 8;
const DEBUG = 7;
const EMERGENCY = 0;
const ERROR = 3;
const INFO = 6;
const NOTICE = 5;
const WARNING = 4;

Properties

/**
 * The adapter stack
 *
 * @var AdapterInterface[]
 */
protected adapters;

/**
 * The excluded adapters for this log process
 *
 * @var array
 */
protected excluded;

/**
 * Minimum log level for the logger
 *
 * @var int
 */
protected logLevel = 8;

/**
 * @var string
 */
protected name = ;

/**
 * @var DateTimeZone
 */
protected timezone;

Metody

public function __construct( string $name, array $adapters = [], DateTimeZone $timezone = null );

Constructor.

public function addAdapter( string $name, AdapterInterface $adapter ): AbstractLogger;

Add an adapter to the stack. For processing we use FIFO

public function excludeAdapters( array $adapters = [] ): AbstractLogger;

Exclude certain adapters.

public function getAdapter( string $name ): AdapterInterface;

Returns an adapter from the stack

public function getAdapters(): array;

Returns the adapter stack array

public function getLogLevel(): int;

Returns the log level

public function getName(): string;

Returns the name of the logger

public function removeAdapter( string $name ): AbstractLogger;

Removes an adapter from the stack

public function setAdapters( array $adapters ): AbstractLogger;

Sets the adapters stack overriding what is already there

public function setLogLevel( int $level ): AbstractLogger;

Sets the adapters stack overriding what is already there

protected function addMessage( int $level, string $message, array $context = [] ): bool;

Adds a message to each handler for processing

protected function getLevelNumber( mixed $level ): int;

Converts the level from string/word to an integer

protected function getLevels(): array;

Returns an array of log levels with integer to string conversion

Abstract Class Phalcon\Logger\Adapter\AbstractAdapter

Source on GitHub

Namespace Phalcon\Logger\Adapter   Uses Phalcon\Logger\Exception, Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Formatter\Line, Phalcon\Logger\Item   Implements AdapterInterface

Class AbstractAdapter

Properties

/**
 * Name of the default formatter class
 *
 * @var string
 */
protected defaultFormatter = Phalcon\\Logger\Formatter\\Line;

/**
 * Formatter
 *
 * @var FormatterInterface|null
 */
protected formatter;

/**
 * Tells if there is an active transaction or not
 *
 * @var bool
 */
protected inTransaction = false;

/**
 * Array with messages queued in the transaction
 *
 * @var array
 */
protected queue;

Metody

public function __destruct();

Destructor cleanup

@throws Exception

public function __serialize(): array;

Prevent serialization

public function __unserialize( array $data ): void;

Prevent unserialization

public function add( Item $item ): AdapterInterface;

Adds a message to the queue

public function begin(): AdapterInterface;

Starts a transaction

public function commit(): AdapterInterface;

Commits the internal transaction

public function getFormatter(): FormatterInterface;
public function inTransaction(): bool;

Returns the whether the logger is currently in an active transaction or not

abstract public function process( Item $item ): void;

Processes the message in the adapter

public function rollback(): AdapterInterface;

Rollbacks the internal transaction

public function setFormatter( FormatterInterface $formatter ): AdapterInterface;

Sets the message formatter

protected function getFormattedItem( Item $item ): string;

Returns the formatted item

Interface Phalcon\Logger\Adapter\AdapterInterface

Source on GitHub

Namespace Phalcon\Logger\Adapter   Uses Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Item

Phalcon\Logger\AdapterInterface

Interface for Phalcon\Logger adapters

Metody

public function add( Item $item ): AdapterInterface;

Adds a message in the queue

public function begin(): AdapterInterface;

Starts a transaction

public function close(): bool;

Closes the logger

public function commit(): AdapterInterface;

Commits the internal transaction

public function getFormatter(): FormatterInterface;

Returns the internal formatter

public function inTransaction(): bool;

Returns the whether the logger is currently in an active transaction or not

public function process( Item $item ): void;

Processes the message in the adapter

public function rollback(): AdapterInterface;

Rollbacks the internal transaction

public function setFormatter( FormatterInterface $formatter ): AdapterInterface;

Sets the message formatter

Class Phalcon\Logger\Adapter\Noop

Source on GitHub

Namespace Phalcon\Logger\Adapter   Uses Phalcon\Logger\Item   Extends AbstractAdapter

Class Noop

@package Phalcon\Logger\Adapter

Metody

public function close(): bool;

Closes the stream

public function process( Item $item ): void;

Processes the message i.e. writes it to the file

Class Phalcon\Logger\Adapter\Stream

Source on GitHub

Namespace Phalcon\Logger\Adapter   Uses LogicException, Phalcon\Logger\Exception, Phalcon\Logger\Item   Extends AbstractAdapter

Phalcon\Logger\Adapter\Stream

Adapter to store logs in plain text files

$logger = new \Phalcon\Logger\Adapter\Stream('app/logs/test.log');

$logger->log('This is a message');
$logger->log(\Phalcon\Logger::ERROR, 'This is an error');
$logger->error('This is another error');

$logger->close();

Properties

/**
 * The file open mode. Defaults to 'ab'
 *
 * @var string
 */
protected mode = ab;

/**
 * Stream name
 *
 * @var string
 */
protected name;

/**
 * Path options
 *
 * @var array
 */
protected options;

Metody

public function __construct( string $name, array $options = [] );

Stream constructor.

public function close(): bool;

Closes the stream

public function getName(): string;

Stream name

public function process( Item $item ): void;

Processes the message i.e. writes it to the file

protected function phpFopen( string $filename, string $mode );

@todo to be removed when we get traits

Class Phalcon\Logger\Adapter\Syslog

Source on GitHub

Namespace Phalcon\Logger\Adapter   Uses LogicException, Phalcon\Logger\Item, Phalcon\Logger\Logger   Extends AbstractAdapter

Class Syslog

Properties

/**
 * @var int
 */
protected facility = 0;

/**
 * @var string
 */
protected name = ;

/**
 * @var bool
 */
protected opened = false;

/**
 * @var int
 */
protected option = 0;

Metody

public function __construct( string $name, array $options = [] );

Syslog constructor.

public function close(): bool;

Closes the logger

public function process( Item $item ): void;

Processes the message i.e. writes it to the syslog

protected function openlog( string $ident, int $option, int $facility ): bool;

Open connection to system logger

@link https://php.net/manual/en/function.openlog.php

Class Phalcon\Logger\AdapterFactory

Source on GitHub

Namespace Phalcon\Logger   Uses Phalcon\Factory\AbstractFactory, Phalcon\Logger\Adapter\AdapterInterface, Phalcon\Logger\Exception   Extends AbstractFactory

Factory used to create adapters used for Logging

Metody

public function __construct( array $services = [] );

AdapterFactory constructor.

public function newInstance( string $name, string $fileName, array $options = [] ): AdapterInterface;

Create a new instance of the adapter

protected function getExceptionClass(): string;
protected function getServices(): array;

Returns the available adapters

Class Phalcon\Logger\Enum

Source on GitHub

Namespace Phalcon\Logger

Log Level Enum constants

Constants

const ALERT = 2;
const CRITICAL = 1;
const CUSTOM = 8;
const DEBUG = 7;
const EMERGENCY = 0;
const ERROR = 3;
const INFO = 6;
const NOTICE = 5;
const WARNING = 4;

Class Phalcon\Logger\Exception

Source on GitHub

Namespace Phalcon\Logger   Extends \Exception

Phalcon\Logger\Exception

Exceptions thrown in Phalcon\Logger will use this class

Abstract Class Phalcon\Logger\Formatter\AbstractFormatter

Source on GitHub

Namespace Phalcon\Logger\Formatter   Uses DateTimeImmutable, Phalcon\Logger\Item, Phalcon\Support\Helper\Str\AbstractStr   Extends AbstractStr   Implements FormatterInterface

Class AbstractFormatter

Properties

/**
 * Default date format
 *
 * @var string
 */
protected dateFormat = c;

Metody

public function getDateFormat(): string;

Return the default date format

public function setDateFormat( string $format ): void;

Set the default date format

protected function getFormattedDate( Item $item ): string;

Returns the date formatted for the logger.

Interface Phalcon\Logger\Formatter\FormatterInterface

Source on GitHub

Namespace Phalcon\Logger\Formatter   Uses Phalcon\Logger\Item

Phalcon\Logger\FormatterInterface

This interface must be implemented by formatters in Phalcon\Logger

Metody

public function format( Item $item ): string;

Applies a format to an item

Class Phalcon\Logger\Formatter\Json

Source on GitHub

Namespace Phalcon\Logger\Formatter   Uses JsonException, Phalcon\Logger\Item   Extends AbstractFormatter

Formats messages using JSON encoding

Metody

public function __construct( string $dateFormat = string );

Json constructor.

public function format( Item $item ): string;

Applies a format to a message before sent it to the internal log

Class Phalcon\Logger\Formatter\Line

Source on GitHub

Namespace Phalcon\Logger\Formatter   Uses Exception, Phalcon\Logger\Item   Extends AbstractFormatter

Class Line

Properties

/**
 * Format applied to each message
 *
 * @var string
 */
protected format;

Metody

public function __construct( string $format = string, string $dateFormat = string );

Line constructor.

public function format( Item $item ): string;

Applies a format to a message before sent it to the internal log

public function getFormat(): string;

Return the format applied to each message

public function setFormat( string $format ): Line;

Set the format applied to each message

Class Phalcon\Logger\Item

Source on GitHub

Namespace Phalcon\Logger   Uses DateTimeImmutable

Phalcon\Logger\Item

Represents each item in a logging transaction

Properties

/**
 * @var array
 */
protected context;

/**
 * @var DateTimeImmutable
 */
protected dateTime;

/**
 * @var string
 */
protected message;

/**
 * @var int
 */
protected level;

/**
 * @var string
 */
protected levelName;

Metody

public function __construct( string $message, string $levelName, int $level, DateTimeImmutable $dateTime, array $context = [] );

Item constructor.

public function getContext(): array;
public function getDateTime(): DateTimeImmutable;
public function getLevel(): int;
public function getLevelName(): string;
public function getMessage(): string;

Class Phalcon\Logger\Logger

Source on GitHub

Namespace Phalcon\Logger   Uses Exception, Phalcon\Logger\Exception   Extends AbstractLogger   Implements LoggerInterface

Phalcon Logger.

A logger, with various adapters and formatters. A formatter interface is available as well as an adapter one. Adapters can be created easily using the built-in AdapterFactory. A LoggerFactory is also available that allows developers to create new instances of the Logger or load them from config files (see Phalcon\Config\Config object).

Metody

public function alert( string $message, array $context = [] ): void;

Action must be taken immediately.

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

public function critical( string $message, array $context = [] ): void;

Critical conditions.

Example: Application component unavailable, unexpected exception.

public function debug( string $message, array $context = [] ): void;

Detailed debug information.

public function emergency( string $message, array $context = [] ): void;

System is unusable.

public function error( string $message, array $context = [] ): void;

Runtime errors that do not require immediate action but should typically be logged and monitored.

public function info( string $message, array $context = [] ): void;

Interesting events.

Example: User logs in, SQL logs.

public function log( mixed $level, string $message, array $context = [] ): void;

Logs with an arbitrary level.

public function notice( string $message, array $context = [] ): void;

Normal but significant events.

public function warning( string $message, array $context = [] ): void;

Exceptional occurrences that are not errors.

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Class Phalcon\Logger\LoggerFactory

Source on GitHub

Namespace Phalcon\Logger   Uses DateTimeZone, Phalcon\Config\ConfigInterface, Phalcon\Factory\AbstractConfigFactory   Extends AbstractConfigFactory

Factory creating logger objects

Properties

/**
 * @var AdapterFactory
 */
private adapterFactory;

Metody

public function __construct( AdapterFactory $factory );
public function load( mixed $config ): Logger;

Factory to create an instance from a Config object

public function newInstance( string $name, array $adapters = [], DateTimeZone $timezone = null ): Logger;

Returns a Logger object

protected function getArrVal( array $collection, mixed $index, mixed $defaultValue = null ): mixed;

@todo Remove this when we get traits

protected function getExceptionClass(): string;

Interface Phalcon\Logger\LoggerInterface

Source on GitHub

Namespace Phalcon\Logger   Uses Phalcon\Logger\Adapter\AdapterInterface

Interface for Phalcon based logger objects.

Metody

public function alert( string $message, array $context = [] ): void;

Action must be taken immediately.

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

public function critical( string $message, array $context = [] ): void;

Critical conditions.

Example: Application component unavailable, unexpected exception.

public function debug( string $message, array $context = [] ): void;

Detailed debug information.

public function emergency( string $message, array $context = [] ): void;

System is unusable.

public function error( string $message, array $context = [] ): void;

Runtime errors that do not require immediate action but should typically be logged and monitored.

public function getAdapter( string $name ): AdapterInterface;

Returns an adapter from the stack

public function getAdapters(): array;

Returns the adapter stack array

public function getLogLevel(): int;

Returns the log level

public function getName(): string;

Returns the name of the logger

public function info( string $message, array $context = [] ): void;

Interesting events.

Example: User logs in, SQL logs.

public function log( mixed $level, string $message, array $context = [] ): void;

Logs with an arbitrary level.

public function notice( string $message, array $context = [] ): void;

Normal but significant events.

public function warning( string $message, array $context = [] ): void;

Normal but significant events.