\phpWTLPhpAppLogger

Logger for PHP event/error/exception logging.

A logger in its basic form typically handles the following tasks:

- Instantiate a LoggerContent object and provide it with a format blueprint in form of a static FormatDescriptor class
- Initialize a DataRetriever and provide it with a LoggerContent object (and if applicable with RetrievalPolicies)
- Initialize a DataValidator and provide it with a LoggerContent object
- Initialize a DataFormatter and provide it with a LoggerContent object
- Provide a method to perform the actual logging (i.e. invoke retriever, validator and formatter accordingly)

Summary

Methods
Properties
Constants
log()
getDataRetrievalPolicies()
setDataRetrievalPolicies()
getFormatDescriptor()
getLoggerContent()
getDataRetriever()
getDataValidator()
getDataFormatter()
getInstance()
interpolateContextData()
e2arr()
e2json()
getLoglevelThreshold()
setLoglevelThreshold()
No public properties found
No constants found
loadDataRetrievalPoliciesDefault()
__clone()
__sleep()
__wakeup()
__construct()
extractPlaceholders()
context2json()
$retrievalPolicies
$loggerContent
$dataRetriever
$dataValidator
$dataFormatter
$_instance
$logLevelThreshold
N/A
No private methods found
$loggerContent_bak
N/A

Properties

$retrievalPolicies

$retrievalPolicies : 

Type

$loggerContent

$loggerContent : 

Type

$dataRetriever

$dataRetriever : 

Type

$dataValidator

$dataValidator : 

Type

$dataFormatter

$dataFormatter : 

Type

$_instance

$_instance : 

Array to hold instances of all derived classes.

Type

$logLevelThreshold

$logLevelThreshold : 

Type

$loggerContent_bak

$loggerContent_bak : 

Type

Methods

log()

log(array  $params = null) : array

Perform the actual logging process:

  • Check loglevel threshold
  • Retrieve log data thru retriever
  • Validate data fields with validator (can be turned off)
  • Format/prefix/suffix fields via formatter (can be turned off), set the datatype class in content object accordingly

Parameters

array $params

Logger parameters (int "loglevel", string "message", array "context", bool "validate" default "false", bool "format" default "true")

Returns

array —

Validation (or other) errors (null if none)

getDataRetrievalPolicies()

getDataRetrievalPolicies() : array

Return data retrieval policies set during initialization.

Returns

array

setDataRetrievalPolicies()

setDataRetrievalPolicies(array  $retrievalPolicies = null) 

Set data retrieval policies after initialization:

  • Also do this in the associated data retriever
  • If null restore the default

Parameters

array $retrievalPolicies

Provide policies for data retrieval.

getFormatDescriptor()

getFormatDescriptor() 

getLoggerContent()

getLoggerContent() 

getDataRetriever()

getDataRetriever() 

getDataValidator()

getDataValidator() 

getDataFormatter()

getDataFormatter() 

getInstance()

getInstance(array|mixed|null  $inject = null) : \phpWTL\$_instance[$class]

Create new instance or give back already existing one.

Parameters

array|mixed|null $inject

Can be used to inject one or more parameter(s) into the constructor

Returns

\phpWTL\$_instance[$class] —

The instance of a derived class

interpolateContextData()

interpolateContextData(string  $message, array  $context = array()) : string

Interpolate context values into the (brace-delimited) message placeholders (see also: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md).

Parameters

string $message
array $context

Key-value pairs for context data

Returns

string —

Message with all {placeholders} replaced by their respective context variable contents.

e2arr()

e2arr(\phpWTL\exception  $e) : array

Transform contents of the given exception object into an associative array.

Parameters

\phpWTL\exception $e

Returns

array —

Array representation of exception object, keys analog to the corr. methods of the exception object: eMessage, ePrevious, eCode, eFile, eLine, eTrace, eTraceAsString, eToString (__toString of whole ex. obj.).

e2json()

e2json(\phpWTL\exception  $e, integer  $jsonParams = null) : string

Transform contents of the given exception object into a JSON data structure (wrapper).

Parameters

\phpWTL\exception $e
integer $jsonParams

Parameter for "json_encode" function (optional)

Returns

string —

JSON representation of exception object, keys analog to the corr. methods of the exception object: eMessage, ePrevious, eCode, eFile, eLine, eTrace, eTraceAsString, eToString (__toString of whole ex. obj.).

getLoglevelThreshold()

getLoglevelThreshold() : integer

Return loglevel threshold.

Returns

integer

setLoglevelThreshold()

setLoglevelThreshold(  $loglevel = null) 

Set loglevel threshold.

Parameters

$loglevel

loadDataRetrievalPoliciesDefault()

loadDataRetrievalPoliciesDefault() 

Set default data retrieval policies.

__clone()

__clone() 

Disable cloning for singleton.

Throws

\phpWTL\Exception

if called

__sleep()

__sleep() 

Disable serialization for singleton.

Throws

\phpWTL\Exception

if called

__wakeup()

__wakeup() 

Disable de-serialization for singleton.

Throws

\phpWTL\Exception

if called

__construct()

__construct(integer  $loglevel = null) 

The constructor must perform the following taks:

  • Instantiate and store a LoggerContent object based on the required static FormatDescriptor
  • Handle/store all other (optional) parts neccessary and/or wanted (data retriever, validator, formatter)

Parameters

integer $loglevel

Threshold for logger (default: LOGLEVEL_WARNING).

extractPlaceholders()

extractPlaceholders(string  $message) : array

Extract placeholder names from message string.

Parameters

string $message

Returns

array —

Placeholder names (keys).

context2json()

context2json(array  $context, array  $exclude_keys, integer  $jsonParams = null) : string

Transform context array into a JSON data structure.

Parameters

array $context
array $exclude_keys
integer $jsonParams

Parameter for "json_encode" function (optional)

Returns

string —

JSON representation of context data.