Skip to content

Instantly share code, notes, and snippets.

@InFog
Created July 5, 2019 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InFog/002402866979b89ee4d6428adeb6d916 to your computer and use it in GitHub Desktop.
Save InFog/002402866979b89ee4d6428adeb6d916 to your computer and use it in GitHub Desktop.
<?php
include __DIR__ . "/vendor/autoload.php";
use Elastica\Client;
use Monolog\Formatter\LogstashFormatter;
use Monolog\Handler\ElasticSearchHandler;
use Monolog\Logger;
$logger = new Logger("MyApp");
$client = new Client([
'host' => 'localhost',
'port' => 9200,
]);
$handler = new ElasticSearchHandler($client);
$logger->pushHandler($handler);
$logger->info("Running the app");
$n = rand(0, 10);
if ($n > 9) {
$logger->error("This is an error!!!");
} else {
$logger->warn("Something happened");
}
$logger->info("Finished running the app");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment