PHP Class SimpleLogger

Example of stderr logger: $logger = new SimpleLogger(fopen('php://stderr', 1)); $logger->warn('You are a monkey');
Author: Rasmus Andersson http://hunch.se/
Mostrar archivo Open project: bonny/wordpress-simple-history Class Usage Examples

Public Properties

Property Type Description
$lastInsertID ID of last inserted row. Used when chaining methods.
$messages By adding your messages here they will be stored both translated and non-translated You then log something like this: $this->info( $this->messages["POST_UPDATED"] ); or with the shortcut $this->infoMessage("POST_UPDATED"); which results in the original, untranslated, string being added to the log and database the translated string are then only used when showing the log in the GUI
$slug Unique slug for this logger Will be saved in DB and used to associate each log row with its logger

Public Methods

Method Description
__construct ( $simpleHistory = null ) Constructor. Remember to call this as parent constructor if making a childlogger
adminCSS ( ) Override this to add CSS in for your logger.
adminJS ( ) Override this to add JavaScript in the footer for your logger.
alert ( string $message, array $context = [] ) : null Action must be taken immediately.
alertMessage ( string $message, array $context = [] ) : null Action must be taken immediately.
critical ( string $message, array $context = [] ) : null Critical conditions.
criticalMessage ( string $message, array $context = [] ) : null Critical conditions.
debug ( string $message, array $context = [] ) : null Detailed debug information.
debugMessage ( string $message, array $context = [] ) : null Detailed debug information.
emergency ( string $message, array $context = [] ) : null System is unusable.
emergencyMessage ( string $message, array $context = [] ) : null System is unusable.
error ( string $message, array $context = [] ) : null Runtime errors that do not require immediate action but should typically be logged and monitored.
errorMessage ( string $message, array $context = [] ) : null Runtime errors that do not require immediate action but should typically be logged and monitored.
getCapability ( ) Returns the capability required to read log rows from this logger
getInfo ( ) : array Get array with information about this logger
getInfoValueByKey ( $key ) : Mixed Return single array entry from the array in getInfo() Returns the value of the key if value exists, or null
getLogRowDetailsOutput ( object $row ) : string Use this method to output detailed output for a log row Example usage is if a user has uploaded an image then a thumbnail of that image can bo outputed here
getLogRowHeaderOutput ( $row ) : string Returns header output for a log row Format should be common for all log rows and should be like: Username (user role) · Date
getLogRowPlainTextOutput ( $row ) Returns the plain text version of this entry Used in for example CSV-exports.
getLogRowSenderImageOutput ( $row ) Get output for image Image can be for example gravar if sender is user, or other images if sender i system, wordpress, and so on
get_event_ip_number_headers ( $row ) Returns additional headers with ip number from context
get_ip_number_header_keys ( ) Returns array with headers that may contain user IP
info ( string $message, array $context = [] ) : null Interesting events.
infoMessage ( string $message, array $context = [] ) : null Interesting events.
interpolate ( string $message, array $context = [], array $row = null ) Interpolates context values into the message placeholders.
loaded ( ) Method that is called automagically when logger is loaded by Simple History Add your init stuff here
log ( mixed $level, string $message, array $context = [] ) : null Logs with an arbitrary level.
notice ( string $message, array $context = [] ) : null Normal but significant events.
noticeMessage ( string $message, array $context = [] ) : null Normal but significant events.
validate_ip ( $ip ) Ensures an ip address is both a valid IP and does not fall within a private network range.
warning ( string $message, array $context = [] ) : null Exceptional occurrences that are not errors.
warningMessage ( string $message, array $context = [] ) : null Exceptional occurrences that are not errors.

Private Methods

Method Description
logByMessageKey ( $SimpleLoggerLogLevelsLevel, $messageKey, $context ) Log with message Called from infoMessage(), errorMessage(), and so on

Method Details

__construct() public method

Constructor. Remember to call this as parent constructor if making a childlogger
public __construct ( $simpleHistory = null )
$simpleHistory history class objectinstance

adminCSS() public method

The CSS that you output will only be outputed on pages where Simple History is used.
public adminCSS ( )

adminJS() public method

The JS that you output will only be outputed on pages where Simple History is used.
public adminJS ( )

alert() public static method

Action must be taken immediately.
public static alert ( string $message, array $context = [] ) : null
$message string
$context array
return null

