Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tradjick's avatar

L5 Logging to GrayLog2

Trying to log to GrayLog2 using monolog as exposed by the Log facade. Thrown exceptions are logging fine, however when I try to use Log::alert() and the like, I get thrown a "Graylog-Server didn't answer properly, expected 'HTTP/1.x 202 Accepted', response is ''" exception.

Temporarily I am inserting the following code into the start of my routes.php.

$monolog = \Illuminate\Support\Facades\Log::getMonolog(); $monolog_handler=new \Monolog\Handler\GelfHandler(new \Gelf\Publisher(new \Gelf\Transport\HttpTransport(env('GRAYLOG2_SERVER'),env('GRAYLOG2_PORT'),'/gelf'))); $monolog_handler->setFormatter(new \Monolog\Formatter\GelfMessageFormatter(env('GRAYLOG2_SOURCE'))); $monolog->pushHandler($monolog_handler);

Any ideas why I'm getting the two differing behaviours?

0 likes
2 replies
drewmiranda's avatar

What does your input look like on the graylog side?

The error "Graylog-Server didn't answer properly, expected 'HTTP/1.x 202 Accepted', response is ''" exception. makes me think that either the graylog node isn't listening on the corect port or expecting the data type.

For /gelf you will want a Gelf HTTP input. Can you confirm that

  1. graylog input is gelf http and port (say 12345 for example)
  2. your config matches correctly with graylog server, gryalog port

Do you see any logging on the graylog side? It will log any odd connections it gets in the server log. I can't say exactly but on my nodes the log is something like this

/graylog2/graylog-1.0.0/log/graylog-server.log

If mongo is sending to the correct server and port you should see something in there about the request. Hope that helps.

1 like
tradjick's avatar

Oh FFS! I am an idiot. Just got back to this and noticed that between the 2 sessions testing this my firewall had reset to default rules! I apologise. Thank you for your reply @drewmiranda

1 like

Please or to participate in this conversation.