PHPackages                             twentysix22/laraveleslogs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. twentysix22/laraveleslogs

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

twentysix22/laraveleslogs
=========================

Elasticsearch structured logging for Laravel

2.0.5(4y ago)32.4k1MITPHP

Since Aug 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/twentysix22/laraveleslogs)[ Packagist](https://packagist.org/packages/twentysix22/laraveleslogs)[ Docs](https://github.com/twentysix22/laraveleslogs)[ RSS](/packages/twentysix22-laraveleslogs/feed)WikiDiscussions master Synced yesterday

READMEChangelog (3)Dependencies (8)Versions (14)Used By (0)

LaravelESLogs
=============

[](#laraveleslogs)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b6cb614f138aaf378456d41c05a383312551b2609e2cbee35ff3f4ca40d56140/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7477656e747973697832322f6c61726176656c65736c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/twentysix22/laraveleslogs)[![Total Downloads](https://camo.githubusercontent.com/576cb79957b5f2da9f716c40b4c56e1d04f8ae38038b3d86337f5216eddf4bdc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7477656e747973697832322f6c61726176656c65736c6f67732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/twentysix22/laraveleslogs)

Structured logging for Laravel into Elasticsearch. Log your Requests and Jobs easily alongside key contextual information to elastic search indexes for easy searching and analysis.

Take a look at [contributing.md](contributing.md) to see a to do list.

Installation
------------

[](#installation)

Via Composer

```
$ composer require twentysix22/laraveleslogs
```

Usage
-----

[](#usage)

Publish the provider in laravel:

```
php artisan vendor:publish --provider="Twentysix22\LaravelESLogs\LaravelESLogsServiceProvider"
```

Add the route middleware alias to the app/Http/Kernel.php

```
protected $routeMiddleware = [
...,
...,

'log' => \Twentysix22\LaravelESLogs\Services\Logging\Requests\LogRequest::class,
```

Configure .env

```
LOG_GROUP=some-group
LOG_ELASTICSEARCH_HOST=localhost:9200
LOG_ELASTICSEARCH_KEEP_DAYS=5
LOG_JOBS=true
LOG_JOB_ATTEMPTS=true
LOG_REQUESTS=true
LOG_REDACTION_INK=REDACTED
LOG_ELASTICSEARCH_AUTH_TYPE=url   [url or apikey]
LOG_ELASTICSEARCH_AUTH_API_ID=
LOG_ELASTICSEARCH_AUTH_API_KEY=
LOG_REQUEST_MAX_SIZE= (size in characters)
LOG_RESPONSE_MAX_SIZE= (size in characters)
LOG_ELASTICSEARCH_INDEX_DATE_PATTERN="Y.m.d"
```

Add the service provider to your providers array in config/app.php

```
\Twentysix22\LaravelESLogs\LaravelESLogsServiceProvider::class,
```

Initialise the Elasticsearch indices.
-------------------------------------

[](#initialise-the-elasticsearch-indices)

This step is not strictly necessary unless you wish to reset any current indices.

```
php artisan laraveleslogs:configure
```

Configure auto cleanup of logs by retention days.
-------------------------------------------------

[](#configure-auto-cleanup-of-logs-by-retention-days)

You can run a daily command to clear up old logs which will use the `LOG_ELASTICSEARCH_KEEP_DAYS` env variable number of days retention.

```
php artisan laraveleslogs:tidy
```

Logging Requests
----------------

[](#logging-requests)

Apply the middleware 'log:{namespace}' to your routes to start logging requests. (you can omit the namespace param if you want to but its useful to specify for clarity in logs) eg:

```
Route::get('/', function () {
    return view('welcome');
})->middleware('log:home');
```

You can add this middleware to individual routes, groups, or even your global route middlware if you wish to simply log out every request/response. (but we recommend you be more specific in your logging :-) )

Adding Request Context
----------------------

[](#adding-request-context)

You can use the Trait `use ReportsRequestContext;` in your request controllers. This gives a coupld of options to apply context to your logs.

```
