Logging formatters for ECS

Overview

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

  • Currently only Monolog:2.* is supported.
  • The major version of this library is compatible with the major version of ECS.

References

Contributing

See contributing documentation.

License

This software is licensed under the Apache 2 license.

Comments
  • Error while installing with PHP8

    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
    
    opened by lichtner 6
  • Full type support

    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.

    opened by pimjansen 6
  • Fix: include timezone in the @timestamp

    Fix: include timezone in the @timestamp

    Otherwise logs might not show up in Kibana until hours later, in my case after 2 hours since I am gmt+2

    Before: 2020-09-01T19:43:37.000000Z After: 2020-09-01T19:43:37.000000+02:00

    opened by DRoet 4
  • docs: update readme

    docs: update readme

    Fixes out of date links in the readme and links to the new Elastic.co documentation.

    For https://github.com/elastic/ecs-logging-php/issues/20.

    ~This PR is currently blocked by https://github.com/elastic/docs/pull/2055.~

    documentation 
    opened by bmorelli25 2
  • [CI] automate release process

    [CI] automate release process

    What

    Update docs with the contributing guideline. Add release guideline. Enable release automation when a tag release is created with the format d+.\d+.\d+ Release automation:

    • will create a release in github matching the tag.
    • will create a changelog using the gren app, filtering only the Pull Requests with certain labels:
      • "Breaking changes" category for all the PRs with the breaking label.
      • "Bug fixes" category for all the PRs with the bug or fix labels.
      • "Features" category for all the PRs with the enhancement, feature or feat labels.

    Actions

    • [x] Validate scripts locally

    How to run locally

    $ GITHUB_TOKEN=${GREN_GITHUB_TOKEN} TAG_NAME=1.0.2 make -f .ci/Makefile release
    

    Output

    Getting gren config from local file /app/.ci/.grenrc.js
    
    🤖  - Generate release notes:
    ===================================
    ✔ Releases found: 3
    ✔ Tags found: 1.0.2
    ✔ Pull Requests found: 13
    ✔ 1.0.2 has been successfully created!
    See the results here: https://github.com/elastic/ecs-logging-php/releases/tag/1.0.2
    

    Tests

    image

    opened by v1v 2
  • [CI] use obltGitHubComments

    [CI] use obltGitHubComments

    What does this PR do?

    Use https://github.com/elastic/apm-pipeline-library/blob/master/vars/obltGitHubComments.txt

    Why is it important?

    Avoid hardcoded strings and easy to normalise the GitHub comments in all the oblt projects

    You can also see in the GitHub comment that there is a specific section for some of those GitHub comments called 🤖 GitHub comments

    Team:Automation 
    opened by v1v 1
  • Fixed incompatibilities with the spec

    Fixed incompatibilities with the spec

    • [x] Fixed incorrect use of log.origin for error (log.origin should refer to location of log statement not where error was thrown)
    • [x] Added support for 'extra' info. This allows to support Monolog processors such as TagProcessor.
    • [x] Added support for log.origin. This allows to support Monolog IntrospectionProcessor.
    bug 
    opened by SergeyKleyman 1
  • [META 27] Add ecs-logging-php to the doc build

    [META 27] Add ecs-logging-php to the doc build

    To do

    • [x] Move docs to asciidoc https://github.com/elastic/ecs-logging-php/pull/18
    • [x] Open PR in elastic/docs to add to the build https://github.com/elastic/docs/pull/2055
    • [x] Open infra ticket to add the elasticsearch/ci docs check to this repo (see link in timeline below)
    • [x] Add the elasticsearch/ci docs webhook to the repo
    • [x] Remove content from readme and link to published docs https://github.com/elastic/ecs-logging-php/pull/21
    • [x] Link to new docs from ecs-logging https://github.com/elastic/ecs-logging/pull/53
    documentation 
    opened by bmorelli25 1
  • Updated implementation to keep it compatible with the latest ECS logging spec

    Updated implementation to keep it compatible with the latest ECS logging spec

    • Moved ElasticCommonSchemaFormatter from Elastic\Monolog\v2\Formatter back to Elastic\Monolog\Formatter
      • To keep backward compatible with already released elastic/ecs-logging 1.0.1
      • For more seamless future support of both Monolog v1 and v2
    • To make output compatible with the latest ECS logging spec
      • Extracted log.level from log
      • Reordered fields
      • Added ecs.version
    enhancement 
    opened by SergeyKleyman 1
  • Multiple monolog versions

    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?

    opened by pimjansen 1
  • ci(jenkins): fixes sanity check

    ci(jenkins): fixes sanity check

    I guess, we might need to fix the shared library to ensure the env variable is passed otherwise:

    18:06:28  + python -
    18:06:28  + curl https://pre-commit.com/install-local.py
    18:06:28    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    18:06:28                                   Dload  Upload   Total   Spent    Left  Speed
    18:06:28  
      0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
    100  2590  100  2590    0     0  11511      0 --:--:-- --:--:-- --:--:-- 11511
    18:06:28  Traceback (most recent call last):
    18:06:28    File "<stdin>", line 103, in <module>
    18:06:28    File "<stdin>", line 64, in main
    18:06:28    File "/usr/lib/python2.7/UserDict.py", line 40, in __getitem__
    18:06:28      raise KeyError(key)
    18:06:28  KeyError: u'HOME'
    
    opened by v1v 1
  • Migrate Jenkinsfile to GH Actions Workflow

    Migrate Jenkinsfile to GH Actions Workflow

    Summary

    Migrate Jenkinsfile to GH Actions Workflow

    Tasks

    • [ ] Migrate Jenkinsfile
    • [ ] Delete Jenkins Job config
    • [ ] Delete Jenkins Job
    • [ ] Update sheet
    opened by reakaleek 1
  • Monolog and PHP 8 updates

    Monolog and PHP 8 updates

    This update fixes an issue working with monolog 2.5 and above, where the IntrospectionProcessor added a callType field to its output. Since the ElasticCommonSchemaFormatter does not know about this field, it gets added as a top level key instead of within log.origin even when $useLogOriginFromContext is set. This can be demonstrated by simply checking out the main branch of this repo and running composer install && composer test.

    This fixes the issue by adding callType to the list of known origin keys and also uses it (if available, so will still work with monolog < 2.5) within the log.origin.function field. E.g. MyClass::myFunction or MyClass->myFunction.

    As a minor additional change it also marks compatibility with psr/log 2.x and 3.x.

    opened by phil-nelson 2
  • psr/log dependency update

    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.

    opened by bandicsongor 1
  • Set

    Set "ecs.version" via ElasticCommonSchemaFormatter::__construct()

    Now is ECS_VERSION is const, but I need to set version 1.5.0, easiest way is via constructor like this. My version is backward compatible.

    Usage in Laravel:

    class EcsFormatter
    {
        public function __invoke($logger)
        {
            foreach ($logger->getHandlers() as $handler) {
                $handler->setFormatter(new ElasticCommonSchemaFormatter([], '1.5.0'));
            }
        }
    }
    
    opened by lichtner 2
  • PHP 7.4.18 Notice:  Undefined property: Elastic\\Monolog\\Formatter\\ElasticCommonSchemaFormatter::$maxNormalizeDepth

    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

    opened by serker72 0
