to send logs from php application to graylog using monolog
Asked Answered
M

1

6

I have installed graylog server and its dependencies.Trying to send logs from my php application to graylog server using Monolog. But I am not aware of how to use the Gelf handler.I have seen the GelfHandlerTest.php that is present inside the project Monolog but I am not able to set my publisher and create the handler.Can please anybody explain me with a sample code how to use it.

Trying to send logs from my localhost apache to a server that is set up in the same private network where the graylog is installed.

The testLogging file that is getting executed in PHP are,

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\GelfHandler;
use Gelf\Message;
use Monolog\Formatter\GelfMessageFormatter;


$handler = new GelfHandler($publisher);

How to set the publisher in monolog?

Any sort of help is appreciated.Thanks

Marquittamarr answered 17/3, 2016 at 9:6 Comment(1)
Please provide a minimal, complete and verifiable example: stackoverflow.com/help/mcveRosena
T
3

Please check the following links:

https://laracasts.com/discuss/channels/general-discussion/l5-logging-to-graylog2

Graylog2 with Symfony 2 (Monolog)

Basically you need something like: $handler = new GelfHandler(new Gelf\Publisher( new Gelf\Transport\TcpTransport(HOST,PORT) ));

The transport must be the input you added in the grayog platform.Ex: new TcpTransport(127.0.0.1,12201)

Available transports: https://github.com/bzikarsky/gelf-php/tree/master/src/Gelf/Transport

Hope it helps.

Treasurehouse answered 26/5, 2018 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.