Git Product home page Git Product logo

ecs-logging-php's Introduction

Build Status

ECS Logging for PHP

Transform your application logs to structured logs that comply with the Elastic Common Schema (ECS). In combination with Filebeat, send your logs directly to Elasticsearch and leverage Kibana's Logs app to inspect all of your logs in a single place. This provides more observability for your PHP applications, for example, by correlating your logs with APM traces.

See the PHP ECS logging documentation to get started, or the ecs-logging repo for other ECS logging libraries and more resources about ECS & logging.


Install

composer require elastic/ecs-logging

Examples and Usage

Library Support

References

Contributing

See contributing documentation.

License

This software is licensed under the Apache 2 license.

ecs-logging-php's People

Contributors

apmmachine avatar bmorelli25 avatar droet avatar intuibase avatar philkra avatar pimjansen avatar reakaleek avatar segrax avatar sergeykleyman avatar thinkspill avatar v1v avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ecs-logging-php's Issues

Full type support

At this moment we are using a custom implementation of this library which was not production ready at that point.

To make things easy there we just moved array keys from the "extra" field of monolog to the root level if the first key matches the ecs schema. This is of course not an ideal situation.

I now notice we have added some types in this lib. Isnt it better if we just fully type the full ecs schema?

So this means we create a class for each root type of the schema where people can easily inject it as well. The types would be fully optional where imo you never want to restrict what you log too much (only the how).

Is this the way to go? If yes i do not mind giving it a shot so we can have a proper way to log in a valid schema format.

PHP 7.4.18 Notice: Undefined property: Elastic\\Monolog\\Formatter\\ElasticCommonSchemaFormatter::$maxNormalizeDepth

PHP message: PHP Notice: Undefined property: Elastic\\Monolog\\Formatter\\ElasticCommonSchemaFormatter::$maxNormalizeDepth in /var/www/vendor/elastic/ecs-logging/src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php on line 60

PHP 7.4.18 (cli) (built: May 3 2021 12:02:44) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.18, Copyright (c), by Zend Technologies

psr/log dependency update

Hi,

The composer require elastic/ecs-logging command generates this:

Using version ^1.0 for elastic/ecs-logging
./composer.json has been updated
Running composer update elastic/ecs-logging
Loading composer repositories with package information
Updating dependencies                                 
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - elastic/ecs-logging[1.0.0, ..., 1.0.2] require php ^7.2 -> your php version (8.0.9) does not satisfy that requirement.
    - elastic/ecs-logging 1.0.3 requires psr/log ^1.0.1 -> found psr/log[1.0.1, ..., 1.1.4] but the package is fixed to 2.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
    - Root composer.json requires elastic/ecs-logging ^1.0 -> satisfiable by elastic/ecs-logging[1.0.0, 1.0.1, 1.0.2, 1.0.3].

Can you update the psr/log dependency in composer.json to "psr/log": "^1.1 || ^2.0" ?

Regards,
Csongor.

Missing src/Elastic/Types after composer require

I'm not sure how these files could be missing, but I've tried both in my main project and a default empty composer init project, and once installed, the only actual file present under src is src/Elastic/Monolog/Formatter/ElasticCommonSchemaFormatter.php.

src/Elastic/Types does not exist.

Reproduction:

mkdir emptyproject && cd emptyproject
composer init
[... hit enter to accept all defaults ...]
composer require elastic/ecs-logging
ls -la vendor/elastic/ecs-logging/src/Elastic/Monolog # exists
ls -la vendor/elastic/ecs-logging/src/Elastic/Types # does not exist

Do you get the same result?

Multiple monolog versions

@philkra how are we going to handle multiple versions of frameworks? Since i see you included them in the dev deps. But installing multiple majors there will be a problem.

How will we handle that? I guess we should mock them instead instead of putting them as dev dependency isnt it?

Release?

The readme lists support for monolog v2 but the latest version on packagist (elastic/ecs-logging) is an older version (1.0.1) that is not synced up with the instructions in this repo.

Maybe release an alpha/beta so its less confusing? right now it's not clear you will have to pull the repo using "dev-master'

[Feature Request] Compatibility with elasticsearchHandler

Would be nice if we could use ECS with Monolog\Handler\ElasticsearchHandler to send the logs directly to elastic search

Unfortunately it now throws with Uncaught InvalidArgumentException: ElasticsearchHandler is only compatible with ElasticsearchFormatter.

I need more documentation and working examples ...

Hi guys , would you please point some working examples for this library ?
Is it possible to post resulting json into elastic search api ? how to do ?
Is there a method list ? how can I add my custom fields ?

Thanks!!!

Incorrectly marked as being a PSR-3 `psr/log-implementation` provider

Hey there! ๐Ÿ‘‹ Please correct me if I'm mistaken, but I noticed this package is marked as being a provider of psr/log-implementation (PSR-3), but it does not appear to implement the interface anywhere. It shouldn't be marked as a provider of a PSR implementation if it does not provide said implementation. ๐Ÿ˜„

De-dot labels' keys

Remove the dots (.) of the each key in the labels field as ES is storing the values as nested in such scenarios, but that would violate the mapping schema. Hence, we need to flatten the keys by replacing each . with a _.

Error while installing with PHP8

Could you add support for PHP 8?

$ composer require elastic/ecs-logging 
                                                                                                                           
[InvalidArgumentException]                                                                                                 
Package elastic/ecs-logging has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version 

$ php -v
PHP 8.0.3 (cli) (built: Mar  5 2021 07:54:30) ( NTS )

$ composer -V
Composer version 2.0.12 2021-04-01 10:14:59

Extras data is ignored

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.