-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bzikarsky
committed
Jan 23, 2014
1 parent
dea5bee
commit c5d4c52
Showing
4 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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); | ||
|
||
// 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 it calso supports to send 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") | ||
->setFacility("example-facility") | ||
; | ||
$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, "example-facility"); | ||
|
||
// Now we can log... | ||
$logger->alert("Foobaz!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?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!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,15 +14,19 @@ | |
use Gelf\Encoder\EncoderInterface; | ||
use Gelf\MessageInterface as Message; | ||
use Gelf\Encoder\CompressedJsonEncoder as DefaultEncoder; | ||
use Gelf\MessageInterface; | ||
use Gelf\PublisherInterface; | ||
use RuntimeException; | ||
|
||
/** | ||
* UdpTransport allows the transfer of GELF-messages to an compatible GELF-UDP-backend | ||
* as described in https://github.com/Graylog2/graylog2-docs/wiki/GELF | ||
* | ||
* It can also act as a direct publisher | ||
* | ||
* @author Benjamin Zikarsky <[email protected]> | ||
*/ | ||
class UdpTransport implements TransportInterface | ||
class UdpTransport implements TransportInterface, PublisherInterface | ||
{ | ||
const CHUNK_GELF_ID = "\x1e\x0f"; | ||
const CHUNK_MAX_COUNT = 256; // sequence-size is stored in a CHAR | ||
|
@@ -116,6 +120,11 @@ public function send(Message $message) | |
return 1; | ||
} | ||
|
||
public function publish(Message $message) | ||
{ | ||
$this->send($message); | ||
} | ||
|
||
/** | ||
* Sends given string in multiple chunks | ||
* | ||
|