Releases(1.0.3)
Owner
elastic
elastic
😎 Tracy: the addictive tool to ease debugging PHP code for cool developers. Friendly design, logging, profiler, advanced features like debugging AJAX calls or CLI support. You will love it.

Tracy - PHP debugger Introduction Tracy library is a useful helper for everyday PHP programmers. It helps you to: quickly detect and correct errors lo

Nette Foundation 1.6k Dec 23, 2022
A Simple Logging Class For PHP

KLogger: Simple Logging for PHP A project written by Kenny Katzgrau and Dan Horrigan. About KLogger is an easy-to-use PSR-3 compliant logging class fo

Kenny Katzgrau 964 Dec 11, 2022
PHP logging library that is highly extendable and simple to use.

Analog - Minimal PHP logging library Copyright: (c) 2012-Present Johnny Broadway License: MIT A minimal PHP logging package based on the idea of using

Aband*nthecar 331 Dec 21, 2022
Manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.

Jobby, a PHP cron job manager Install the master jobby cron job, and it will manage all your offline tasks. Add jobs without modifying crontab. Jobby

null 1k Dec 25, 2022
🐣 Backend-Logging aller Aktionen im Backend

Addon BE_Logger - Backend-Logging Mit dem Addon be_logger können die Backend-Zugriffe aller Benutzer in einer Logging-Tabelle ausgegeben werden. Es gi

