PHP Класс SimpleLogger

Example of stderr logger: $logger = new SimpleLogger(fopen('php://stderr', 1)); $logger->warn('You are a monkey');
Автор: Rasmus Andersson http://hunch.se/
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
logByMessageKey ( $SimpleLoggerLogLevelsLevel, $messageKey, $context ) Log with message Called from infoMessage(), errorMessage(), and so on

Описание методов

__construct() публичный Метод

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

adminCSS() публичный Метод

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

adminJS() публичный Метод

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

alert() публичный статический Метод

Action must be taken immediately.
public static alert ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

alertMessage() публичный Метод

Action must be taken immediately.
public alertMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

critical() публичный статический Метод

Example: Application component unavailable, unexpected exception.
public static critical ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

criticalMessage() публичный Метод

Critical conditions.
public criticalMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

debug() публичный Метод

Detailed debug information.
public debug ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

debugMessage() публичный Метод

Detailed debug information.
public debugMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

emergency() публичный статический Метод

System is unusable.
public static emergency ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

emergencyMessage() публичный Метод

System is unusable.
public emergencyMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

error() публичный Метод

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
Результат null

errorMessage() публичный Метод

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
Результат null

getCapability() публичный Метод

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

getInfo() публичный Метод

Get array with information about this logger
public getInfo ( ) : array
Результат array

getInfoValueByKey() публичный Метод

Return single array entry from the array in getInfo() Returns the value of the key if value exists, or null
С версии: 2.5.4
public getInfoValueByKey ( $key ) : Mixed
Результат Mixed

getLogRowDetailsOutput() публичный Метод

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
Результат string HTML-formatted output

getLogRowHeaderOutput() публичный Метод

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
Результат string HTML

getLogRowPlainTextOutput() публичный Метод

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() публичный Метод

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() публичный Метод

Returns additional headers with ip number from context
С версии: 2.0.29
public get_event_ip_number_headers ( $row )

get_ip_number_header_keys() публичный Метод

Returns array with headers that may contain user IP
С версии: 2.0.29

info() публичный Метод

Example: User logs in, SQL logs.
public info ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

infoMessage() публичный Метод

Example: User logs in, SQL logs.
public infoMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

interpolate() публичный Метод

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() публичный Метод

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

log() публичный Метод

Logs with an arbitrary level.
public log ( mixed $level, string $message, array $context = [] ) : null
$level mixed
$message string
$context array
Результат null

notice() публичный Метод

Normal but significant events.
public notice ( string $message, array $context = [] ) : null
$message string
$context array
Результат null

noticeMessage() публичный Метод

Normal but significant events.
public noticeMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

validate_ip() публичный Метод

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

warning() публичный Метод

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
Результат null

warningMessage() публичный Метод

Exceptional occurrences that are not errors.
public warningMessage ( string $message, array $context = [] ) : null
$message string key from getInfo messages array
$context array
Результат null

Описание свойств

$lastInsertID публичное свойство

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

$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
public $messages

$slug публичное свойство

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