-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadme.txt
53 lines (40 loc) · 2.32 KB
/
readme.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
=== WP Monolog ===
Contributors: rickycheers
Tags: monolog, log, debug
Requires at least: 3.9
Tested up to: 4.1.1
WordPress plugin that enables logging capabilities for theme and/or plugin development.
== Description ==
WP Monolog is a very lightweight plugin which purpose is to integrate [Monolog](https://github.com/Seldaek/monolog) into WordPress, allowing theme or plugin developers to log messages to files, for debugging purposes, or to email, to alert on failures.
== Usage ==
A global variable named `$logger` is available and it's an instance of `Monolog\Logger`, so you can use it as you would normally use monolog:
<?php
global $logger;
$logger->addInfo("An info message");
$logger->addWarning("A warning message");
$logger->addError("An error message");
**Info** logs will be sent to the 'default' stream handler, which is a log file available at `wp-content/plugins/wp-monolog/log/yy-mm-dd_wp_monolog.log`.
**Error** logs will be sent by email to the site administrator. You can change this on the settings page of the plugin. ***WordPress Admin > Tools > WP Monolog***
Another global variable exists which is `$wp_monolog`, this instance is helpful at the moment to get new `Monolog\Logger` instances on demand. This is useful for example when you have different features spread across your theme or plugins and you want to create specific log records per feature for better error/warning/info tracking.
**Example:**
<?php
function greet(){
global $wp_monolog;
$greet_logger = $wp_monolog->getLoggerInstance('GreetLog');
try{
$greet_logger->addInfo('About to greet');
sayHello();
} catch ( Exception $e ){
$greet_logger->addError('Oops, something went wrong with the greeting message');
}
}
function replyGreeting(){
global $wp_monolog;
$reply_greeting_logger = $wp_monolog->getLoggerInstance('ReplyGreetingLog');
$reply_greeting_logger->addInfo('Replying greeting');
echo "Hello yourself!";
}
The above examples will result in a log record similar to this (in order of appearance):
[yyyy-mm-dd hh:ii:ss] GreetLog.INFO: Message: About to greet
[yyyy-mm-dd hh:ii:ss] GreetLog.ERROR: Message: Oops, something went wrong with the greeting message
[yyyy-mm-dd hh:ii:ss] ReplyGreetingLog.INFO: Message: Replying greeting