Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Log Bundle Laravel Package

etsglobal/log-bundle

ETSGlobal LogBundle adds normalized logging and request tracing to Symfony apps: automatic logger injection, token collection and context enrichment, custom exception levels, a Slack handler, and Guzzle/Symfony HttpClient token forwarding.

View on GitHub
Deep Wiki
Context7

LogBundle

Provides normalized logging and tracing features for all ETSGlobal Symfony applications.

Build Status

Overview

Main features:

  • Automatic logger injection.
  • Provide TokenCollection utility to enable downstream applications for request tracing from app to app.
  • Automatically configure global and process token tracing for incoming HTTP requests/responses as well as long-running processes.
  • Automatically enrich log context with the application name and tracing tokens.
  • Processor to change the log level of exceptions, like Symfony's NotFoundHttpException
  • Slack handler: An extended version of Monolog's slack handler, with custom message contents, and custom filters.
  • Provides a Guzzle middleware to forward tokens through HTTP calls.
  • Provides a Symfony HttpClient decorator to forward tokens through HTTP calls.

Installation

  1. Install the bundle
composer require etsglobal/log-bundle
  1. Load the bundle
// config/Bundles.php
return [
    ...
    ETSGlobal\LogBundle\ETSGlobalLogBundle::class => ['all' => true],
    ...
];

For Symfony < 4

// app/AppKernel.php
$bundles = [
    ...
    new ETSGlobal\LogBundle\ETSGlobalLogBundle(),
    ...
];

Configuration

Bundle configuration

# config/packages/ets_global_log.yaml
ets_global_log:
    app_name: my-app # Used to filter logs by application.
    slack_handler:
        token: "slack API token"
        channel: "#channel-name"
        jira_url: "example.jira.com"
        kibana_url: "kibana.example.com/app/kibana"
    custom_exceptions_levels:
        My\Custom\Exception: !php/const Monolog\Logger::INFO

Monolog configuration

If you want to use the slack handler provided by this bundle, add the following configuration:

# config/packages/<env>/monolog.yaml
monolog:
    handlers:
        ...
        slack_failure:
            type: 'whatfailuregroup'
            members: ['slack']
        slack:
            type: 'service'
            id:  'ets_global_log.monolog.handler.slack'
            level: "error"

If you have a file handler, you might want to use the token_collection formatter to add the tracing tokens:

# config/packages/<env>/monolog.yaml
monolog:
    handlers:
        ...
        file:
            type: "rotating_file"
            path: "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
            formatter: 'ets_global_log.monolog.formatter.token_collection'

Automatic logger injection

Automatic logger injection will try to inject the logger in all services tagged with the ets_global_log.logger_aware tag. The services hate to implement Psr\Log\LoggerAwareInterface to receive the logger by setter injection.

// src/MyService.php
namespace App;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

class MyService implements LoggerAwareInterface
{
    use LoggerAwareTrait;
}
# config/services.yaml
App\MyService:
    tags:
    - { name: "ets_global_log.logger_aware" }

Symfony HttpClient decorator

Install symfony/http-client:

composer require symfony/http-client

Configure your scoped client:

framework:
    http_client:
        scoped_clients:
            my.client:
                base_uri: 'example.com/api/'

Just inject the my.client HttpClient in your services like normally. The HttpClientDecorator will decorate the HttpClient to automatically inject the token_global in the request.

Guzzle middleware

Install csa/guzzle-bundle:

composer require csa/guzzle-bundle

Configure HTTP clients with the "token_global" middleware:

# config/packages/cas_guzzle.yaml
csa_guzzle:
     profiler: '%kernel.debug%'
     logger: true
     clients:
         foo:
             config:
                 base_uri: "http://example.com/api"
             middleware: ['token_global']
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
pharaonic/laravel-notification-dependencies
beautinow/translug
dev-brainiac/bot-cloaked
octoberrain/html
octoberrain/extension
octoberrain/exception
octoberrain/contracts
frankyso/ipaymu
3mdikram/worldmoneywords
snowsoft/config
itmosoft/laravel-subscriptions
larva/laravel-ai-qwen
adachsoft/api-version-bundle
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core