\apex\app\syslog

Log Handler

Service: apex\services\log

Handles all logging and ebugging of Apex, and is fully PSR3 compliant. Supports the 7 log levels, log channels, and PSR compliant placeholders within the messages.

This class is available within the services container, meaning its methods can be accessed statically via the service singleton as shown below.

PHP Example

</php

namespace apex;

use apex\app; use apex\services\log;

Summary

Methods
Properties
Constants
__construct()
set_log_levels()
debug()
info()
warning()
notice()
error()
critical()
alert()
emergency()
log()
add_system_log()
No public properties found
EMERGENCY
ALERT
CRITICAL
ERROR
WARNING
NOTICE
INFO
DEBUG
write()
$log_file
$log_line
$is_system
N/A
No private methods found
$log_dir
$log_levels
$channel
$streams
N/A

Constants

EMERGENCY

EMERGENCY

ALERT

ALERT

CRITICAL

CRITICAL

ERROR

ERROR

WARNING

WARNING

NOTICE

NOTICE

INFO

INFO

DEBUG

DEBUG

Properties

$log_file

$log_file : 

Type

$log_line

$log_line : 

Type

$is_system

$is_system : 

Type

$log_dir

$log_dir : 

Type

$log_levels

$log_levels : 

Type

$channel

$channel : 

Type

$streams

$streams : 

Type

Methods

__construct()

__construct(string  $channel_name = 'apex') 

Initiates anew class, allowing for channel creation

Parameters

string $channel_name

The name of the log channel to create, defaults to 'apex'.

set_log_levels()

set_log_levels(array  $levels) 

Set the log levels

Parameters

array $levels

The log levels to set. Only levels within this array will be logged.

debug()

debug(mixed  $msg, array  $context = array()) : void

DEBUG message.

Parameters

mixed $msg

The log entry message.

array $context

Values to replace the placeholders within the message with.

info()

info(mixed  $msg, array  $context = array()) : void

INFO message.

Example: User logs in, SQL logs.

Parameters

mixed $msg

The log entry message.

array $context

Values to replace the placeholders within the message with.

warning()

warning(mixed  $msg, array  $vars = array()) : void

WARNING message.

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

notice()

notice(mixed  $msg, array  $vars = array()) : void

NOTICE message.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

error()

error(mixed  $msg, array  $vars = array()) : void

ERROR message.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

critical()

critical(mixed  $msg, array  $vars = array()) : void

CRITICAL message.

Example: Application component unavailable, unexpected exception.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

alert()

alert(mixed  $msg, array  $vars = array()) : void

ALERT message

Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

emergency()

emergency(mixed  $msg, array  $vars = array()) : void

EMERGENCY message.

Parameters

mixed $msg

The log entry message.

array $vars

Values to replace the placeholders within the message with.

log()

log(string  $level, mixed  $msg, array  $context = array()) : void

Adds new line to log file

Parameters

string $level

One of the eight PSR3 log levels

mixed $msg

The log message

array $context

Optional array of context variables

add_system_log()

add_system_log(string  $type, integer  $is_system,   $file, integer  $line, string  $msg, array  $vars) 

Add system log

Adds a system log, and should never be executed manually. This is used when PHP throws an error or the trigger_error() function is used, plus when a DEBUG level message comes in. This is due to the fact file and line numbers are included, plus for filtering reasons.

Parameters

string $type

One of the eight PSR supported log levels

integer $is_system

Whether this message is from the PHP compiler or not.

$file

The FILE variable captured.

integer $line

The LINE variable captured.

string $msg

The log message.

array $vars

Values to replace placeholders in the message with.

write()

write(string  $level, string  $line) 

Write line to a log file

Parameters

string $level

the log level / filename

string $line

The line to write