Logger
in package
implements
LoggerInterface
The CodeIgntier Logger
The message MUST be a string or object implementing __toString().
The message MAY contain placeholders in the form: {foo} where foo will be replaced by the context data in key "foo".
The context array can contain arbitrary data, the only assumption that can be made by implementors is that if an Exception instance is given to produce a stack trace, it MUST be in a key named "exception".
Tags
Table of Contents
Interfaces
- LoggerInterface
Properties
- $logCache : array<string|int, mixed>
- Caches logging calls for debugbar.
- $cacheLogs : bool
- Should we cache our logged items?
- $dateFormat : string
- Format of the timestamp for log files.
- $fileExt : string
- Filename Extension
- $filePermissions : int
- File permissions
- $handlerConfig : array<class-string, array<string, int|array<int, string>|string>>
- Holds the configuration for each handler.
- $handlers : array<string|int, mixed>
- Caches instances of the handlers.
- $loggableLevels : array<string|int, mixed>
- Array of levels to be logged.
- $logLevels : array<string, int>
- Used by the logThreshold Config setting to define which errors to show.
Methods
- __construct() : mixed
- Constructor.
- alert() : void
- Action must be taken immediately.
- critical() : void
- Critical conditions.
- debug() : void
- Detailed debug information.
- determineFile() : array<string|int, mixed>
- Determines the file and line that the logging call was made from by analyzing the backtrace.
- 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.
- log() : void
- Logs with an arbitrary level.
- notice() : void
- Normal but significant events.
- warning() : void
- Exceptional occurrences that are not errors.
- cleanFileNames() : string
- Cleans the paths of filenames by replacing APPPATH, SYSTEMPATH, FCPATH with the actual var. i.e.
- interpolate() : string
- Replaces any placeholders in the message with variables from the context, as well as a few special items like:
Properties
$logCache
Caches logging calls for debugbar.
public
array<string|int, mixed>
$logCache
$cacheLogs
Should we cache our logged items?
protected
bool
$cacheLogs
= false
$dateFormat
Format of the timestamp for log files.
protected
string
$dateFormat
= 'Y-m-d H:i:s'
$fileExt
Filename Extension
protected
string
$fileExt
$filePermissions
File permissions
protected
int
$filePermissions
= 0644
$handlerConfig
Holds the configuration for each handler.
protected
array<class-string, array<string, int|array<int, string>|string>>
$handlerConfig
= []
The key is the handler's class name. The value is an associative array of configuration items.
$handlers
Caches instances of the handlers.
protected
array<string|int, mixed>
$handlers
= []
$loggableLevels
Array of levels to be logged.
protected
array<string|int, mixed>
$loggableLevels
= []
The rest will be ignored. Set in Config/logger.php
$logLevels
Used by the logThreshold Config setting to define which errors to show.
protected
array<string, int>
$logLevels
= ['emergency' => 1, 'alert' => 2, 'critical' => 3, 'error' => 4, 'warning' => 5, 'notice' => 6, 'info' => 7, 'debug' => 8]
Methods
__construct()
Constructor.
public
__construct(Logger $config[, bool $debug = CI_DEBUG ]) : mixed
Parameters
- $config : Logger
- $debug : bool = CI_DEBUG
Tags
alert()
Action must be taken immediately.
public
alert(string $message[, array<string|int, mixed> $context = [] ]) : void
Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
Parameters
- $message : string
- $context : array<string|int, mixed> = []
critical()
Critical conditions.
public
critical(string $message[, array<string|int, mixed> $context = [] ]) : void
Example: Application component unavailable, unexpected exception.
Parameters
- $message : string
- $context : array<string|int, mixed> = []
debug()
Detailed debug information.
public
debug(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
determineFile()
Determines the file and line that the logging call was made from by analyzing the backtrace.
public
determineFile() : array<string|int, mixed>
Find the earliest stack frame that is part of our logging system.
Return values
array<string|int, mixed>emergency()
System is unusable.
public
emergency(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
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
- $context : array<string|int, mixed> = []
info()
Interesting events.
public
info(string $message[, array<string|int, mixed> $context = [] ]) : void
Example: User logs in, SQL logs.
Parameters
- $message : string
- $context : array<string|int, mixed> = []
log()
Logs with an arbitrary level.
public
log(string $level, string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $level : string
- $message : string
- $context : array<string|int, mixed> = []
notice()
Normal but significant events.
public
notice(string $message[, array<string|int, mixed> $context = [] ]) : void
Parameters
- $message : string
- $context : array<string|int, mixed> = []
warning()
Exceptional occurrences that are not errors.
public
warning(string $message[, array<string|int, mixed> $context = [] ]) : void
Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
Parameters
- $message : string
- $context : array<string|int, mixed> = []
cleanFileNames()
Cleans the paths of filenames by replacing APPPATH, SYSTEMPATH, FCPATH with the actual var. i.e.
protected
cleanFileNames(string $file) : string
Use dedicated clean_path()
function.
/var/www/site/app/Controllers/Home.php becomes: APPPATH/Controllers/Home.php
Parameters
- $file : string
Return values
stringinterpolate()
Replaces any placeholders in the message with variables from the context, as well as a few special items like:
protected
interpolate(string $message[, array<string|int, mixed> $context = [] ]) : string
{session_vars} {post_vars} {get_vars} {env} {env:foo} {file} {line}
Parameters
- $message : string
- $context : array<string|int, mixed> = []