Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extras data is ignored #13

Open
chippyash opened this issue Apr 7, 2020 · 2 comments
Open

Extras data is ignored #13

chippyash opened this issue Apr 7, 2020 · 2 comments
Assignees

Comments

@chippyash
Copy link

Hi,
I'm curious. Reading through source code to figure out why data that I am inserting via processors (e.g. MonoLog WebProcessor) is not being displayed by your formatter, I see that you are completely ignoring the extras array member of the Monolog record structure, and instead relying on data being in the context member of the record. This appears to be somewhat counter-intuitive to the way that Monolog normally works.

Is this purposeful, or just an unhandled scenario at the present time?

use \Codeception\Test\Unit as UnitTest;
use Elastic\Monolog\Formatter\ElasticCommonSchemaFormatter;
use Monolog\Handler\TestHandler;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;

class ECSFormatterTest extends UnitTest
{
    /**
     * Logger
     */
    protected $sut;
    /**
     * @var TestHandler
     */
    protected $handler;

    public function testECSFormatIsSupported()
    {
        $this->sut->error('Test Message', ['func' => __FUNCTION__]);
        $record = $this->handler->getRecords()[0]['formatted'];
        var_dump($record);exit;
    }

    protected function setUp(): void
    {
        $this->handler = new TestHandler();
        $formatter = new ElasticCommonSchemaFormatter();
        $this->handler->setFormatter($formatter);
        //mock a web server
        $serverData = [
            'REQUEST_URI' => '/test',
            'REMOTE_ADDR' => '127.0.0.1',
            'REQUEST_METHOD' => 'GET',
            'SERVER_NAME' => 'zinc.test',
            'HTTP_REFERER' => 'http://zinc.test',
        ];
        $this->sut = new Logger('test', [$this->handler], [new WebProcessor($serverData)]);

    }
}

At the very least I would expect the data that gets injected into extras to get into the output format labels node, as the func item does in the above test snippet. Ideally I would see 'REMOTE_ADDR' being injected to source.ip in the output.

@akzincsystems
Copy link

bump

@SergeyKleyman
Copy link
Contributor

It should be fixed in the latest release (1.0.2).

@SergeyKleyman SergeyKleyman self-assigned this Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants