- Phalcon\Logger
- Phalcon\Logger\Adapter\AbstractAdapter
- Phalcon\Logger\Adapter\AdapterInterface
- Phalcon\Logger\Adapter\Noop
- Phalcon\Logger\Adapter\Stream
- Phalcon\Logger\Adapter\Syslog
- Phalcon\Logger\AdapterFactory
- Phalcon\Logger\Exception
- Phalcon\Logger\Formatter\AbstractFormatter
- Phalcon\Logger\Formatter\FormatterInterface
- Phalcon\Logger\Formatter\Json
- Phalcon\Logger\Formatter\Line
- Phalcon\Logger\Item
- Phalcon\Logger\LoggerFactory
Class Phalcon\Logger
| Namespace | Phalcon | | Uses | Psr\Log\LoggerInterface, Phalcon\Logger\Adapter\AdapterInterface, Phalcon\Logger\Item, Phalcon\Logger\Exception | | Implements | LoggerInterface |
Phalcon\Logger
This component offers logging capabilities for your application. The component accepts multiple adapters, working also as a multiple logger. Phalcon\Logger implements PSR-3.
use Phalcon\Logger;
use Phalcon\Logger\Adapter\Stream;
$adapter1 = new Stream('/logs/first-log.log');
$adapter2 = new Stream('/remote/second-log.log');
$adapter3 = new Stream('/manager/third-log.log');
$logger = new Logger(
'messages',
[
'local' => $adapter1,
'remote' => $adapter2,
'manager' => $adapter3,
]
);
// Log to all adapters
$logger->error('Something went wrong');
// Log to specific adapters
$logger
->excludeAdapters(['manager'])
->info('This does not go to the "manager" logger);
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;
/**
* Minimum log level for the logger
*
* @var int
*/
protected logLevel = 8;
/**
* @var string
*/
protected name = ;
/**
* The excluded adapters for this log process
*
* @var AdapterInterface[]
*/
protected excluded;
Methods¶
Constructor. Add an adapter to the stack. For processing we use FIFO 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. Exclude certain adapters. Returns an adapter from the stack Returns the adapter stack array Returns the name of the logger Interesting events.Example: User logs in, SQL logs.
Logs with an arbitrary level. Normal but significant events. Removes an adapter from the stack Sets the adapters stack overriding what is already there Sets the log level above which we can log Exceptional occurrences that are not errors.Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
Adds a message to each handler for processing Returns an array of log levels with integer to string conversionAbstract Class Phalcon\Logger\Adapter\AbstractAdapter
| Namespace | Phalcon\Logger\Adapter | | Uses | Phalcon\Logger, Phalcon\Logger\Exception, Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Item | | Implements | AdapterInterface |
This file is part of the Phalcon Framework.
(c) Phalcon Team team@phalcon.io
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
Properties¶
/**
* Name of the default formatter class
*
* @var string
*/
protected defaultFormatter = Line;
/**
* Formatter
*
* @var FormatterInterface
*/
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 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 formatterInterface Phalcon\Logger\Adapter\AdapterInterface
| Namespace | Phalcon\Logger\Adapter | | Uses | Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Item |
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 formatterClass Phalcon\Logger\Adapter\Noop
| Namespace | Phalcon\Logger\Adapter | | Uses | Phalcon\Logger\Item | | Extends | AbstractAdapter |
Phalcon\Logger\Adapter\Noop
Adapter to store logs in plain text files
$logger = new \Phalcon\Logger\Adapter\Noop();
$logger->log(\Phalcon\Logger::ERROR, "This is an error");
$logger->error("This is another error");
$logger->close();
Methods¶
Closes the stream Processes the message i.e. writes it to the fileClass Phalcon\Logger\Adapter\Stream
| Namespace | Phalcon\Logger\Adapter | | Uses | Phalcon\Logger\Adapter, Phalcon\Logger\Exception, Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Item, UnexpectedValueException | | 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¶
/**
* Stream handler resource
*
* @var resource|null
*/
protected handler;
/**
* 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¶
Constructor. Accepts the name and some options Closes the stream Processes the message i.e. writes it to the fileClass Phalcon\Logger\Adapter\Syslog
| Namespace | Phalcon\Logger\Adapter | | Uses | LogicException, Phalcon\Helper\Arr, Phalcon\Logger, Phalcon\Logger\Adapter, Phalcon\Logger\Exception, Phalcon\Logger\Formatter\FormatterInterface, Phalcon\Logger\Item | | Extends | AbstractAdapter |
Phalcon\Logger\Adapter\Syslog
Sends logs to the system logger
use Phalcon\Logger;
use Phalcon\Logger\Adapter\Syslog;
// LOG_USER is the only valid log type under Windows operating systems
$logger = new Syslog(
"ident",
[
"option" => LOG_CONS | LOG_NDELAY | LOG_PID,
"facility" => LOG_USER,
]
);
$logger->log("This is a message");
$logger->log(Logger::ERROR, "This is an error");
$logger->error("This is another error");
Properties¶
/**
* Name of the default formatter class
*
* @var string
*/
protected defaultFormatter = Line;
/**
* @var int
*/
protected facility = 0;
/**
* @var string
*/
protected name = ;
/**
* @var bool
*/
protected opened = false;
/**
* @var int
*/
protected option = 0;
Methods¶
Phalcon\Logger\Adapter\Syslog constructor Closes the logger Processes the message i.e. writes it to the syslogClass Phalcon\Logger\AdapterFactory
| Namespace | Phalcon\Logger | | Uses | Phalcon\Factory\AbstractFactory, Phalcon\Logger\Adapter\AdapterInterface | | Extends | AbstractFactory |
This file is part of the Phalcon Framework.
(c) Phalcon Team team@phalcon.io
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
Methods¶
AdapterFactory constructor.public function newInstance( string $name, string $fileName, array $options = [] ): AdapterInterface;
Class Phalcon\Logger\Exception
| Namespace | Phalcon\Logger | | Extends | \Phalcon\Exception |
Phalcon\Logger\Exception
Exceptions thrown in Phalcon\Logger will use this class
Abstract Class Phalcon\Logger\Formatter\AbstractFormatter
| Namespace | Phalcon\Logger\Formatter | | Uses | DateTimeImmutable, DateTimeZone, Phalcon\Logger, Phalcon\Logger\Item | | Implements | FormatterInterface |
This file is part of the Phalcon Framework.
(c) Phalcon Team team@phalcon.io
For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.
Properties¶
Methods¶
Interpolates context values into the message placeholders@see https://www.php-fig.org/psr/psr-3/ Section 1.2 Message
Returns the date formatted for the logger. @todo Not using the set time from the Item since we have interface misalignment which will break semver This will change in the futureInterface Phalcon\Logger\Formatter\FormatterInterface
| Namespace | Phalcon\Logger\Formatter | | Uses | Phalcon\Logger\Item |
Phalcon\Logger\FormatterInterface
This interface must be implemented by formatters in Phalcon\Logger
Methods¶
Applies a format to an itemClass Phalcon\Logger\Formatter\Json
| Namespace | Phalcon\Logger\Formatter | | Uses | Phalcon\Helper\Json, Phalcon\Logger\Item | | Extends | AbstractFormatter |
Phalcon\Logger\Formatter\Json
Formats messages using JSON encoding
Methods¶
Phalcon\Logger\Formatter\Json construct Applies a format to a message before sent it to the internal logClass Phalcon\Logger\Formatter\Line
| Namespace | Phalcon\Logger\Formatter | | Uses | DateTime, Phalcon\Logger\Item | | Extends | AbstractFormatter |
Phalcon\Logger\Formatter\Line
Formats messages using an one-line string
Properties¶
Methods¶
Phalcon\Logger\Formatter\Line construct Applies a format to a message before sent it to the internal logClass Phalcon\Logger\Item
| Namespace | Phalcon\Logger |
Phalcon\Logger\Item
Represents each item in a logging transaction
Properties¶
/**
* Log Context
*
* @var mixed
*/
protected context;
/**
* Log message
*
* @var string
*/
protected message;
/**
* Log message
*
* @var string
*/
protected name;
/**
* Log timestamp
*
* @var integer
*/
protected time;
/**
* Log type
*
* @var integer
*/
protected type;
Methods¶
public function __construct( string $message, string $name, int $type, int $time = int, mixed $context = [] );
Class Phalcon\Logger\LoggerFactory
| Namespace | Phalcon\Logger | | Uses | Phalcon\Config, Phalcon\Config\ConfigInterface, Phalcon\Helper\Arr, Phalcon\Logger |
Phalcon\Logger\LoggerFactory
Logger factory