Sections

Abstract Class Phalcon\Logger\Adapter\AbstractAdapter

Código fuente en GitHub

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

This file is part of the Phalcon Framework.

(c) Phalcon Team [email protected]

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;

Métodos

public function __destruct();

Destructor cleanup

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

Interface Phalcon\Logger\Adapter\AdapterInterface

Código fuente en GitHub

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

Phalcon\Logger\AdapterInterface

Interface for Phalcon\Logger adapters

Métodos

public function add( Item $item ): void;

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 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

Código fuente en GitHub

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();

Métodos

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

Código fuente en GitHub

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;

Métodos

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

Constructor. Accepts the name and some options

public function close(): bool;

Closes the stream

public function getName(): string
public function process( Item $item ): void;

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

Class Phalcon\Logger\Adapter\Syslog

Código fuente en GitHub

Namespace Phalcon\Logger\Adapter   Uses LogicException, Phalcon\Logger\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 = Syslog;

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

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

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

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

Métodos

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

Phalcon\Logger\Adapter\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

Class Phalcon\Logger\AdapterFactory

Código fuente en GitHub

Namespace Phalcon\Logger   Uses Phalcon\Factory\AbstractFactory   Extends AbstractFactory

This file is part of the Phalcon Framework.

(c) Phalcon Team [email protected]

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Métodos

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 getAdapters(): array;

//

Class Phalcon\Logger\Exception

Código fuente en GitHub

Namespace Phalcon\Logger   Extends \Phalcon\Exception

Phalcon\Logger\Exception

Exceptions thrown in Phalcon\Logger will use this class

Abstract Class Phalcon\Logger\Formatter\AbstractFormatter

Código fuente en GitHub

Namespace Phalcon\Logger\Formatter   Uses Phalcon\Logger\Logger   Implements FormatterInterface

This file is part of the Phalcon Framework.

(c) Phalcon Team [email protected]

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Métodos

public function interpolate( string $message, mixed $context = null );

Interpolates context values into the message placeholders

@see http://www.php-fig.org/psr/psr-3/ Section 1.2 Message @param string $message @param array $context

Interface Phalcon\Logger\Formatter\FormatterInterface

Código fuente en GitHub

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

Phalcon\Logger\FormatterInterface

This interface must be implemented by formatters in Phalcon\Logger

Métodos

public function format( Item $item ): string | array;

Applies a format to an item

Class Phalcon\Logger\Formatter\Json

Código fuente en GitHub

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

Phalcon\Logger\Formatter\Json

Formats messages using JSON encoding

Properties

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

Métodos

public function __construct( string $dateFormat = string ): void;

Phalcon\Logger\Formatter\Json construct

public function format( Item $item ): string;

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

public function getDateFormat(): string
public function setDateFormat( string $dateFormat )

Class Phalcon\Logger\Formatter\Line

Código fuente en GitHub

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

Phalcon\Logger\Formatter\Line

Formats messages using an one-line string

Properties

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

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

Métodos

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

Phalcon\Logger\Formatter\Line construct

public function format( Item $item ): string;

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

public function getDateFormat(): string
public function getFormat(): string
public function setDateFormat( string $dateFormat )
public function setFormat( string $format )

Class Phalcon\Logger\Formatter\Syslog

Código fuente en GitHub

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

Phalcon\Logger\Formatter\Syslog

Prepares a message to be used in a Syslog backend

Métodos

public function format( Item $item ): array;

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

Class Phalcon\Logger\Item

Código fuente en GitHub

Namespace Phalcon\Logger

Phalcon\Logger\Item

Represents each item in a logging transaction

Properties

//
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;

Métodos

public function __construct( string $message, string $name, int $type, int $time = int, mixed $context = [] );

Phalcon\Logger\Item constructor

public function getContext()
public function getMessage(): string
public function getName(): string
public function getTime(): integer
public function getType(): integer

Class Phalcon\Logger\Logger

Código fuente en GitHub

Namespace Phalcon\Logger   Uses Psr\Log\LoggerInterface, Psr\Log\InvalidArgumentException, 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);

Constantes

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;

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

/**
 * The excluded adapters for this log process
 *
 * @var AdapterInterface[]
 */
protected excluded;

Métodos

public function __construct( string $name, array $adapters = [] ): void;

Constructor.

@param string name The name of the logger @param array adapters The collection of adapters to be used for logging (default [])

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

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

@param string name The name of the adapter @param adapter The adapter to add to the stack

public function alert( mixed $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.

@param string message

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

Critical conditions.

Example: Application component unavailable, unexpected exception.

@param string message

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

Detailed debug information.

@param string message

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

System is unusable.

@param string message

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

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

@param string message

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

Exclude certain adapters.

public function getAdapter( string $name ): AdapterInterface;

Returns an adapter from the stack

@param string name The name of the adapter

@throws

public function getAdapters(): array;

Returns the adapter stack array

@return AdapterInterface[]

public function getName(): string;

Returns the name of the logger

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

Interesting events.

Example: User logs in, SQL logs.

@param string message

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

Logs with an arbitrary level.

@param mixed level @param string message

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

Normal but significant events.

@param string message

public function removeAdapter( string $name ): Logger;

Removes an adapter from the stack

@param string name The name of the adapter

@throws <Logger\Exception>

public function setAdapters( array $adapters ): Logger;

Sets the adapters stack overriding what is already there

@param array adapters An array of adapters

public function warning( mixed $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.

@param string message

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

Adds a message to each handler for processing

@param int level @param string message

@throws <Logger\Exception>

protected function getLevels(): array;

Returns an array of log levels with integer to string conversion

Class Phalcon\Logger\LoggerFactory

Código fuente en GitHub

Namespace Phalcon\Logger   Uses Phalcon\Config\Config, Phalcon\Helper\Arr, Phalcon\Logger\Logger, Phalcon\Logger\AdapterFactory

PhalconNG\Logger\LoggerFactory

Logger factory

Properties

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

Métodos

public function __construct( AdapterFactory $factory );

//

public function load( mixed $config ): mixed;

Factory to create an instace from a Config object

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

Returns a Logger object

@param string $name @param array $adapters

@return Logger