PHP Agent

This agent posts events and exception data to Loggr from your PHP-based website. Includes a fluent interface to posting events.

Installing
Posting Events
Handling Exceptions

Installing

Installing the PHP agent is very simple. Download the loggr.php file to your web server reference the file using 'require_once' in your PHP application.

top

Posting Events

As pointed out in the Installation section above, reference the loggr.php file from you PHP page. Then instantiate the $loggr class.

<?php 

  require_once 'loggr.php';

  // creating class for using fluent syntax
  $loggr = new Loggr("YOUR-LOGKEY", "YOUR-APIKEY");

?>
You'll need to add your LOGKEY and APIKEY from your Loggr log when you instantiate the $loggr class.

Using the $loggr class, you can post events using the fluent-style interface.

  // create a simple event
  $loggr->Events->Create()
        ->Text("Simple fluent event")
        ->Post();

  // more complex event
  $world = "World";
  $loggr->Events->Create()
        ->TextF("hello%s", $world)
        ->Tags("tag1 tag2 tag3")
        ->Link("http://google.com")
        ->Source("dave")
        ->Data("foobar")
        ->Value(3)
        ->Geo(-14.456, 73.6879)
        ->Post();

  // trace a variable
  $var = "TEST VAR";
  $loggr->Events->CreateFromVariable($var)
        ->Text("Tracing TEST VAR")
        ->Post();

Alternatively you can use a non-fluent syntax:

  $client = new LogClient("YOUR-LOGKEY", "YOUR-APIKEY");

  // create a simple event
  $ev = new Event();
  $ev->Text = "Simple non-fluent event";
  $client->Post($ev); 

top

Handling Exceptions

It's pretty easy to send exceptions to Loggr as well.

  // trace an exception
  try {
    $error = 'Always throw this error';
    throw new Exception($error);
  } catch (Exception $e) {
    $loggr->Events->CreateFromException($e)
          ->Text("Exception")
          ->Post();
  }

top