<?php /* * This file is part of the php-gelf package. * * (c) Benjamin Zikarsky <http://benjamin-zikarsky.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../vendor/autoload.php'; // When creating a logger without any options, it logs automatically to localhost:12201 via UDP // For a move advanced configuration, check out the advanced.php example $logger = new Gelf\Logger(); // Log! $logger->alert("Foobaz!");
<?php require_once __DIR__ . DIRECTORY_SEPARATOR . '../../vendor/autoload.php'; $transport = new Gelf\Transport\TcpTransport("127.0.0.1", 12201); $publisher = new Gelf\Publisher(); $publisher->addTransport($transport); $logger = new Gelf\Logger($publisher); $logger->debug("A debug message."); $logger->alert("An alert message", ['structure' => ['data' => [0, 1]]]); try { throw new Exception("Test exception"); } catch (Exception $e) { $logger->emergency("Exception example", array('exception' => $e)); } $message = new Gelf\Message(); $message->setShortMessage("Structured message")->setLevel(\Psr\Log\LogLevel::ALERT)->setFullMessage("There was a foo in bar")->setFacility("example-facility")->setAdditional('foo', 'bar')->setAdditional('bar', 'baz'); $publisher->publish($message); $logger->warning("A warning message.", ['structure' => ['with' => ['several' => 'nested', 'levels']]]); $logger->info(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . "bacon.txt"));
<?php /* * This file is part of the php-gelf package. * * (c) Benjamin Zikarsky <http://benjamin-zikarsky.de> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../vendor/autoload.php'; // Logger takes an optional Publisher and a facility name // If the publisheris ommitted (or equals null) a default publisher // is created which logs GELF to udp://localhost:12201 $logger = new Gelf\Logger(null, "test facility"); // throw an exception, catch it immediatly and pass it // to the logger try { throw new Exception("test exception"); } catch (Exception $e) { $logger->emergency("Exception example", array('exception' => $e)); }