alertMessage() public method

Action must be taken immediately.
public alertMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

critical() public static method

Example: Application component unavailable, unexpected exception.
public static critical ( string $message, array $context = [] ) : null
$message string
$context array
return null

criticalMessage() public method

Critical conditions.
public criticalMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

debug() public method

Detailed debug information.
public debug ( string $message, array $context = [] ) : null
$message string
$context array
return null

debugMessage() public method

Detailed debug information.
public debugMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

emergency() public static method

System is unusable.
public static emergency ( string $message, array $context = [] ) : null
$message string
$context array
return null

emergencyMessage() public method

System is unusable.
public emergencyMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

error() public method

Runtime errors that do not require immediate action but should typically be logged and monitored.
public error ( string $message, array $context = [] ) : null
$message string
$context array
return null

errorMessage() public method

Runtime errors that do not require immediate action but should typically be logged and monitored.
public errorMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

getCapability() public method

Returns the capability required to read log rows from this logger
public getCapability ( )

getInfo() public method

Get array with information about this logger
public getInfo ( ) : array
return array

getInfoValueByKey() public method

Return single array entry from the array in getInfo() Returns the value of the key if value exists, or null
Since: 2.5.4
public getInfoValueByKey ( $key ) : Mixed
return Mixed

getLogRowDetailsOutput() public method

Use this method to output detailed output for a log row Example usage is if a user has uploaded an image then a thumbnail of that image can bo outputed here
public getLogRowDetailsOutput ( object $row ) : string
$row object
return string HTML-formatted output

getLogRowHeaderOutput() public method

Returns header output for a log row Format should be common for all log rows and should be like: Username (user role) · Date
public getLogRowHeaderOutput ( $row ) : string
return string HTML

getLogRowPlainTextOutput() public method

Defaults to log message with context interpolated. Keep format as plain and simple as possible. Links are ok, for example to link to users or posts. Tags will be stripped when text is used for CSV-exports and so on. Keep it on a single line. No

or
and so on. Example output: Edited post "About the company" Message should sound like it's coming from the user. Image that the name of the user is added in front of the text: Jessie James: Edited post "About the company"

public getLogRowPlainTextOutput ( $row )

getLogRowSenderImageOutput() public method

Get output for image Image can be for example gravar if sender is user, or other images if sender i system, wordpress, and so on
public getLogRowSenderImageOutput ( $row )

get_event_ip_number_headers() public method

Returns additional headers with ip number from context
Since: 2.0.29
public get_event_ip_number_headers ( $row )

get_ip_number_header_keys() public method

Returns array with headers that may contain user IP
Since: 2.0.29

info() public method

Example: User logs in, SQL logs.
public info ( string $message, array $context = [] ) : null
$message string
$context array
return null

infoMessage() public method

Example: User logs in, SQL logs.
public infoMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

interpolate() public method

Interpolates context values into the message placeholders.
public interpolate ( string $message, array $context = [], array $row = null )
$message string
$context array
$row array Currently not always passed, because loggers need to be updated to support this...

loaded() public method

Method that is called automagically when logger is loaded by Simple History Add your init stuff here
public loaded ( )

log() public method

Logs with an arbitrary level.
public log ( mixed $level, string $message, array $context = [] ) : null
$level mixed
$message string
$context array
return null

notice() public method

Normal but significant events.
public notice ( string $message, array $context = [] ) : null
$message string
$context array
return null

noticeMessage() public method

Normal but significant events.
public noticeMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

validate_ip() public method

Ensures an ip address is both a valid IP and does not fall within a private network range.
public validate_ip ( $ip )

warning() public method

Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
public warning ( string $message, array $context = [] ) : null
$message string
$context array
return null

warningMessage() public method

Exceptional occurrences that are not errors.
public warningMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
return null

Property Details

$lastInsertID public_oe property

ID of last inserted row. Used when chaining methods.
public $lastInsertID

$messages public_oe property

By adding your messages here they will be stored both translated and non-translated You then log something like this: $this->info( $this->messages["POST_UPDATED"] ); or with the shortcut $this->infoMessage("POST_UPDATED"); which results in the original, untranslated, string being added to the log and database the translated string are then only used when showing the log in the GUI
public $messages

$slug public_oe property

Unique slug for this logger Will be saved in DB and used to associate each log row with its logger
public $slug