Download the PHP package michael4d45/context-logging without Composer

On this page you can find all versions of the php package michael4d45/context-logging. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package context-logging

Contextual Logging for Laravel

Latest Version on Packagist Tests Total Downloads

This package provides a structured, context-first logging model for Laravel applications.

Instead of emitting many unstructured log lines during execution, the system accumulates contextual information throughout a request's lifecycle and emits a single structured log event at completion. The resulting log data is high-signal, query-friendly, and compatible with modern observability workflows.

Inspired by "Logging sucks" - a comprehensive exploration of wide events and modern observability practices.

Installation

You can install the package via composer:

Laravel Middleware Registration

This package requires two global HTTP middleware to function correctly:

Laravel 12+ registers middleware via bootstrap/app.php.

Registering Global Middleware

Open bootstrap/app.php and locate the withMiddleware section.

Append the package middleware to the global stack:

Both middleware are appended to run after Laravel's core request processing.

Ordering Considerations

Middleware execution order matters.

Recommended placement:

Using append() achieves this safely.

If you need the request context earlier, you may use prepend() instead:

Manually Managing the Global Middleware Stack (Optional)

If your application explicitly defines Laravel's global middleware stack using use(), include the package middleware in that list.

Example:

When using use(), Laravel does not automatically include defaults—you are responsible for the full stack. Both middleware should be included in the array.

Notes

Summary

To enable contextual logging in Laravel:

  1. Install the package via Composer
  2. Register the two global middleware in bootstrap/app.php
  3. Continue using Log::info(), Log::error(), etc. as usual

Once enabled, the package will emit one structured log event per request using Laravel's existing logging configuration.

How It Works

Traditional Logging

Contextual Logging

Log calls become annotations that are collected into comprehensive wide events.

Bootstrap and early log calls

Pre-lifecycle behavior is split by how PHP is running:

Once a lifecycle has started, annotations accumulate only until that request/job/command completes. Long-lived lifecycles clear the store after emit so completed runs and jobs do not leak into the next one.

Interrupted requests and console runs

If PHP exits before Laravel reaches its normal termination phase, the package now falls back to a shutdown handler. That means a request or console lifecycle can still emit its accumulated wide event when execution is interrupted by things like dd(), exit, or a fatal error.

Fatal shutdowns add a PHP fatal error event automatically. Non-fatal interruptions still emit a synthetic interruption event when nothing else was logged, so abrupt exits are visible instead of disappearing.

Tinker behavior

artisan tinker is treated differently from normal console commands. Instead of buffering one giant context until you leave the shell, each evaluated statement gets its own lifecycle and emits immediately after execution. That keeps Tinker logging usable without waiting for shell exit.

Philosophy: Wide Events Only

This package embraces Wide Events exclusively - no more scattered logs! Instead of emitting individual log entries throughout request processing, all logging calls are accumulated and emitted as a single comprehensive event at request completion.

Why Wide Events?

The transformation:

Your logs stop lying to you. They start telling the whole truth.

Usage

The package preserves the existing Laravel logging interface. No changes to your application code are required!

Instead of emitting 3 separate log entries, this produces a single wide event:

Architecture

Core Components

Request Lifecycle

  1. Request enters application
  2. Request context middleware populates base metadata (request ID, method, path, etc.)
  3. Application code calls Log::*() as usual - these become context annotations
  4. Request completes
  5. Terminating middleware emits one structured log entry via Laravel's logger
  6. Laravel handles delivery via its configured logging stack

Configuration

The package works out of the box with no configuration required. It provides wide events exclusively - no individual log pass-through.

You can optionally publish the configuration file for future customization:

This creates config/context-logging.php for future options like sampling rates, field filtering, and custom context enrichment.

Outgoing HTTP Sub-Context Hooks

You can attach outbound HTTP request/response data as a sub-context layer without wrapping every Http:: call.

The package provides:

Global Setup

Outbound HTTP instrumentation is auto-registered when the package boots while http.enabled=true.

You can still register manually in App\Providers\AppServiceProvider::boot() if you want explicit control:

Once registered, all outbound Http::get/post/... calls are captured automatically.

You can control payload collection in config/context-logging.php:

Set capture_body to true when you need request/response body capture. When body capture is enabled, configured redact_body_fields are masked recursively for JSON payloads. Captured requests also include path and query_params, and configured redact_query_params are masked.

Optional Manual Control

ContextStore provides three methods:

You can still use these for fine-grained control around specific calls:

When outbound HTTP calls are tracked, they appear as interleaved events in the events array, sorted by timestamp alongside other log events.

Hooks are registered through HttpContextHooks::beforeRequest() and HttpContextHooks::afterResponse(). If a hook throws an exception, processing continues and hook error details are attached to the tracked HTTP call.

Compatibility

The package emits exactly one log entry using Laravel's standard Log::info() method, ensuring full compatibility with:

Performance

Operational Characteristics

Error Handling

Exceptions and errors enrich the existing request context rather than being emitted separately. This guarantees correlation without relying on log aggregation heuristics.

Future Extensions

The design supports future extensions without API breakage:

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of context-logging with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
composer-plugin-api Version ^2.2
guzzlehttp/guzzle Version ^7.8|^8.0
illuminate/support Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
psr/http-message Version ^1.1|^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package michael4d45/context-logging contains the following files

Loading the files please wait ...