Skip to content

A middleware that logs HTTP requests into a table before sending response

License

Notifications You must be signed in to change notification settings

landrok/laravel-request-logger

Repository files navigation

Laravel Request Logger

Build Status Test Coverage Code Climate

Laravel Request Logger provides a middleware that logs HTTP requests into a table.

It can be reconfigured to target specific requests or to log only specified informations.

What is logged ?

For each request, the following informations are stored.

User

  • session_id
  • user_id
  • ip
  • route
  • route_params: optional

Performances

  • duration
  • mem_alloc

HTTP stuff

  • method
  • status_code
  • url: this one has 2 ways of configuration: set it to full to log full URL with query or set it to true to log only URL
  • referer
  • referer_host
  • request_headers: optional
  • response_headers: optional

Device

The following values are provided by the jenssegers/agent package.

  • device
  • os
  • os_version
  • browser
  • browser_version
  • is_desktop
  • is_mobile
  • is_tablet
  • is_phone
  • is_robot
  • robot_name
  • user_agent

Miscellaneous

  • meta : this field is for custom logging. See RequestLogger::meta($value)
  • created_at

Table of contents


Requirements

Laravel Request Logger supports Laravel 6, 7, 8.


Installation

composer require landrok/laravel-request-logger

Create the request_logs table with

php artisan migrate

Configuration

You may log every calls (default), only routes that match some patterns and only specified criterias.

You have to publish configuration file before.

php artisan vendor:publish --provider="Landrok\Laravel\RequestLogger\RequestLoggerServiceProvider"

The config file can be found at config/requestlogger.php.


Meta::set(string $key, $value)

This tool is made to log anything from anywhere in your code (Controller, View, Service, etc...) into the meta column.

use Landrok\Laravel\RequestLogger\Meta;

Meta::set($key, $value);

$value can be a string or an array or a serializable. It will be stored as a JSON string.

Before using this method, you have to authorize this field in the config file.


Contributing

Feel free to open issues and make PR. Contributions are welcome.


License

Laravel Request License is licensed under The MIT License (MIT).

About

A middleware that logs HTTP requests into a table before sending response

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages