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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.