class Logger

Supports the ability to produce logging.

Constants

EMERGENCY

Constant for alert level emergency.

ALERT

Constant for alert level alert.

CRITICAL

Constant for alert level critical.

ERROR

Constant for alert level error.

WARNING

Constant for alert level warning.

NOTICE

Constant for alert level notice.

INFO

Constant for alert level info.

DEBUG

Constant for alert level debug.

private LEVELS

Associative array of levels mapped to integers based on severity.

private LOG_FILE_PATH

Path to log files.

Properties

static private string $logFile

Full path and name of current log file.

Methods

static void
emergencyFallback(string $message)

Performs system logging if we cannot write to log file. We also dump the message to the console/view.

static string
generateLogMessage(string $level, string $message, string $file, int $line)

Packages together the actual formatted log message with

static void
init()

Initializes the log file based on the environment (CLI or Web).

static void
isLogDirWritable(string $logDir)

Checks if log directory is writeable. If not writable we write message to PHP log file and dump message to console or view.

static void
isLogFileWritable()

Checks if log file is writable. If not writable we write message to PHP log file and dump message to console or view.

static void
log(string $message, string $level = self::INFO)

Performs operations for adding content to log files.

static void
logDirExists(string $logDir)

Checks if log directory exists. If not, then we create it.

static void
logFileExists()

Checks if log file exists. If not, then we create it.

static bool
shouldLog(string $level)

Logs to file based on level. If level is info the anything with a severity level greater or equal to is logged.

static bool
verifyLoggingLevel(string $level)

Tests if the PSR-3 logging level that is provided is valid

static void
writeToLog(string $message, string $level)

Internal function for writing to log after all checks have passed.

Details

at line 60
static private void emergencyFallback(string $message)

Performs system logging if we cannot write to log file. We also dump the message to the console/view.

Parameters

string $message

The message to be logged.

Return Value

void

at line 73
static private string generateLogMessage(string $level, string $message, string $file, int $line)

Packages together the actual formatted log message with

Parameters

string $level

The severity level of the message.

string $message

The original message.

string $file
int $line

Return Value

string

The formatted message for log file.

at line 87
static private void init()

Initializes the log file based on the environment (CLI or Web).

Return Value

void

at line 106
static private void isLogDirWritable(string $logDir)

Checks if log directory is writeable. If not writable we write message to PHP log file and dump message to console or view.

Parameters

string $logDir

Path for the log directory

Return Value

void

at line 120
static private void isLogFileWritable()

Checks if log file is writable. If not writable we write message to PHP log file and dump message to console or view.

Return Value

void

at line 134
static void log(string $message, string $level = self::INFO)

Performs operations for adding content to log files.

Parameters

string $message

The description of an event that is being written to a log file.

string $level

Describes the severity of the message.

Return Value

void

at line 156
static private void logDirExists(string $logDir)

Checks if log directory exists. If not, then we create it.

Parameters

string $logDir

Path for the log directory.

Return Value

void

at line 167
static private void logFileExists()

Checks if log file exists. If not, then we create it.

Return Value

void

at line 183
static bool shouldLog(string $level)

Logs to file based on level. If level is info the anything with a severity level greater or equal to is logged.

Parameters

string $level

The level passed as a parameter to the log function.

Return Value

bool

True we will log based on level. Otherwise, we return false.

at line 200
static bool verifyLoggingLevel(string $level)

Tests if the PSR-3 logging level that is provided is valid

Parameters

string $level

The PSR-3 level to be tested.

Return Value

bool

True if the level is valid. Otherwise, we return false.

at line 218
static private void writeToLog(string $message, string $level)

Internal function for writing to log after all checks have passed.

Parameters

string $message

The description of an event that is being written to a log file.

string $level

Describes the severity of the message.

Return Value

void