{"id":15077713,"url":"https://github.com/aubes/ecs-logging-bundle","last_synced_at":"2026-02-18T23:01:29.823Z","repository":{"id":159872180,"uuid":"634823122","full_name":"aubes/ecs-logging-bundle","owner":"aubes","description":"This Symfony bundle provides the Ecs log format","archived":false,"fork":false,"pushed_at":"2023-05-02T08:04:00.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T08:38:32.695Z","etag":null,"topics":["ecs","monolog-formatter","monolog-processor","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aubes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-01T09:41:39.000Z","updated_at":"2024-12-04T10:09:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"18433fb1-a527-4901-891d-69a5aa73110e","html_url":"https://github.com/aubes/ecs-logging-bundle","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/aubes/ecs-logging-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aubes%2Fecs-logging-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aubes%2Fecs-logging-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aubes%2Fecs-logging-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aubes%2Fecs-logging-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aubes","download_url":"https://codeload.github.com/aubes/ecs-logging-bundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aubes%2Fecs-logging-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29597853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T22:25:43.180Z","status":"ssl_error","status_checked_at":"2026-02-18T22:25:42.766Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecs","monolog-formatter","monolog-processor","symfony-bundle"],"created_at":"2024-09-25T04:30:26.527Z","updated_at":"2026-02-18T23:01:29.804Z","avatar_url":"https://github.com/aubes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ecs Logging Bundle\n\n![CI](https://github.com/aubes/ecs-logging-bundle/actions/workflows/php.yml/badge.svg)\n\nThis Symfony bundle provides the [Ecs](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html) log format for Monolog.\n\nIt uses [elastic/ecs-logging](https://github.com/elastic/ecs-logging).\n\nIt is compatible with :\n * PHP 7.4 and 8.x\n * Symfony 5.4 and 6.x\n * Monolog 2.x\n\n## Installation\n\n```shell\ncomposer require aubes/ecs-logging-bundle\n```\n\n## Configuration\n\n### Formatter\n\nFirst, you need to configure the Ecs formatter in monolog:\n\n```yaml\n# config/packages/monolog.yaml\nmonolog:\n    handlers:\n        ecs:\n            # [...]\n            formatter: 'monolog.formatter.ecs'\n```\n\nThen configure the bundle, the configuration looks as follows :\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    monolog:\n        # Register the processors on channels or handlers, not both\n        # To configure channels or handlers is recommended\n        # Default logging channels the processors should be pushed to\n        handlers: []\n\n        # Default logging handlers the processors should be pushed to\n        #channels: []\n\n    processor:\n        # https://www.elastic.co/guide/en/ecs/current/ecs-service.html\n        service:\n            enabled: false\n            name: ~         # Name of the service data is collected from.\n            version: ~      # Version of the service the data was collected from.\n            ephemeral_id: ~ # Ephemeral identifier of this service (if one exists).\n            id: ~           # Unique identifier of the running service.\n            node_name: ~    # Name of a service node.\n            state: ~        # Current state of the service.\n            type: ~         # The type of the service data is collected from.\n\n            #handlers: [] # Logging channels the processor should be pushed to\n            #channels: [] # Logging handlers the processor should be pushed to\n\n        error:\n            enabled: false\n            field_name: 'error'\n\n            #handlers: [] # Logging channels the processor should be pushed to\n            #channels: [] # Logging handlers the processor should be pushed to\n\n        tracing:\n            enabled: false\n            field_name: 'tracing'\n\n            #handlers: [] # Logging channels the processor should be pushed to\n            #channels: [] # Logging handlers the processor should be pushed to\n\n        user:\n            enabled: false\n            domain: ~ # Ecs user domain, example: ldap\n            provider: ~ # Service Id of the Ecs user provider, default: Aubes\\EcsLoggingBundle\\Security\\EcsUserProvider\n\n            #handlers: [] # Logging channels the processor should be pushed to\n            #channels: [] # Logging handlers the processor should be pushed to\n\n        auto_label:\n            enabled: false\n            fields: [] # Name of internal fields, these fields will not be moved\n\n            #handlers: [] # Logging channels the processor should be pushed to\n            #channels: [] # Logging handlers the processor should be pushed to\n```\n\n### Configuration example\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    monolog:\n        handlers: ['ecs']\n\n    processor:\n        service:\n            enabled: true\n            name: 'MyApp'\n            version: '%env(string:ECS_LOGGING_SERVICE_VERSION)%'\n            # [...]\n\n        user:\n            enabled: true\n            domain: ~ # Ecs user domain, example: ldap\n```\n\n```yaml\n# config/packages/monolog.yaml\nmonolog:\n    handlers:\n        # [...]\n\n        ecs:\n            type: stream\n            path: \"%kernel.logs_dir%/%kernel.environment%.ecs.log\"\n            level: info\n            channels: [ \"app\" ]\n            formatter: 'monolog.formatter.ecs'\n```\n\n## Usage\n\n### Service processor\n\n#### Without service processor\n\n```php\nuse Elastic\\Types\\Service;\n\n$service = new Service()\n$service-\u003esetName(/* [...] */);\n$service-\u003esetVersion(/* [...] */);\n\n$logger-\u003einfo('exception.message', [\n    'service' =\u003e new Service(),\n]);\n```\n\n#### With service processor\n\nEnable the processor:\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n    processor:\n        service:\n            enabled: true\n            name: # [...]\n            version: # [...]\n```\n\n```php\n$logger-\u003einfo('message');\n```\n\n### Log error\n\n#### Without error processor\n\n```php\nuse Elastic\\Types\\Error as EcsError;\n\ntry {\n    // [...]\n} catch (\\Exception $e) {\n    $logger-\u003einfo('exception.message', [\n        'error' =\u003e new EcsError($e),\n    ]);\n}\n```\n\n#### With error processor\n\nEnable the processor:\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n    processor:\n        error:\n            enabled: true\n```\n\n```php\ntry {\n    // [...]\n} catch (\\Exception $e) {\n    $logger-\u003einfo('exception.message', [\n        'error' =\u003e $e,\n    ]);\n}\n```\n\n### Tracing\n\n#### Without tracing processor\n\n```php\nuse Elastic\\Types\\Tracing;\n\n// [...]\n\n$logger-\u003einfo('tracing.message', [\n    'tracing' =\u003e new Tracing($traceId, $transactionId),\n]);\n```\n\n#### With tracing processor\n\nEnable the processor:\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n    processor:\n        tracing:\n            enabled: true\n```\n\n```php\n// [...]\n\n$logger-\u003einfo('tracing.message', [\n    'tracing' =\u003e [\n        'trace_id' =\u003e $traceId,\n        'transaction_id' =\u003e $transactionId,\n    ],\n]);\n```\n\n### User\n\n#### Without user processor\n\n```php\nuse Elastic\\Types\\User;\n\n// [...]\n\n$ecsUser = new User();\n$ecsUser-\u003esetId($userId);\n$ecsUser-\u003esetName($userName);\n\n$logger-\u003einfo('exception.message', [\n    'user' =\u003e $ecsUser,\n]);\n```\n\n#### With user processor\n\nEnable the processor:\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n    processor:\n        user:\n            enabled: true\n```\n\n```php\n// [...]\n\n$logger-\u003einfo('message');\n```\n\n### Auto label\n\nTo automatically move all additional fields into the Ecs `labels` field, useful for internal Symfony bundle log.\n\nFor example without the processor, a Symfony log contains these fields :\n\n```json\n{\n    \"route\": \"_wdt\",\n    \"route_parameters\": {\n        \"_route\": \"_wdt\",\n        \"_controller\": \"web_profiler.controller.profiler::toolbarAction\",\n        \"token\": \"...\"\n    },\n    \"request_uri\": \"...\",\n    \"method\": \"GET\"\n}\n```\n\nWith the processor, the Symfony log looks like :\n\n```json\n{\n    \"labels\": {\n        \"route\": \"_wdt\",\n        \"route_parameters\": {\n            \"_route\": \"_wdt\",\n            \"_controller\": \"web_profiler.controller.profiler::toolbarAction\",\n            \"token\": \"...\"\n        },\n        \"request_uri\": \"...\",\n        \"method\": \"GET\"\n    }\n}\n```\n\nWarning, this processor can impact performance.\n\n#### Configuration\n\nFirst, you need to configure the processor:\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n\n    processor:\n        auto_label:\n            enabled: true\n            fields: [] # Name of internal fields, these fields will not be moved\n            #fields: !php/const Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_MINIMAL\n            #fields: !php/const Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_BUNDLE\n            #fields: !php/const Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_ALL\n```\n\nYou can define a custom list or use the built-in constant:\n\n * `Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_MINIMAL`: minimal fields supported by the bundle\n * `Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_BUNDLE`: all fields supported by the bundle\n * `Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_ALL`: all [Ecs fields](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html) and all bundle fields\n\nFor performance reasons, use only necessary fields.\n\n#### Configuration example\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    monolog:\n        handlers: ['app', 'main']\n\n    processor:\n        # [...]\n\n        auto_label:\n            enabled: true\n            fields: !php/const Aubes\\EcsLoggingBundle\\Logger\\AutoLabelProcessor::FIELDS_BUNDLE\n            handlers: ['main'] # do not apply on ecs channel\n```\n\n```yaml\n# config/packages/monolog.yaml\nmonolog:\n    handlers:\n        main:\n            type: stream\n            path: \"%kernel.logs_dir%/%kernel.environment%.log\"\n            level: warning\n            channels: [ \"!event\", \"!app\" ]\n            formatter: 'monolog.formatter.ecs'\n        app:\n            type: stream\n            path: \"%kernel.logs_dir%/%kernel.environment%.log\"\n            level: info\n            channels: [ \"app\" ]\n            formatter: 'monolog.formatter.ecs'\n```\n\n## Custom Ecs user provider\n\nThe default Ecs user provider is [Aubes\\EcsLoggingBundle\\Security\\EcsUserProvider](src/Security/EcsUserProvider.php), but you can use your own provider.\n\nFirst you need to create an Ecs User Provider class and implement [EcsUserProviderInterface](src/Security/EcsUserProviderInterface.php) :\n\n```php\n// src/Security/CustomEcsUserProvider.php\nnamespace App\\Security;\n\nuse Elastic\\Types\\User;\nuse Symfony\\Component\\Security\\Core\\Security;\n\nclass CustomEcsUserProvider implements EcsUserProviderInterface\n{\n    public function getUser(): ?User\n    {\n        // [...]\n    }\n\n    public function getDomain(): ?string\n    {\n        return 'custom_user_provider';\n    }\n}\n```\n\nNext, register your class as a service :\n\n```yaml\n# config/services.yaml\nservices:\n    App\\Security\\CustomEcsUserProvider: ~\n```\n\nThen, configure the provider :\n\n```yaml\n# config/packages/ecs-logging.yaml\necs_logging:\n    # [...]\n\n    processor:\n        user:\n            enabled: true\n            provider: 'App\\Security\\CustomEcsUserProvider'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faubes%2Fecs-logging-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faubes%2Fecs-logging-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faubes%2Fecs-logging-bundle/lists"}