Friends Of REDAXO 14 Sep 12, 2022
Application for logging HTTP and DNS Requests

Request Logger Made by Adam Langley ( https://twitter.com/adamtlangley ) What is it? Request logger is a free and open source utility for logging HTTP

null 13 Nov 28, 2022
Emoncms is an open-source web application for processing, logging and visualising energy, temperature and other environmental data and is part of the OpenEnergyMonitor project.

Emoncms is an open-source web application for processing, logging and visualising energy, temperature and other environmental data and is part of the OpenEnergyMonitor project.

Emoncms 1.1k Dec 22, 2022
This package is for centralized logging of multiple Laravel application into one connection.

Laralogs This package is for centralized logging of multiple Laravel application into one connection. Installation You can install the package via com

Remon 4 Apr 26, 2022
Simple blog concept with features such authentication (creating accounts, logging in) and commenting.

Simple blog concept with features such authentication (creating accounts, logging in) and commenting. Styling done with tailwindcss and inline javascript is provided by alpineJS.

null 1 Oct 26, 2021
Here is an Instagram Guest API. Gather all public information as JSON format without logging yourself.

Here is an Instagram Guest API. Gather all public information as JSON format without logging yourself. It's all automation and time saving.

Quatrecentquatre 1 Nov 2, 2021
The package provides the ability to write logs into the database synchronously or asynchronously, along with other logging channels.

Laravel database log channel The package provides the ability to write logs into the database synchronously or asynchronously, along with other loggin

Jarosław Goszowski 18 Nov 28, 2022
RadPHP Logging Component

RadPHP Logging Component The Logging library provides multiple logging adapters using a simple interface. With the Logger class it is possible to send

RadPHP 9 Sep 8, 2021
A simple Laravel event log package for easy model based logging.

Karacraft Logman A simple Model Event Logging Package Usage Installation composer require karacraft/logman Migrate php artisan migrate Publish php a

Karacraft 0 Dec 28, 2021
Best logging support into Nette Framework (@nette)

Website ?? contributte.org | Contact ????‍?? f3l1x.io | Twitter ?? @contributte Usage To install the latest version of contributte/monolog use Compose

Contributte 21 Dec 1, 2022
A PocketMine-MP plugin for logging Exceptions to a Sentry server

Sentry A PocketMine-MP plugin for logging Exceptions to a Sentry server. Asynchronous logging If you want to log exceptions in a thread-safe way, you

null 4 Apr 9, 2022
Monolog logging support for Slim Framework

Monolog Logging for Slim Framework This repository adds support for logging to Monolog to the Slim Framework. Installation MonologWriter takes an arra

null 113 Dec 18, 2022
High-performance API performing logging for PHP applications into files or SysLog

Logging API Table of contents: About Configuration Binding Points Logging Installation Unit Tests Reference Guide Specifications How Are Log Lines For

Lucian Gabriel Popescu 0 Jan 9, 2022
A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF world conversion.

ChunkLoader A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF

null 2 Aug 10, 2022
PocketMine-MP To Discord Chat Logging.

Welcome To PocketCord PocketCord is a PocketMine-MP plugin designed to link discord and your PocketMine-MP Server with quick and easy setup! Installat

null 2 Sep 15, 2022