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/
Afficher le fichier Open project: bonny/wordpress-simple-history Class Usage Examples

Méthodes publiques

Свойство 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

Méthodes publiques

Méthode 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

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

Method Details

__construct() public méthode

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

adminCSS() public méthode

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

adminJS() public méthode

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

alert() public static méthode

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

alertMessage() public méthode

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

critical() public static méthode

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

criticalMessage() public méthode

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

debug() public méthode

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

debugMessage() public méthode

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

emergency() public static méthode

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

emergencyMessage() public méthode

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

error() public méthode

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
Résultat null

errorMessage() public méthode

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
Résultat null

getCapability() public méthode

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

getInfo() public méthode

Get array with information about this logger
public getInfo ( ) : array
Résultat array

getInfoValueByKey() public méthode

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
Résultat Mixed

getLogRowDetailsOutput() public méthode

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
Résultat string HTML-formatted output

getLogRowHeaderOutput() public méthode

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
Résultat string HTML

getLogRowPlainTextOutput() public méthode

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 méthode

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 méthode

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 méthode

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

info() public méthode

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

infoMessage() public méthode

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

interpolate() public méthode

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 méthode

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

log() public méthode

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

notice() public méthode

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

noticeMessage() public méthode

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

validate_ip() public méthode

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

warning() public méthode

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
Résultat null

warningMessage() public méthode

Exceptional occurrences that are not errors.
public warningMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Résultat 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