-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
// 1. Install the GELF classes from https://github.com/Graylog2/gelf-php | ||
require 'GELFMessage.php'; | ||
require 'GELFMessagePublisher.php'; | ||
|
||
require '../lib/Analog.php'; | ||
|
||
Analog::handler (Analog\Handler\GELF::init ( | ||
'localhost' | ||
)); | ||
|
||
Analog::log ('Error message'); | ||
Analog::log (array ('Debug info', __FILE__, __LINE__), Analog::DEBUG); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Analog\Handler; | ||
|
||
/** | ||
* Send the log message to a Graylog2 server (http://graylog2.org/). | ||
* | ||
* Usage: | ||
* | ||
* // First include the GELF classes from | ||
* // https://github.com/Graylog2/gelf-php | ||
* require 'GELFMessage.php'; | ||
* require 'GELFMessagePublisher.php'; | ||
* | ||
* // Initialize the Analog GELF handler | ||
* Analog::handler (Analog\Handler\GELF::init ( | ||
* '172.16.22.30' | ||
* )); | ||
* | ||
* // Send a message with file and line number | ||
* Analog::log (array ('Log me', __FILE__, __LINE__), Analog::DEBUG); | ||
* | ||
* // Send an ordinary message | ||
* Analog::log ('An error message'); | ||
*/ | ||
class GELF { | ||
public static function init ($host = '127.0.0.1', $port = \GELFMessagePublisher::GRAYLOG2_DEFAULT_PORT) { | ||
$publisher = new \GELFMessagePublisher ($host, $port); | ||
|
||
return function ($info) use ($publisher) { | ||
$message = new \GELFMessage (); | ||
$message->setHost ($info['machine']); | ||
$message->setLevel ($info['level']); | ||
|
||
if (is_array ($info['message'])) { | ||
$message->setShortMessage ($info['message'][0]); | ||
$message->setFullMessage ($info['message'][0]); | ||
$message->setFile ($info['message'][1]); | ||
$message->setLine ($info['message'][2]); | ||
} else { | ||
$message->setShortMessage ($info['message']); | ||
$message->setFullMessage ($info['message']); | ||
} | ||
|
||
$publisher->publish ($message); | ||
}; | ||
} | ||
} |