Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added handler to write to Amon server monitoring tool

  • Loading branch information...
commit b2f5143a2a446a9201cae7114565720a8685695d 1 parent 264e9d6
@jbroadway authored
Showing with 59 additions and 1 deletion.
  1. +2 −1  README.md
  2. +14 −0 examples/amon.php
  3. +43 −0 lib/Analog/Handler/Amon.php
View
3  README.md
@@ -14,9 +14,10 @@ By default, this class will write to a file named `sys_get_temp_dir() . '/analog
using the format `"machine - date - level - message\n"`, making it usable with no
customization necessary.
-Analog also comes with a dozen pre-written handlers in the Analog/Handlers folder,
+Analog also comes with over a dozen pre-written handlers in the Analog/Handlers folder,
with examples for each in the examples folder. These include:
+* Amon - Send logs to the [Amon](http://amon.cx/) server monitoring tool
* Buffer - Buffer messages to send all at once (works with File, Mail, Stderr, and Variable handlers)
* File - Append messages to a file
* FirePHP - Send messages to [FirePHP](http://www.firephp.org/) browser plugin
View
14 examples/amon.php
@@ -0,0 +1,14 @@
+<?php
+
+// 1. Install the Amon PHP lib from http://amon.cx/guide/clients/php/
+require 'amon.php';
+
+Analog::handler (Analog\Handler\Amon::init (
+ 'http://127.0.0.1',
+ 2464
+));
+
+Analog::log ('Error message');
+Analog::log ('Debug info', Analog::DEBUG);
+
+?>
View
43 lib/Analog/Handler/Amon.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Analog\Handler;
+
+/**
+ * Send the log message to an Amon monitoring server (http://amon.cx/).
+ *
+ * Usage:
+ *
+ * // First include the Amon classes
+ * require 'amon.php';
+ *
+ * // Initialize the Analog Amon handler
+ * Analog::handler (Analog\Handler\Amon::init (
+ * 'http://127.0.0.1', // server address
+ * 2464, // port number
+ * 'abc123def456' // application key
+ * ));
+ */
+class Amon {
+ public static function init ($host = 'http://127.0.0.1', $port = 2464, $key = false) {
+ \Amon::config (array (
+ 'host' => $host,
+ 'port' => $port,
+ 'application_key' => $key
+ ));
+
+ $tags = array (
+ 0 => 'urgent',
+ 1 => 'alert',
+ 2 => 'critical',
+ 3 => 'error',
+ 4 => 'warning',
+ 5 => 'notice',
+ 6 => 'info',
+ 7 => 'debug'
+ );
+
+ return function ($info) use ($tags) {
+ \Amon::log ($info, array ($tags[$info['level']]));
+ };
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.