Raydium Framework

FileLogger
in package
implements LoggerInterface

Interfaces, Classes, Traits and Enums

LoggerInterface

Table of Contents

DEFAULT_MAX_FILE_SIZE  = 10485760
DEFAULT_MAX_FILES  = 5
VALID_LOG_LEVELS  = [\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::DEBUG]
$dateFormat  : string
$enableRotation  : bool
$fileHandle  : null|resource
$logFile  : string|null
$maxFiles  : int
$maxFileSize  : int
__construct()  : mixed
Constructor to initialize the logger configuration.
__destruct()  : mixed
Destructor to ensure file handle is properly closed.
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 be logged and monitored.
info()  : void
Interesting events.
log()  : void
Logs with an arbitrary level.
notice()  : void
Normal but significant events.
setLogFile()  : void
Sets and validates the log file path.
warning()  : void
Exceptional occurrences that are not errors.
closeFileHandle()  : void
Closes the file handle if open.
formatLogEntry()  : string
Formats a log entry with timestamp, level, and message.
interpolate()  : string
Interpolates context values into the message placeholders.
rotateLogFile()  : void
Rotates the current log file.
shouldRotate()  : bool
Checks if log rotation is needed.
validateAndSetLogFile()  : void
Validates and sets the log file path.
writeLogEntry()  : void
Writes log entry to file or error_log.

Constants

DEFAULT_MAX_FILE_SIZE

private mixed DEFAULT_MAX_FILE_SIZE = 10485760

DEFAULT_MAX_FILES

private mixed DEFAULT_MAX_FILES = 5

VALID_LOG_LEVELS

private mixed VALID_LOG_LEVELS = [\Psr\Log\LogLevel::EMERGENCY, \Psr\Log\LogLevel::ALERT, \Psr\Log\LogLevel::CRITICAL, \Psr\Log\LogLevel::ERROR, \Psr\Log\LogLevel::WARNING, \Psr\Log\LogLevel::NOTICE, \Psr\Log\LogLevel::INFO, \Psr\Log\LogLevel::DEBUG]

Properties

$fileHandle

private null|resource $fileHandle = null

Methods

__construct()

Constructor to initialize the logger configuration.

public __construct([null|string $logFile = null ][, int $maxFileSize = self::DEFAULT_MAX_FILE_SIZE ][, int $maxFiles = self::DEFAULT_MAX_FILES ][, bool $enableRotation = true ][, string $dateFormat = 'Y-m-d H:i:s' ]) : mixed
Parameters
$logFile : null|string = null

Path to log file. If null, uses error_log()

$maxFileSize : int = self::DEFAULT_MAX_FILE_SIZE

Maximum file size before rotation (bytes)

$maxFiles : int = self::DEFAULT_MAX_FILES

Maximum number of rotated files to keep

$enableRotation : bool = true

Whether to enable log rotation

$dateFormat : string = 'Y-m-d H:i:s'

Date format for log entries

Tags
throws
InvalidArgumentException

If log file path is invalid

throws
RuntimeException

If log file cannot be created or accessed

Return values
mixed

__destruct()

Destructor to ensure file handle is properly closed.

public __destruct() : mixed
Return values
mixed

alert()

Action must be taken immediately.

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

critical()

Critical conditions.

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

debug()

Detailed debug information.

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

emergency()

System is unusable.

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

error()

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

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

info()

Interesting events.

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

log()

Logs with an arbitrary level.

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

Log level

$message : string

Log message

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

Context data for interpolation

Tags
throws
InvalidArgumentException

If the log level is invalid

Return values
void

notice()

Normal but significant events.

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

setLogFile()

Sets and validates the log file path.

public setLogFile(string $logFile) : void
Parameters
$logFile : string

Path to log file

Tags
throws
InvalidArgumentException

If path is invalid or unsafe

throws
RuntimeException

If file cannot be created or accessed

Return values
void

warning()

Exceptional occurrences that are not errors.

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

closeFileHandle()

Closes the file handle if open.

private closeFileHandle() : void
Return values
void

formatLogEntry()

Formats a log entry with timestamp, level, and message.

private formatLogEntry(string $level, string $message) : string
Parameters
$level : string

Log level

$message : string

Interpolated message

Return values
string

Formatted log entry

interpolate()

Interpolates context values into the message placeholders.

private interpolate(string $message[, array<string|int, mixed> $context = [] ]) : string
Parameters
$message : string

Message with placeholders

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

Context data

Return values
string

Interpolated message

rotateLogFile()

Rotates the current log file.

private rotateLogFile() : void
Return values
void

shouldRotate()

Checks if log rotation is needed.

private shouldRotate() : bool
Return values
bool

True if rotation is needed

validateAndSetLogFile()

Validates and sets the log file path.

private validateAndSetLogFile(string $logFile) : void
Parameters
$logFile : string

Path to log file

Tags
throws
InvalidArgumentException

If path is invalid or unsafe

throws
RuntimeException

If file cannot be created or accessed

Return values
void

writeLogEntry()

Writes log entry to file or error_log.

private writeLogEntry(string $logEntry) : void
Parameters
$logEntry : string

Formatted log entry

Tags
throws
RuntimeException

If file writing fails

Return values
void

Search results