Phalcon logger
NOTE
All classes are prefixed with Phalcon
Logger\AbstractLogger ¶
-
Namespace
Phalcon\Logger
-
Uses
DateTimeImmutable
DateTimeZone
Exception
Phalcon\Logger\Adapter\AdapterInterface
Phalcon\Logger\Exception
-
Extends
-
Implements
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).
@property AdapterInterface[] $adapters @property array $excluded @property int $logLevel @property string $name @property string $timezone
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;
Methods¶
Constructor. Add an adapter to the stack. For processing we use FIFO Exclude certain adapters. Returns an adapter from the stack Returns the adapter stack array Returns the log level Returns the name of the logger Removes an adapter from the stack Sets the adapters stack overriding what is already there Sets the adapters stack overriding what is already there Adds a message to each handler for processing Converts the level from string/word to an integer Returns an array of log levels with integer to string conversionLogger\Adapter\AbstractAdapter ¶
-
Namespace
Phalcon\Logger\Adapter
-
Uses
Phalcon\Logger\Exception
Phalcon\Logger\Formatter\FormatterInterface
Phalcon\Logger\Formatter\Line
Phalcon\Logger\Item
-
Extends
-
Implements
AdapterInterface
Class AbstractAdapter
@property string $defaultFormatter @property FormatterInterface $formatter @property bool $inTransaction @property array $queue
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;
Methods¶
Destructor cleanup@throws Exception
Prevent serialization Prevent unserialization Adds a message to the queue Starts a transaction Commits the internal transaction Returns the whether the logger is currently in an active transaction or not Processes the message in the adapter Rollbacks the internal transaction Sets the message formatter Returns the formatted itemLogger\Adapter\AdapterInterface ¶
-
Namespace
Phalcon\Logger\Adapter
-
Uses
Phalcon\Logger\Formatter\FormatterInterface
Phalcon\Logger\Item
-
Extends
-
Implements
Phalcon\Logger\AdapterInterface
Interface for Phalcon\Logger adapters
Methods¶
Adds a message in the queue Starts a transaction Closes the logger Commits the internal transaction Returns the internal formatter Returns the whether the logger is currently in an active transaction or not Processes the message in the adapter Rollbacks the internal transaction Sets the message formatterLogger\Adapter\Noop¶
-
Namespace
Phalcon\Logger\Adapter
-
Uses
Phalcon\Logger\Item
-
Extends
AbstractAdapter
-
Implements
Class Noop
@package Phalcon\Logger\Adapter
Methods¶
Closes the stream Processes the message i.e. writes it to the fileLogger\Adapter\Stream¶
-
Namespace
Phalcon\Logger\Adapter
-
Uses
LogicException
Phalcon\Logger\Exception
Phalcon\Logger\Item
-
Extends
AbstractAdapter
-
Implements
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();
@property string $mode @property string $name @property array $options
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;
Methods¶
Stream constructor. Closes the stream Stream name Processes the message i.e. writes it to the file @todo to be removed when we get traitsLogger\Adapter\Syslog¶
-
Namespace
Phalcon\Logger\Adapter
-
Uses
LogicException
Phalcon\Logger\Item
Phalcon\Logger\Logger
-
Extends
AbstractAdapter
-
Implements
Class Syslog
@property string $defaultFormatter @property int $facility @property string $name @property bool $opened @property int $option
Properties¶
/**
* @var int
*/
protected $facility = ;
/**
* @var string
*/
protected $name = ;
/**
* @var bool
*/
protected $opened = false;
/**
* @var int
*/
protected $option = ;
Methods¶
Syslog constructor. Closes the logger Processes the message i.e. writes it to the syslog Open connection to system logger@link https://php.net/manual/en/function.openlog.php
Logger\AdapterFactory¶
-
Namespace
Phalcon\Logger
-
Uses
Phalcon\Factory\AbstractFactory
Phalcon\Logger\Adapter\AdapterInterface
Phalcon\Logger\Exception
-
Extends
AbstractFactory
-
Implements
Factory used to create adapters used for Logging
Methods¶
AdapterFactory constructor.public function newInstance( string $name, string $fileName, array $options = [] ): AdapterInterface;
Logger\Enum¶
-
Namespace
Phalcon\Logger
-
Uses
-
Extends
-
Implements
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;
Logger\Exception¶
-
Namespace
Phalcon\Logger
-
Uses
-
Extends
\Exception
-
Implements
Phalcon\Logger\Exception
Exceptions thrown in Phalcon\Logger will use this class
Logger\Formatter\AbstractFormatter ¶
-
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;
/**
* @var string
*/
protected $interpolatorLeft = %;
/**
* @var string
*/
protected $interpolatorRight = %;
Methods¶
Returns the date formatted for the logger.Logger\Formatter\FormatterInterface ¶
-
Namespace
Phalcon\Logger\Formatter
-
Uses
Phalcon\Logger\Item
-
Extends
-
Implements
Phalcon\Logger\FormatterInterface
This interface must be implemented by formatters in Phalcon\Logger
Methods¶
Applies a format to an itemLogger\Formatter\Json¶
-
Namespace
Phalcon\Logger\Formatter
-
Uses
JsonException
Phalcon\Logger\Item
-
Extends
AbstractFormatter
-
Implements
Formats messages using JSON encoding
Methods¶
public function __construct( string $dateFormat = string, string $interpolatorLeft = string, string $interpolatorRight = string );
Logger\Formatter\Line¶
-
Namespace
Phalcon\Logger\Formatter
-
Uses
Exception
Phalcon\Logger\Item
-
Extends
AbstractFormatter
-
Implements
Class Line
Properties¶
Methods¶
public function __construct( string $format = string, string $dateFormat = string, string $interpolatorLeft = string, string $interpolatorRight = string );
Logger\Item¶
-
Namespace
Phalcon\Logger
-
Uses
DateTimeImmutable
-
Extends
-
Implements
Phalcon\Logger\Item
Represents each item in a logging transaction
@property array $context @property string $message @property int $level @property string $levelName @property DateTimeImmutable $datetime
Properties¶
/**
* @var array
*/
protected $context;
/**
* @var DateTimeImmutable
*/
protected $dateTime;
/**
* @var string
*/
protected $message;
/**
* @var int
*/
protected $level;
/**
* @var string
*/
protected $levelName;
Methods¶
public function __construct( string $message, string $levelName, int $level, DateTimeImmutable $dateTime, array $context = [] );
Logger\Logger¶
-
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).
Methods¶
Action must be taken immediately.Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
Critical conditions.Example: Application component unavailable, unexpected exception.
Detailed debug information. System is unusable. Runtime errors that do not require immediate action but should typically be logged and monitored. Interesting events.Example: User logs in, SQL logs.
Logs with an arbitrary level. Normal but significant events. Exceptional occurrences that are not errors.Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
Logger\LoggerFactory¶
-
Namespace
Phalcon\Logger
-
Uses
DateTimeZone
Phalcon\Config\ConfigInterface
Phalcon\Factory\AbstractConfigFactory
-
Extends
AbstractConfigFactory
-
Implements
Factory creating logger objects
Properties¶
Methods¶
Factory to create an instance from a Config objectpublic function newInstance( string $name, array $adapters = [], DateTimeZone $timezone = null ): Logger;
Logger\LoggerInterface ¶
-
Namespace
Phalcon\Logger
-
Uses
Phalcon\Logger\Adapter\AdapterInterface
-
Extends
-
Implements
Interface for Phalcon based logger objects.
Methods¶
Action must be taken immediately.Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
Critical conditions.Example: Application component unavailable, unexpected exception.
Detailed debug information. System is unusable. Runtime errors that do not require immediate action but should typically be logged and monitored. Returns an adapter from the stack Returns the adapter stack array Returns the log level Returns the name of the logger Interesting events.Example: User logs in, SQL logs.
Logs with an arbitrary level. Normal but significant events. Normal but significant events.