-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathadvanced.php
More file actions
41 lines (32 loc) · 1.4 KB
/
advanced.php
File metadata and controls
41 lines (32 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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';
// We need a transport - UDP via port 12201 is standard.
$transport = new Gelf\Transport\UdpTransport("127.0.0.1", 12201, Gelf\Transport\UdpTransport::CHUNK_SIZE_LAN);
// To mute all connection related exceptions, as it may be useful in logging, we can wrap the transport:
//
// $transport = new Gelf\Transport\IgnoreErrorTransportWrapper($transport);
// While the UDP transport is itself a publisher, we wrap it in a real Publisher for convenience.
// A publisher allows for message validation before transmission, and also supports sending
// messages to multiple backends at once.
$publisher = new Gelf\Publisher();
$publisher->addTransport($transport);
// Now we can create custom messages and publish them
$message = new Gelf\Message();
$message->setShortMessage("Foobar!")
->setLevel(\Psr\Log\LogLevel::ALERT)
->setFullMessage("There was a foo in bar")
;
$publisher->publish($message);
// The implementation of PSR-3 is encapsulated in the Logger-class.
// It provides high-level logging methods, such as alert(), info(), etc.
$logger = new Gelf\Logger($publisher);
// Now we can log...
$logger->alert("Foobaz!");