Documentation

CMonoLogger
in package
implements ILogger

A simplified factory and wrapper for Monolog.

This class simplifies Monolog's setup by allowing the user to specify a handler type and its parameters directly in the constructor.

Table of Contents

Interfaces

ILogger
Interface for logging operations, compliant with PSR-3 log levels.

Properties

$monolog  : Logger

Methods

__construct()  : mixed
Constructor for CMonoLogger.
AddLog()  : void
Logs a request and its corresponding response with a custom format.
Alert()  : void
Action must be taken immediately.
Critical()  : void
Critical conditions.
Debug()  : void
Detailed debug information.
Emergency()  : void
System is unusable.
Error()  : void
Runtime errors that do not require immediate action but should typically be logged and monitored.
Info()  : void
Interesting events.
Notice()  : void
Normal but significant events.
Warning()  : void
Exceptional occurrences that are not errors.
CreateRotatingFileHandler()  : RotatingFileHandler
Creates a RotatingFileHandler instance for daily log rotation.
CreateSlackHandler()  : SlackWebhookHandler
Creates a SlackWebhookHandler instance for Slack notifications.
CreateSmtpHandler()  : SymfonyMailerHandler
Creates a SymfonyMailerHandler instance for sending logs via email.
CreateStreamHandler()  : StreamHandler
Creates a StreamHandler instance for file-based logging.
CreateTelegramHandler()  : TelegramBotHandler
Creates a TelegramBotHandler instance for Telegram notifications.

Properties

$monolog

private Logger $monolog

The underlying Monolog logger instance

Methods

__construct()

Constructor for CMonoLogger.

public __construct([string $channel = 'app' ][, string $handler_type = 'Stream' ][, array<string, mixed> $handler_params = [] ]) : mixed

Initializes a Monolog instance with a specific handler based on the provided type.

Parameters
$channel : string = 'app'

The name of the logger channel.

$handler_type : string = 'Stream'

The type of handler to use (e.g., 'Stream', 'Smtp', 'Slack').

$handler_params : array<string, mixed> = []

The parameters for the chosen handler.

Tags
throws
InvalidArgumentException

If the handler type is not supported or required parameters are missing.

AddLog()

Logs a request and its corresponding response with a custom format.

public AddLog(CUser $user, CRequest|null $request, CResponse|null $response) : void
Parameters
$user : CUser

The user object associated with the request.

$request : CRequest|null

The request object containing input data.

$response : CResponse|null

The response object containing output data.

Alert()

Action must be taken immediately.

public Alert(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Critical()

Critical conditions.

public Critical(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Debug()

Detailed debug information.

public Debug(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Emergency()

System is unusable.

public Emergency(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Error()

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

public Error(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Info()

Interesting events.

public Info(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Notice()

Normal but significant events.

public Notice(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

Warning()

Exceptional occurrences that are not errors.

public Warning(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
$message : string

The log message.

$context : array<string|int, mixed> = []

The log context.

CreateRotatingFileHandler()

Creates a RotatingFileHandler instance for daily log rotation.

private CreateRotatingFileHandler(array<string, mixed> $params) : RotatingFileHandler
Parameters
$params : array<string, mixed>

The parameters for the handler.

Tags
throws
InvalidArgumentException

If the 'filename' parameter is missing.

Return values
RotatingFileHandler —

The configured handler instance.

CreateSlackHandler()

Creates a SlackWebhookHandler instance for Slack notifications.

private CreateSlackHandler(array<string, mixed> $params) : SlackWebhookHandler
Parameters
$params : array<string, mixed>

The parameters for the handler.

Tags
throws
InvalidArgumentException

If 'webhook_url' or 'channel' parameters are missing.

Return values
SlackWebhookHandler —

The configured handler instance.

CreateSmtpHandler()

Creates a SymfonyMailerHandler instance for sending logs via email.

private CreateSmtpHandler(array<string, mixed> $params) : SymfonyMailerHandler

Requires symfony/mailer package to be installed.

Parameters
$params : array<string, mixed>

The parameters for the handler.

Tags
throws
InvalidArgumentException

If required parameters are missing.

Return values
SymfonyMailerHandler —

The configured handler instance.

CreateStreamHandler()

Creates a StreamHandler instance for file-based logging.

private CreateStreamHandler(array<string, mixed> $params) : StreamHandler
Parameters
$params : array<string, mixed>

The parameters for the handler.

Tags
throws
InvalidArgumentException

If the 'path' parameter is missing.

Return values
StreamHandler —

The configured handler instance.

CreateTelegramHandler()

Creates a TelegramBotHandler instance for Telegram notifications.

private CreateTelegramHandler(array<string, mixed> $params) : TelegramBotHandler
Parameters
$params : array<string, mixed>

The parameters for the handler.

Tags
throws
InvalidArgumentException

If 'api_key' or 'chat_id' parameters are missing.

Return values
TelegramBotHandler —

The configured handler instance.


        
On this page

Search results