MilkCore

Logs
in package

Logging System Class

This class provides a flexible logging system that allows for organizing logs into groups, with different message types and optional parameter storage. It can also automatically track the file path that generated each log entry.

Tags
example
// Basic log entry
Logs::set('system', 'INFO', 'Application started');

// Log with parameters
Logs::set('user', 'LOGIN', 'User login attempt', [
    'username' => 'john.doe',
    'ip' => '192.168.1.1'
]);

// Log without file path tracking
Logs::set('performance', 'BENCHMARK', 'Query execution time', ['time' => 0.023], false);

Table of Contents

Methods

cleanStr()  : string
Clean string before saving to log
get()  : mixed
Returns the saved message group
logStr()  : string
Cleans a log string that was modified with cleanStr
set()  : void
Adds a log entry to a log group

Methods

cleanStr()

Clean string before saving to log

public static cleanStr(string $string) : string
Parameters
$string : string
Return values
string

get()

Returns the saved message group

public static get(string $group) : mixed
Parameters
$group : string

logStr()

Cleans a log string that was modified with cleanStr

public static logStr(string $string) : string
Parameters
$string : string
Return values
string

set()

Adds a log entry to a log group

public static set(string $group, string $msgType[, string $msg = "" ][, mixed $params = "" ][, bool|array<string|int, mixed> $path = true ]) : void

This method creates a new log entry and stores it in the specified group. It can optionally include additional parameters and automatically track the file path that generated the log entry.

Parameters
$group : string

The log group name (also used as filename when writing to disk)

$msgType : string

The message type (free text, typically uppercase like 'ERROR', 'INFO')

$msg : string = ""

Optional message text to log

$params : mixed = ""

Optional parameters to store with the log entry

$path : bool|array<string|int, mixed> = true

Whether to include file paths that led to this log call, or custom paths

Tags
example
// Simple error log
Logs::set('errors', 'ERROR', 'Database connection failed');

// Detailed log with parameters
Logs::set('security', 'WARNING', 'Invalid access attempt', [
    'ip' => $_SERVER['REMOTE_ADDR'],
    'user_agent' => $_SERVER['HTTP_USER_AGENT']
]);

        
On this page

Search results