Logger

Type
Class
Namespace
Craft
Inherits
Craft\Logger » CLogger » CComponent
Since
1.0

Class Logger

See also http://craftcms.com

View source

Public Properties

$autoDump

Signature

public boolean $autoDump = true

$autoFlush

Signature

public integer $autoFlush = 0

Protected Properties

PropertyDescription
$_categoriesarray – Log categories for filtering (used when filtering)
$_exceptarray – Log categories for excluding from filtering (used when filtering)
$_levelsarray – Log levels for filtering (used when filtering)
$_logCountinteger – Number of log messages
$_logsarray – Log messages
$_processingboolean – If we are processing the log or still accepting new log messages
$_timingsarray – The profiling results (category, token => time in seconds)

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
flush()Removes all recorded messages from the memory.
getEventHandlers()Returns the list of attached event handlers for an event.
getExecutionTime()Returns the total time for serving the current request.
getLogs()Retrieves log messages.
getMemoryUsage()Returns the memory usage of the current application.
getProfilingResults()Returns the profiling results.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
log()Logs a message. Messages logged by this method may be retrieved back via {@link getLogs}.
onFlush()Raises an onFlush event.
raiseEvent()Raises an event.

getLogs()

Retrieves log messages. Messages may be filtered by log levels and/or categories.

A level filter is specified by a list of levels separated by comma or space (e.g. 'trace, error'). A category filter is similar to level filter (e.g. 'system, system.web'). A difference is that in category filter you can use pattern like 'system.*' to indicate all categories starting with 'system'.

If you do not specify level filter, it will bring back logs at all levels. The same applies to category filter.

Level filter and category filter are combinational, i.e., only messages satisfying both filter conditions will be returned.

View source

Arguments

Returns

array – The list of messages. Each array element represents one message with the following structure:

array(
   [0] => message (string)
   [1] => level (string)
   [2] => category (string)
   [3] => timestamp (float, obtained by microtime(true)
);

Signature

public array getLogs ( $levels = '', $categories = [], $except = [] )

log()

Logs a message. Messages logged by this method may be retrieved back via {@link getLogs}.

View source

Arguments

  • $message (string) – The message to be logged
  • $level (string) – The level of the message (e.g. 'Trace', 'Warning', 'Error'). It is case-insensitive.
  • $force (boolean) – Whether for force the message to be logged regardless of category or level.
  • $category (string) – The category of the message (e.g. 'system.web'). It is case-insensitive.
  • $plugin (string) – The plugin handle that made the log call. If null, will be set to 'craft'. Use for determining which log file to write to.

Returns

null

Signature

public null log ( $message, $level = 'info', $force = false, $category = 'application', $plugin = null )

Protected Methods

MethodDescription
filterAllCategories()Filter function used to filter included and excluded categories
filterByCategory()Filter function used by {@link getLogs}
filterByLevel()Filter function used by {@link getLogs}

filterAllCategories()

Filter function used to filter included and excluded categories

View source

Arguments

  • $value (array) – The element to be filtered
  • $index (integer) – The index of the values array to be used for check

Returns

boolean – True if valid timing entry, false if not.

Signature

protected boolean filterAllCategories ( $value, $index )

filterByCategory()

Filter function used by {@link getLogs}

View source

Arguments

  • $value (array) – The element to be filtered

Returns

boolean – True if valid log, false if not.

Signature

protected boolean filterByCategory ( $value )

filterByLevel()

Filter function used by {@link getLogs}

View source

Arguments

  • $value (array) – The element to be filtered

Returns

boolean – True if valid log, false if not.

Signature

protected boolean filterByLevel ( $value )

Constants

ConstantDescription
LEVEL_ERROR
LEVEL_INFO
LEVEL_PROFILE
LEVEL_TRACE
LEVEL_WARNING