This class contains the main functionalities for the logging in CONTENIDO.

Examples:

$writer = cLogWriter::factory("File", array('destination' => 'contenido.log')); $log = new cLog($writer);

$log->addPriority("CONTENIDO", 10); $log->log("Contenido Log Message.", "CONTENIDO"); $log->contenido("Same log entry in short notation."); $log->removePriority("CONTENIDO");

$log->emerg("System down.");

$log->log('Notice Log Message', cLog::NOTICE);

$log->buffer('Buffered Log Message', cLog::WARN); $log->commit();

 Methods

Magic call method for direct priority named calls.

__call(string $method, array $arguments) : void

Parameters

$method

string

Name of the method

$arguments

array

Array with the method arguments

Exceptions

\cInvalidArgumentException if the given priority is not supported

Creates a new instance of the CONTENIDO Log mechanism.

__construct(mixed $writer) 

The log format interface of cLog is capable of being extended by subclasses. See the note about the log shortcuts below.

About Log Shortcuts

Log shortcuts are placeholders which are replaced when a log entry is created. Placeholders start with a percentage sign (%) and contain one or more characters. Each placeholder is handled by an own function which decides what to do.

Parameters

$writer

mixed

writer Writer object (any subclass of cLogWriter), or false if cLog should handle the writer creation

Adds a new priority to the log.

addPriority(string $name, int $value) : void

Parameters

$name

string

Name of the log priority

$value

int

Index value of the log priority

Exceptions

\cInvalidArgumentException if the given name is empty, already exists or the value already exists

Buffers a log message for committing them on a later moment.

buffer(string $message, mixed $priority) : void

Parameters

$message

string

Message to buffer

$priority

mixed

Priority of the log entry (optional)

Commits all buffered messages and empties the message buffer if parameter is not false.

commit(boolean $revoke) : void

Parameters

$revoke

boolean

Flag, whether the buffer is cleared or not (optional, default: true)

Returns the local writer instance.

getWriter() : \cLogWriter

Returns

Logs a message using the local writer instance

log(string $message, mixed $priority) : void

Parameters

$message

string

Message to log

$priority

mixed

Priority of the log entry (optional)

Removes a priority from log.

removePriority(string $name) : void

Default properties can not be removed.

Parameters

$name

string

Name of the log priority to remove

Exceptions

\cInvalidArgumentException if the given name is empty, does not exist or is a default priority

Empties the message buffer.

revoke() : void

Defines a custom shortcut handler.

setShortcutHandler(string $shortcut, string $handler) : bool

Each shortcut handler receives an array with the message and the priority of the entry.

Parameters

$shortcut

string

Shortcut name

$handler

string

Name of the function to call

Exceptions

\cInvalidArgumentException if the given shortcut is empty or already in use or if the handler is not callable

Returns

boolTrue if setting was successful

Sets the local writer instance.

setWriter(\cLogWriter $writer) : void

Parameters

$writer

\cLogWriter

Writer instacne

Shortcut Handler Date.

shDate() : string

Returns the current date

Returns

stringThe current date

Shortcut Handler Level.

shLevel($info) : string

Returns the canonical name of the priority. The canonical name is padded to 10 characters to achieve a better formatting.

Parameters

$info

Returns

stringThe canonical log level

Shortcut Handler Message.

shMessage($info) : string

Returns the log message.

Parameters

$info

Returns

stringThe log message

Unsets a specific shortcut handler.

unsetShortcutHandler(string $shortcut) : boolean

Parameters

$shortcut

string

Name of the shortcut

Exceptions

\cInvalidArgumentException if the given shortcut handler does not exist

Returns

boolean

 Properties

 

Contains all buffered messages

$_buffer : array
 

Contains all default priorities

$_defaultPriorities : array
 

Contains all available priorities

$_priorities : array
 

Contains all shortcut handlers

$_shortcutHandlers : array
 

Contains the local log writer instance.

$_writer : \cLogWriter

 Constants

 

ALERT

ALERT 
 

CRIT

CRIT 
 

DEBUG

DEBUG 
 

EMERG

EMERG 
 

ERR

ERR 
 

INFO

INFO 
 

NOTICE

NOTICE 
 

WARN

WARN