Log

Log writer object factory and Logger. Thought implements IObjectFactory and you can directly get a log writer object, this class contains static methods for writing into a log. e.g. "Log::error('objectname', 'comments');", the first argument for logger methods is the Log writer object-name. There are separated methods that can log a request, IModel object and a special event.
The recommended way is to add config entries for logger objects inside the application's config array or ini file and use the static methods of this class to write into a log by addressing the config object by it's name.
Source
Log.php
Implements
ILog , IObjectFactory
Depends on
Arta , LogText , LogCsv , LogWriterEngineNotSupported , ILogWriter , IModel , Binder
Since
1.2.2

Static Methods

config

array|string Log::config(string objectName=null, string index=null, array configs=null)

Set or get configs for a Log writer object. The configs will only be set if a last param is passed. The configs are stored in "Arta::$logConfigs" which also contains the app log writer object configs (from the app config ini file or array).

Arguments

    objectName=null (string)
    The object name to set or to get configs for, null=return all object configs
    index=null (string)
    Config key, to get the value of a specific setting
    configs=null (array)
    To add a new log writer object configs
    {
        string engine    :
            log write engine currently 'text' and 'csv',
        string log_file  : TEMP_DIR/logs/date(Y-m-d).EXT
            file path to write the log into. the default,
        bool   json      : false
            true=save array comments as JSON,
        bool   user_data : true
            true=add user id, username and IP if available,
        bool   compact   : false
            only for csv logs.
            true=put array comments in one column
            false=put array items in separated columns,
        string style     : arta
            the log item style. may be any of
            'arta' = log in a highly readable style
            'one'  = log each item in only one line
            'two'  = log each item in two lines
            'param'= log each item's part inside braces,
    }
    

Returns

array|string
{configs} or {object-name: {configs},} or the value of a config key

debug

void Log::debug(string objectName, string | array comment)

Log debug information.

Arguments

    objectName (string)
    The log writer object name
    comment (string | array)
    Comment to be written to log

Returns

void

Throws

error

void Log::error(string objectName, string | array comment)

Log an error.

Arguments

    objectName (string)
    The log writer object name
    comment (string | array)
    Comment to be written to log

Returns

void

Throws

get

ILogWriter|array Log::get(string | bool objectName=null, bool remove=false)

Creates and returns or returns an already created object. When creating a new object the object configs are expected to exists in "Arta::$logConfigs", note that the log writer objects defined in the app config array or ini file are put in "Arta::$logConfigs" by Artaengine.
Get a log writer object by passing the object name.
Get all log writer objects in an array by passing true.
To remove an object pass true for the second argument.

Arguments

    objectName=null (string | bool)
    Object name to create or to get handle of, null=return the last object in the list, true=return all objects
    remove=false (bool)
    true=remove/unsset the object

Returns

ILogWriter|array
Reference to a log writer object or a list of log writer objects

Throws

getCreateNew

ILogWriter Log::getCreateNew(string objectName, array configs)

Creates and returns an object. Use this method to create a new object by passing the object configs versus "get()" that expects the configs to exist in "Arta::$logConfigs".

Arguments

    objectName (string)
    The object name to be created
    configs (array)
    Log writer object configs
    {
        string engine    :
            log write engine currently 'text' and 'csv',
        string log_file  : TEMP_DIR/logs/date(Y-m-d).EXT
            file path to write the log into. the default,
        bool   json      : false
            true=save array comments as JSON,
        bool   user_data : true
            true=add user id, username and IP if available,
        bool   compact   : false
            only for csv logs.
            true=put array comments in one column
            false=put array items in separated columns,
        string style     : arta
            the log item style. may be any of
            'arta' = log in a highly readable style
            'one'  = log each item in only one line
            'two'  = log each item in two lines
            'param'= log each item's part inside braces,
    }
    

Returns

ILogWriter
Reference to the newly created log writer object

Throws

handle

void Log::handle(string objectName)

Log special events. (Exceptions, URL/Factory not found, Not AJAX, Permission errors). To log this events put "Log::handle('object-name');" inside the event handler, the log data will be fetched automatically.

Arguments

    objectName (string)
    The log writer object name

Returns

void

Throws

info

void Log::info(string objectName, string | array comment)

Log information.

Arguments

    objectName (string)
    The log writer object name
    comment (string | array)
    Comment to be written to log

Returns

void

Throws

model

void Log::model(string objectName, IModel model, bool full)

Log model actions Add, Update and Delete. You can put "Log::model('object-name', $this);" inside model's "afterAdd()", "afterUpdate()" or "afterDelete()" to record the event.

Arguments

    objectName (string)
    The log writer object name
    model (IModel)
    The model instance
    full (bool)
    full=true true=include model's data property values in the log

Returns

void

Throws

remove

void Log::remove(string objectName)

Remove an object if already been created.

Arguments

    objectName (string)
    Object name to remove

Returns

void

request

void Log::request(string objectName, array data=array())

Log a request.

Arguments

    objectName (string)
    The log writer object name
    data=array() (array)
    Additional data to be in log, to include request proccess time add 'start' => proccess start time stamp, to add all headers add 'headers' => true, to add all request arrays add 'array' => true

Returns

void

Throws

trace

void Log::trace(string objectName, string | array comment)

Log trace information.

Arguments

    objectName (string)
    The log writer object name
    comment (string | array)
    Comment to be written to log

Returns

void

Throws

warn

void Log::warn(string objectName, string | array comment)

Log a warning.

Arguments

    objectName (string)
    The log writer object name
    comment (string | array)
    Comment to be written to log

Returns

void

Throws