Oihana PHP System

MonoLogManager extends LoggerManager

A logger manager.

Table of Contents

Constants

DEFAULT_EXTENSION  = '.log'
Default log file extension.
DEFAULT_NAME  = 'log'
Default log file name.
DEFAULT_PATH  = 'log'
Default log folder path (relative to $directory).

Properties

$bubbles  : bool
Indicates if the bubbling is active.
$directory  : string
The base directory for log storage.
$dirPermissions  : int|float
The directory permission.
$extension  : string
The file extension used for log files (e.g., ".log").
$filePermissions  : int|float
The file permission.
$level  : int|Level
The default level of the logger.
$maxFiles  : int
The maximum number of files stored in the log folder.
$name  : string|null
Optional name of the logging channel.
$path  : string
Subfolder or path where log files are stored (relative to $directory).
$formatter  : FormatterInterface|null
The line formatter.

Methods

__construct()  : mixed
Creates a new MonoLogManager instance.
clear()  : bool
Clears the content of a specific log file.
countLines()  : int
Returns the number of lines in a log file.
createLog()  : Log|null
Parses a log line into a structured array.
createLogger()  : LoggerInterface
Creates and configures a logger instance.
getDirectory()  : string
Returns the full path of the log directory.
getExtension()  : string
Returns the file extension used for log files.
getFileName()  : string
Returns the base name of the log file.
getFilePath()  : string
Returns the full path to a log file.
getFormatter()  : FormatterInterface
Retrieves the formatter instance.
getLoggerFiles()  : array<string|int, mixed>|false
Returns the list of log files in the log directory matching the current logger name and extension.
getLogLines()  : array<string|int, mixed>|null
Returns the lines of a log file as an array of structured entries.
setFormatter()  : void
Sets the formatter for log entries.

Constants

DEFAULT_EXTENSION

Default log file extension.

public mixed DEFAULT_EXTENSION = '.log'

DEFAULT_NAME

Default log file name.

public mixed DEFAULT_NAME = 'log'

DEFAULT_PATH

Default log folder path (relative to $directory).

public mixed DEFAULT_PATH = 'log'

Properties

$bubbles

Indicates if the bubbling is active.

public bool $bubbles = true

$directory

The base directory for log storage.

public string $directory = \oihana\enums\Char::EMPTY

$dirPermissions

The directory permission.

public int|float $dirPermissions = 0775

$extension

The file extension used for log files (e.g., ".log").

public string $extension

$filePermissions

The file permission.

public int|float $filePermissions = 0664

$maxFiles

The maximum number of files stored in the log folder.

public int $maxFiles = 0

$name

Optional name of the logging channel.

public string|null $name

Used as prefix for log files and as a descriptive label.

$path

Subfolder or path where log files are stored (relative to $directory).

public string $path

$formatter

The line formatter.

protected FormatterInterface|null $formatter = null

Methods

__construct()

Creates a new MonoLogManager instance.

public __construct([string $directory = Char::EMPTY ][, array<string|int, mixed> $init = [] ][, string|null $name = null ]) : mixed
Parameters
$directory : string = Char::EMPTY
$init : array<string|int, mixed> = []
$name : string|null = null

clear()

Clears the content of a specific log file.

public clear(string $file) : bool
Parameters
$file : string

Log file name.

Tags
throws
FileException

If clearing fails due to filesystem permissions or errors.

Return values
bool

True if the file was cleared, false if file does not exist.

countLines()

Returns the number of lines in a log file.

public countLines(string $file) : int
Parameters
$file : string

Log file name.

Tags
throws
FileException

If file cannot be read.

Return values
int

Number of lines in the file.

createLog()

Parses a log line into a structured array.

public createLog(string $line) : Log|null

Example: "2025-08-21 10:30:00 INFO Some message" becomes: [ 'date' => '2025-08-21', 'time' => '10:30:00', 'level' => 'INFO', 'message' => 'Some message' ]

Parameters
$line : string

Raw log line.

Return values
Log|null

Parsed log entry or null if line is empty or malformed.

createLogger()

Creates and configures a logger instance.

public createLogger() : LoggerInterface

This method sets up a logger with a rotating file handler, custom formatter, and registers it for error handling to capture system errors and exceptions.

Return values
LoggerInterface

The configured logger instance.

getDirectory()

Returns the full path of the log directory.

public getDirectory() : string
Return values
string

Absolute path to the log folder.

getExtension()

Returns the file extension used for log files.

public getExtension() : string
Return values
string

Log file extension, including dot (e.g., ".log").

getFileName()

Returns the base name of the log file.

public getFileName() : string
Return values
string

Log file name.

getFilePath()

Returns the full path to a log file.

public getFilePath([string|null $file = null ]) : string
Parameters
$file : string|null = null

Optional custom file name. Defaults to .

Return values
string

Full path to the log file.

getFormatter()

Retrieves the formatter instance.

public getFormatter() : FormatterInterface
Return values
FormatterInterface

getLoggerFiles()

Returns the list of log files in the log directory matching the current logger name and extension.

public getLoggerFiles() : array<string|int, mixed>|false
Tags
throws
DirectoryException

If the log directory cannot be read.

Return values
array<string|int, mixed>|false

List of log file names or false on error.

getLogLines()

Returns the lines of a log file as an array of structured entries.

public getLogLines(string|null $file) : array<string|int, mixed>|null
Parameters
$file : string|null

Log file name.

Tags
throws
FileException

If the file cannot be read.

Return values
array<string|int, mixed>|null

Array of parsed log entries or null if file does not exist.

setFormatter()

Sets the formatter for log entries.

public setFormatter() : void

        
On this page

Search results