StreamLogTarget

Type
Class
Namespace
craft\log
Inherits
craft\log\StreamLogTarget » yii\log\Target (opens new window) » yii\base\Component (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Uses traits
craft\base\LogTargetTrait
Since
3.6.0

Class StreamLogTarget

View source (opens new window)

# Public Properties

Property Description
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component.
categories (opens new window) array (opens new window) – List of message categories that this target is interested in.
disableTimestamp boolean (opens new window) – Whether to disable the timestamp.
enableLocking boolean (opens new window) – Whether to use flock() to lock/unlock the stream before/after writing.
enabled (opens new window) boolean (opens new window) – Indicates whether this log target is enabled.
except (opens new window) array (opens new window) – List of message categories that this target is NOT interested in.
exportInterval (opens new window) integer (opens new window) – How many messages should be accumulated before they are exported.
includeUserIp boolean (opens new window) – Whether the user IP should be included in the default log prefix.
levels (opens new window) integer (opens new window) – The message levels that this target is interested in.
logVars (opens new window) array (opens new window) – List of the PHP predefined variables that should be logged in a message.
maskVars (opens new window) array (opens new window) – List of the PHP predefined variables that should NOT be logged "as is" and should always be replaced with a mask *** before logging, when exist.
messages (opens new window) array (opens new window) – The messages that are retrieved from the logger so far by this log target.
microtime (opens new window) boolean (opens new window) – Whether to log time with microseconds.
prefix (opens new window) callable (opens new window) – A PHP callable that returns a string to be prefixed to every exported message.
prefixString string (opens new window) – A string to prepend to all messages.
replaceNewline string (opens new window), null (opens new window) – A string that should replace all newline characters in a log message.
url string (opens new window) – The URL to use.

# disableTimestamp

Type
boolean (opens new window)
Default value
false

Whether to disable the timestamp. The default is false which will prepend every message with a timestamp created with [yii\log\Target::getTime()].

View source (opens new window)

# enableLocking

Type
boolean (opens new window)
Default value
false

Whether to use flock() to lock/unlock the stream before/after writing. This can be used to ensure that the stream is written by 2 processes simultaneously. Note though, that not all stream types support locking. The default is false.

View source (opens new window)

# prefixString

Type
string (opens new window)
Default value
''

A string to prepend to all messages. The string will be added to the very beginning (even before the timestamp).

View source (opens new window)

# replaceNewline

Type
string (opens new window), null (opens new window)
Default value
null

A string that should replace all newline characters in a log message. Default is null for no replacement.

View source (opens new window)

# url

Type
string (opens new window)
Default value
null

The URL to use. See https://php.net/manual/en/wrappers.php for details. This gets ignored if fp is configured.

View source (opens new window)

# Protected Properties

# fp

Default value
null

View source (opens new window)

# openedFp

Type
boolean (opens new window)
Default value
false

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__clone() (opens new window) This method is called after the object is created by cloning an existing one.
__construct() (opens new window) Constructor.
__destruct()
__get() (opens new window) Returns the value of a component property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets the value of a component property.
__unset() (opens new window) Sets a component property to be null.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
behaviors() (opens new window) Returns a list of behaviors that this component should behave as.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
closeFp() Close the file handle if it was opened by this class
collect() (opens new window) Processes the given log messages.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
ensureBehaviors() (opens new window) Makes sure that the behaviors declared in behaviors() (opens new window) are attached to this component.
export() Writes a log message to the given target URL
filterMessages() (opens new window) Filters the given messages according to their categories and levels.
formatMessage() Formats a log message for display as a string.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getEnabled() (opens new window) Check whether the log target is enabled.
getFp()
getLevels() (opens new window)
getMessagePrefix() Returns a string to be prefixed to the given message.
hasEventHandlers() (opens new window) Returns a value indicating whether there is any handler attached to the named event.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined for this component.
init() Initializes the object.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
setEnabled() (opens new window) Sets a value indicating whether this log target is enabled.
setFp()
setLevels() (opens new window) Sets the message levels that this target is interested in.
trigger() (opens new window) Triggers an event.

# __destruct()

View source (opens new window)

# closeFp()

Close the file handle if it was opened by this class

View source (opens new window)

# export()

Writes a log message to the given target URL

View source (opens new window)

Throws

# formatMessage()

Formats a log message for display as a string.

View source (opens new window)

Arguments

Returns

string (opens new window) – The formatted message

# getFp()

View source (opens new window)

Returns

resource (opens new window) – The stream resource to write messages to

Throws

# init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source (opens new window)

# setFp()

View source (opens new window)

Arguments

  • $value (resource (opens new window)) – An open and writeable resource. This can also be one of PHP's pre-defined resources like STDIN or STDERR, which are available in CLI context.

Throws

# Protected Methods

Method Description
getContextMessage() Generates the context information to be logged.
getTime() Returns formatted ('Y-m-d H:i:s') timestamp for message.

# getTime()

Returns formatted ('Y-m-d H:i:s') timestamp for message.

If microtime (opens new window) is configured to true it will return format 'Y-m-d H:i:s.u'.

View source (opens new window)

Arguments

Returns

string (opens new window)