Phalcon logger
NOTE
All classes are prefixed with Phalcon
Logger\AbstractLogger¶
Abstract Source on GitHub
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
Phalcon\Logger\AbstractLogger
Uses DateTimeImmutable · DateTimeZone · Exception · Phalcon\Logger\Adapter\AdapterInterface · Phalcon\Logger\Exceptions\AdapterNotFound · Phalcon\Logger\Exceptions\NoAdaptersConfigured · Phalcon\Time\Clock\ClockInterface · Phalcon\Time\Clock\SystemClock
Method Summary¶
public
__construct(string $name,array $adapters = [],DateTimeZone $timezone = null,ClockInterface $clock = null)
Constructor.
public
static
addAdapter(string $name,AdapterInterface $adapter)
Add an adapter to the stack. For processing we use FIFO
public
static
begin()
Starts a transaction on every (non-excluded) adapter in the stack.
public
static
commit()
Commits the transaction on every (non-excluded) adapter in the stack.
public
static
excludeAdapters( array $adapters = [] )
Exclude certain adapters.
public
AdapterInterface
getAdapter( string $name )
Returns an adapter from the stack
public
array
getAdapters()
Returns the adapter stack array
public
int
getLogLevel()
Returns the log level
public
string
getName()
Returns the name of the logger
public
static
removeAdapter( string $name )
Removes an adapter from the stack
public
static
rollback()
Rolls back the transaction on every (non-excluded) adapter in the stack.
public
static
setAdapters( array $adapters )
Sets the adapters stack overriding what is already there
public
static
setLogLevel( int $level )
Sets the minimum log level for the logger.
protected
bool
addMessage(int $level,string $message,array $context = [])
Adds a message to each handler for processing
protected
int
getLevelNumber( mixed $level )
Converts the level from string/word to an integer
protected
array
getLevels()
Returns an array of log levels with integer to string conversion
Constants¶
int
ALERT = 2
int
CRITICAL = 1
int
CUSTOM = 8
Default threshold and fallback sink. It sits between DEBUG (7) and
TRACE (9) in the ordering, so the default log level excludes TRACE.
It is also the fallback for unknown message levels and invalid
setLogLevel() values.
int
DEBUG = 7
int
EMERGENCY = 0
int
ERROR = 3
int
INFO = 6
int
NOTICE = 5
int
TRACE = 9
int
WARNING = 4
Properties¶
protected
AdapterInterface[]
$adapters = []
The adapter stack
protected
ClockInterface
$clock
Clock used to timestamp log items
protected
array
$excluded = []
The excluded adapters for this log process
protected
int
$logLevel = 8
Minimum log level for the logger
protected
string
$name = ""
protected
DateTimeZone
$timezone
Methods¶
__construct()¶
public function __construct(
string $name,
array $adapters = [],
DateTimeZone $timezone = null,
ClockInterface $clock = null
);
Constructor.
addAdapter()¶
Add an adapter to the stack. For processing we use FIFO
begin()¶
Starts a transaction on every (non-excluded) adapter in the stack.
commit()¶
Commits the transaction on every (non-excluded) adapter in the stack.
excludeAdapters()¶
Exclude certain adapters.
getAdapter()¶
Returns an adapter from the stack
getAdapters()¶
Returns the adapter stack array
getLogLevel()¶
Returns the log level
getName()¶
Returns the name of the logger
removeAdapter()¶
Removes an adapter from the stack
rollback()¶
Rolls back the transaction on every (non-excluded) adapter in the stack.
setAdapters()¶
Sets the adapters stack overriding what is already there
setLogLevel()¶
Sets the minimum log level for the logger.
An unknown level is not rejected: it is stored as CUSTOM, which sits between DEBUG and TRACE in the ordering, so the threshold becomes "everything except TRACE".
addMessage()¶
Adds a message to each handler for processing
getLevelNumber()¶
Converts the level from string/word to an integer
getLevels()¶
Returns an array of log levels with integer to string conversion
Logger\AdapterFactory¶
Class Source on GitHub
Factory used to create adapters used for Logging
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Logger\AdapterFactory
Uses Phalcon\Factory\AbstractFactory · Phalcon\Logger\Adapter\AdapterInterface · Phalcon\Logger\Exception
Method Summary¶
public
__construct( array $services = [] )
AdapterFactory constructor.
public
AdapterInterface
newInstance(string $name,string $fileName,array $options = [])
Create a new instance of the adapter
protected
string
getExceptionClass()
protected
array
getServices()
Returns the available adapters
Methods¶
__construct()¶
AdapterFactory constructor.
newInstance()¶
public function newInstance(
string $name,
string $fileName,
array $options = []
): AdapterInterface;
Create a new instance of the adapter
getExceptionClass()¶
getServices()¶
Returns the available adapters
Logger\Adapter\AbstractAdapter¶
Abstract Source on GitHub
Class AbstractAdapter
@property string $defaultFormatter @property FormatterInterface $formatter @property bool $inTransaction @property array $queue
Phalcon\Logger\Adapter\AbstractAdapter- implementsPhalcon\Logger\Adapter\AdapterInterface
Uses Phalcon\Logger\Exceptions\DeserializationFailed · Phalcon\Logger\Exceptions\SerializationFailed · Phalcon\Logger\Exceptions\TransactionAlreadyActive · Phalcon\Logger\Exceptions\TransactionNotActive · Phalcon\Logger\Formatter\FormatterInterface · Phalcon\Logger\Formatter\Line · Phalcon\Logger\Item
Method Summary¶
public
__destruct()
Destructor cleanup
public
array
__serialize()
Prevent serialization
public
void
__unserialize( array $data )
Prevent unserialization
public
AdapterInterface
add( Item $item )
Adds a message to the queue
public
AdapterInterface
begin()
Starts a transaction
public
bool
close()
Closes the logger
public
AdapterInterface
commit()
Commits the internal transaction
public
FormatterInterface
getFormatter()
public
int
getQueueLimit()
Returns the configured transaction-queue cap (0 = unlimited)
public
bool
inTransaction()
Returns the whether the logger is currently in an active transaction or
public
void
process( Item $item )
Processes the message in the adapter
public
AdapterInterface
rollback()
Rollbacks the internal transaction
public
AdapterInterface
setFormatter( FormatterInterface $formatter )
Sets the message formatter
public
AdapterInterface
setQueueLimit( int $queueLimit )
Sets the maximum number of items retained in the transaction
protected
string
getFormattedItem( Item $item )
Returns the formatted item
Properties¶
protected
string
$defaultFormatter = "Phalcon\\Logger\\Formatter\\Line"
Name of the default formatter class
protected
FormatterInterface|null
$formatter = null
Formatter
protected
bool
$inTransaction = false
Tells if there is an active transaction or not
protected
array
$queue = []
Array with messages queued in the transaction
protected
int
$queueLimit = 0
Maximum number of items retained in the transaction queue.
0 (default) keeps the original unbounded behavior; a positive
value drops the oldest queued item FIFO before a new one is
appended in add().
Methods¶
__destruct()¶
Destructor cleanup
Throwing from a destructor is fatal during script shutdown, so an open transaction is auto-committed here (flushing the queued items) rather than throwing.
__serialize()¶
Prevent serialization
__unserialize()¶
Prevent unserialization
add()¶
Adds a message to the queue
begin()¶
Starts a transaction
close()¶
Closes the logger
commit()¶
Commits the internal transaction
getFormatter()¶
getQueueLimit()¶
Returns the configured transaction-queue cap (0 = unlimited)
inTransaction()¶
Returns the whether the logger is currently in an active transaction or not
process()¶
Processes the message in the adapter
rollback()¶
Rollbacks the internal transaction
setFormatter()¶
Sets the message formatter
setQueueLimit()¶
Sets the maximum number of items retained in the transaction queue. 0 disables the cap (the default; preserves the original unbounded behavior).
getFormattedItem()¶
Returns the formatted item
Logger\Adapter\AdapterInterface¶
Interface Source on GitHub
Phalcon\Logger\AdapterInterface
Interface for Phalcon\Logger adapters
Phalcon\Contracts\Logger\Adapter\AdapterPhalcon\Logger\Adapter\AdapterInterface
Uses Phalcon\Contracts\Logger\Adapter\Adapter
Logger\Adapter\Exceptions\FileOpenFailed¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Adapter\Exceptions\FileOpenFailed
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Adapter\Exceptions\InvalidStreamMode¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Adapter\Exceptions\InvalidStreamMode
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Adapter\Exceptions\SyslogOpenFailed¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Adapter\Exceptions\SyslogOpenFailed
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Adapter\Noop¶
Class Source on GitHub
Class Noop
@package Phalcon\Logger\Adapter
Phalcon\Logger\Adapter\AbstractAdapterPhalcon\Logger\Adapter\Noop
Uses Phalcon\Logger\Item
Method Summary¶
public
bool
close()
Closes the stream
public
void
process( Item $item )
Processes the message i.e. writes it to the file
Methods¶
close()¶
Closes the stream
process()¶
Processes the message i.e. writes it to the file
Logger\Adapter\Stream¶
Class Source on GitHub
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\Enum::ERROR, 'This is an error');
$logger->error('This is another error');
$logger->close();
@property resource|null $handler @property string $mode @property string $name
Phalcon\Logger\Adapter\AbstractAdapterPhalcon\Logger\Adapter\Stream
Uses Phalcon\Logger\Adapter\Exceptions\FileOpenFailed · Phalcon\Logger\Adapter\Exceptions\InvalidStreamMode · Phalcon\Logger\Item
Method Summary¶
public
__construct(string $name,array $options = [])
Stream constructor.
public
bool
close()
Closes the stream
public
string
getName()
Stream name
public
void
process( Item $item )
Processes the message i.e. writes it to the file
protected
bool
phpFclose( mixed $handle )
@todo to be removed when we get traits
protected
phpFopen(string $filename,string $mode)
@todo to be removed when we get traits
protected
phpFwrite(mixed $handle,string $message)
@todo to be removed when we get traits
Properties¶
protected
resource|null
$handler = null
Stream handler resource
protected
string
$mode = "ab"
The file open mode. Defaults to 'ab'
protected
string
$name
Stream name
Methods¶
__construct()¶
Stream constructor.
close()¶
Closes the stream
getName()¶
Stream name
process()¶
Processes the message i.e. writes it to the file
phpFclose()¶
@todo to be removed when we get traits
phpFopen()¶
@todo to be removed when we get traits
phpFwrite()¶
@todo to be removed when we get traits
Logger\Adapter\Syslog¶
Class Source on GitHub
Class Syslog
@property string $defaultFormatter @property int $facility @property string $name @property bool $opened @property int $option
Phalcon\Logger\Adapter\AbstractAdapterPhalcon\Logger\Adapter\Syslog
Uses Phalcon\Logger\Adapter\Exceptions\SyslogOpenFailed · Phalcon\Logger\Enum · Phalcon\Logger\Item
Method Summary¶
public
__construct(string $name,array $options = [])
Syslog constructor.
public
bool
close()
Closes the logger
public
void
process( Item $item )
Processes the message i.e. writes it to the syslog
protected
bool
openlog(string $ident,int $option,int $facility)
Open connection to system logger
Properties¶
protected
int
$facility = 0
protected
string
$name = ""
protected
bool
$opened = false
protected
int
$option = 0
Methods¶
__construct()¶
Syslog constructor.
close()¶
Closes the logger
process()¶
Processes the message i.e. writes it to the syslog
openlog()¶
Open connection to system logger
@link https://php.net/manual/en/function.openlog.php
Logger\Enum¶
Class Source on GitHub
Log Level Enum constants
Phalcon\Logger\Enum
Constants¶
int
ALERT = 2
int
CRITICAL = 1
int
CUSTOM = 8
int
DEBUG = 7
int
EMERGENCY = 0
int
ERROR = 3
int
INFO = 6
int
NOTICE = 5
int
TRACE = 9
int
WARNING = 4
Logger\Exception¶
Class Source on GitHub
Phalcon\Logger\Exception
Exceptions thrown in Phalcon\Logger will use this class
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Adapter\Exceptions\FileOpenFailedPhalcon\Logger\Adapter\Exceptions\InvalidStreamModePhalcon\Logger\Adapter\Exceptions\SyslogOpenFailedPhalcon\Logger\Exceptions\AdapterNotFoundPhalcon\Logger\Exceptions\DeserializationFailedPhalcon\Logger\Exceptions\NoAdaptersConfiguredPhalcon\Logger\Exceptions\SerializationFailedPhalcon\Logger\Exceptions\TransactionAlreadyActivePhalcon\Logger\Exceptions\TransactionNotActive
Logger\Exceptions\AdapterNotFound¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\AdapterNotFound
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Exceptions\DeserializationFailed¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\DeserializationFailed
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Exceptions\NoAdaptersConfigured¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\NoAdaptersConfigured
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Exceptions\SerializationFailed¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\SerializationFailed
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Exceptions\TransactionAlreadyActive¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\TransactionAlreadyActive
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Exceptions\TransactionNotActive¶
Class Source on GitHub
\ExceptionPhalcon\Logger\ExceptionPhalcon\Logger\Exceptions\TransactionNotActive
Uses Phalcon\Logger\Exception
Method Summary¶
Methods¶
__construct()¶
Logger\Formatter\AbstractFormatter¶
Abstract Source on GitHub
Class AbstractFormatter
Phalcon\Support\Helper\Str\AbstractStrPhalcon\Logger\Formatter\AbstractFormatter- implementsPhalcon\Logger\Formatter\FormatterInterface
Uses DateTimeImmutable · Phalcon\Logger\Item · Phalcon\Support\Helper\Str\AbstractStr
Method Summary¶
public
string
getDateFormat()
public
void
setDateFormat( string $format )
protected
string
getFormattedDate( Item $item )
Returns the date formatted for the logger.
protected
string
getInterpolatedMessage(Item $item,string $message)
Properties¶
protected
string
$dateFormat = "c"
Default date format
protected
string
$interpolatorLeft = "%"
protected
string
$interpolatorRight = "%"
Methods¶
getDateFormat()¶
setDateFormat()¶
getFormattedDate()¶
Returns the date formatted for the logger.
getInterpolatedMessage()¶
Logger\Formatter\FormatterInterface¶
Interface Source on GitHub
Phalcon\Logger\FormatterInterface
This interface must be implemented by formatters in Phalcon\Logger
Phalcon\Contracts\Logger\Formatter\FormatterPhalcon\Logger\Formatter\FormatterInterface
Uses Phalcon\Contracts\Logger\Formatter\Formatter
Logger\Formatter\Json¶
Class Source on GitHub
Formats messages using JSON encoding
Phalcon\Support\Helper\Str\AbstractStrPhalcon\Logger\Formatter\AbstractFormatterPhalcon\Logger\Formatter\Json
Uses JsonException · Phalcon\Logger\Item
Method Summary¶
public
__construct(string $dateFormat = "c",string $interpolatorLeft = "%",string $interpolatorRight = "%")
Json constructor.
public
string
format( Item $item )
Applies a format to a message before sent it to the internal log
Methods¶
__construct()¶
public function __construct(
string $dateFormat = "c",
string $interpolatorLeft = "%",
string $interpolatorRight = "%"
);
Json constructor.
format()¶
Applies a format to a message before sent it to the internal log
Logger\Formatter\Line¶
Class Source on GitHub
Class Line
Phalcon\Support\Helper\Str\AbstractStrPhalcon\Logger\Formatter\AbstractFormatterPhalcon\Logger\Formatter\Line
Uses Exception · Phalcon\Logger\Item
Method Summary¶
public
__construct(string $format = "[%date%][%level%] %message%",string $dateFormat = "c",string $interpolatorLeft = "%",string $interpolatorRight = "%")
Line constructor.
public
string
format( Item $item )
Applies a format to a message before sent it to the internal log
public
string
getFormat()
Return the format applied to each message
public
static
setFormat( string $format )
Set the format applied to each message
Properties¶
protected
string
$format
Format applied to each message
Methods¶
__construct()¶
public function __construct(
string $format = "[%date%][%level%] %message%",
string $dateFormat = "c",
string $interpolatorLeft = "%",
string $interpolatorRight = "%"
);
Line constructor.
format()¶
Applies a format to a message before sent it to the internal log
getFormat()¶
Return the format applied to each message
setFormat()¶
Set the format applied to each message
Logger\Item¶
Class Source on GitHub
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
Phalcon\Logger\Item
Uses DateTimeImmutable
Method Summary¶
public
__construct(string $message,string $levelName,int $level,DateTimeImmutable $dateTime,array $context = [])
Item constructor.
public
array
getContext()
public
DateTimeImmutable
getDateTime()
public
int
getLevel()
public
string
getLevelName()
public
string
getMessage()
Properties¶
protected
array
$context = []
protected
DateTimeImmutable
$dateTime
protected
int
$level
protected
string
$levelName
protected
string
$message
Methods¶
__construct()¶
public function __construct(
string $message,
string $levelName,
int $level,
DateTimeImmutable $dateTime,
array $context = []
);
Item constructor.
getContext()¶
getDateTime()¶
getLevel()¶
getLevelName()¶
getMessage()¶
Logger\Logger¶
Class Source on GitHub
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).
Phalcon\Logger\AbstractLoggerPhalcon\Logger\Logger- implementsPhalcon\Logger\LoggerInterface
Uses Exception · Phalcon\Logger\Exception
Method Summary¶
public
void
alert(string $message,array $context = [])
Action must be taken immediately.
public
void
critical(string $message,array $context = [])
Critical conditions.
public
void
debug(string $message,array $context = [])
Detailed debug information.
public
void
emergency(string $message,array $context = [])
System is unusable.
public
void
error(string $message,array $context = [])
Runtime errors that do not require immediate action but should typically
public
void
info(string $message,array $context = [])
Interesting events.
public
void
log(mixed $level,string $message,array $context = [])
Logs with an arbitrary level.
public
void
notice(string $message,array $context = [])
Normal but significant events.
public
void
trace(string $message,array $context = [])
Extra-verbose diagnostic output.
public
void
warning(string $message,array $context = [])
Exceptional occurrences that are not errors.
Methods¶
alert()¶
Action must be taken immediately.
Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
critical()¶
Critical conditions.
Example: Application component unavailable, unexpected exception.
debug()¶
Detailed debug information.
emergency()¶
System is unusable.
error()¶
Runtime errors that do not require immediate action but should typically be logged and monitored.
info()¶
Interesting events.
Example: User logs in, SQL logs.
log()¶
Logs with an arbitrary level.
An unknown level (a typo or an unmapped value) is not rejected; it maps to the CUSTOM level and is logged, rather than raising an exception.
notice()¶
Normal but significant events.
trace()¶
Extra-verbose diagnostic output.
Use for high-frequency, fine-grained events such as raw socket frames, HTTP response bodies, or internal state transitions that are too noisy for DEBUG.
warning()¶
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¶
Class Source on GitHub
Factory creating logger objects
Phalcon\Factory\AbstractConfigFactoryPhalcon\Logger\LoggerFactory
Uses DateTimeZone · Phalcon\Config\ConfigInterface · Phalcon\Factory\AbstractConfigFactory
Method Summary¶
public
__construct( AdapterFactory $factory )
public
Logger
load( mixed $config )
Factory to create an instance from a Config object
public
Logger
newInstance(string $name,array $adapters = [],DateTimeZone $timezone = null)
Returns a Logger object
protected
mixed
getArrVal(array $collection,mixed $index,mixed $defaultValue = null)
@todo Remove this when we get traits
protected
string
getExceptionClass()
Methods¶
__construct()¶
load()¶
Factory to create an instance from a Config object
newInstance()¶
public function newInstance(
string $name,
array $adapters = [],
DateTimeZone $timezone = null
): Logger;
Returns a Logger object
getArrVal()¶
@todo Remove this when we get traits
getExceptionClass()¶
Logger\LoggerInterface¶
Interface Source on GitHub
Interface for Phalcon based logger objects.
Phalcon\Contracts\Logger\LoggerPhalcon\Logger\LoggerInterface
Uses Phalcon\Contracts\Logger\Logger