Skip to content

Commit 5b1ba03

Browse files
authored
Update README.md
1 parent a8a843d commit 5b1ba03

File tree

1 file changed

+31
-218
lines changed

1 file changed

+31
-218
lines changed

README.md

Lines changed: 31 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,58 @@
1-
## Laravel 5 service provider for Understand.io
1+
## Laravel 5 service provider for Understand.io
22

33
[![Build Status](https://travis-ci.org/understand/understand-laravel5.svg)](https://travis-ci.org/understand/understand-laravel5)
44
[![Latest Stable Version](https://poser.pugx.org/understand/understand-laravel5/v/stable.svg)](https://packagist.org/packages/understand/understand-laravel5)
55
[![Total Downloads](https://poser.pugx.org/understand/understand-laravel5/downloads)](https://packagist.org/packages/understand/understand-laravel5)
66
[![Latest Unstable Version](https://poser.pugx.org/understand/understand-laravel5/v/unstable.svg)](https://packagist.org/packages/understand/understand-laravel5)
77
[![License](https://poser.pugx.org/understand/understand-laravel5/license.svg)](https://packagist.org/packages/understand/understand-laravel5)
8-
[![HHVM Status](http://hhvm.h4cc.de/badge/understand/understand-laravel5.svg)](http://hhvm.h4cc.de/package/understand/understand-laravel5)
9-
10-
> You may also be interested in our [Laravel 4](https://github.com/understand/understand-laravel), [Laravel Lumen service provider](https://github.com/understand/understand-lumen) or [Monolog Understand.io handler](https://github.com/understand/understand-monolog)
11-
128

139
### Introduction
1410

1511
This packages provides a full abstraction for Understand.io and provides extra features to improve Laravel's default logging capabilities. It is essentially a wrapper around Laravel's event handler to take full advantage of Understand.io's data aggregation and analysis capabilities.
1612

1713
### Quick start
1814

19-
1. Add package to your project.
15+
1. Add the package to your project
2016

21-
```
22-
composer require understand/understand-laravel5
23-
```
17+
```
18+
composer require understand/understand-laravel5:^2
19+
```
2420

25-
2. Add the ServiceProvider to the providers array in ```config/app.php```
21+
2. Add the ServiceProvider to the `providers` array in `config/app.php`
2622

27-
```php
28-
'Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider',
29-
```
23+
```php
24+
Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider::class,
25+
```
3026

31-
3. Set Understand.io input key in your `.env` file
27+
3. Set your Understand.io input key in your `.env` file
3228

33-
```php
34-
UNDERSTAND_TOKEN=your-input-token-from-understand-io
35-
```
36-
37-
4. Send your first event
29+
```php
30+
UNDERSTAND_ENABLED=true
31+
UNDERSTAND_TOKEN=your-input-token-from-understand-io
32+
```
3833

39-
```php
40-
// anywhere inside your Laravel app
41-
\Log::info('Understand.io test');
42-
```
43-
4434
- We recommend that you make use of a async handler - [How to send data asynchronously](#how-to-send-data-asynchronously)
4535
- If you are using Laravel 5.0 (`>= 5.0, < 5.1`) version, please read about - [How to report Laravel 5.0 exceptions](#how-to-report-laravel-50--50--51-exceptions).
4636
- For advanced configuration please read about - [Advanced configuration](#advanced-configuration)
4737

48-
38+
4939
### How to send events/logs
5040

5141
#### Laravel logs
52-
By default, Laravel automatically stores its logs in ```storage/logs```. By using this package, your logs can also be sent to your Understand.io channel. This includes error and exception logs, as well as any log events that you have defined (for example, ```Log::info('my custom log')```).
42+
By default, Laravel automatically stores its [logs](http://laravel.com/docs/errors#logging) in `storage/logs`. By using this package, your log data will also be sent to your Understand.io channel. This includes error and exception logs, as well as any log events that you have defined (for example, `Log::info('my custom log')`).
5343

5444
```php
5545
\Log::info('my message', ['my_custom_field' => 'my data']);
5646
```
57-
58-
[Laravel logging documentation](http://laravel.com/docs/errors#logging)
59-
6047
#### PHP/Laravel exceptions
61-
By default, All exceptions will be sent to Understand.io service.
62-
63-
#### Eloquent model logs
64-
Eloquent model logs are generated whenever one of the `created`, `updated`, `deleted` or `restored` Eloquent events is fired. This allows you to automatically track all changes to your models and will contain a current model diff (`$model->getDirty()`), the type of event (created, updated, etc) and additonal meta data (user_id, session_id, etc). This means that all model events will be transformed into a log event which will be sent to Understand.io.
65-
66-
By default model logs are disabled. To enable model logs, you can set the config value to `true`:
67-
68-
```php
69-
'log_types' => [
70-
'eloquent_log' => [
71-
'enabled' => true,
72-
```
73-
74-
### Additional meta data (field providers)
75-
You may wish to capture additional meta data with each event. For example, it can be very useful to capture the request url with exceptions, or perhaps you want to capture the current user's ID. To do this, you can specify custom field providers via the config.
76-
77-
```php
78-
/**
79-
* Specify additional field providers for each log
80-
* E.g. sha1 version session_id will be appended to each "Log::info('event')"
81-
*/
82-
'log_types' => [
83-
'eloquent_log' => [
84-
'enabled' => false,
85-
'meta' => [
86-
'session_id' => 'UnderstandFieldProvider::getSessionId',
87-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
88-
'user_id' => 'UnderstandFieldProvider::getUserId',
89-
'env' => 'UnderstandFieldProvider::getEnvironment',
90-
'client_ip' => 'UnderstandFieldProvider::getClientIp',
91-
]
92-
],
93-
'laravel_log' => [
94-
'enabled' => true,
95-
'meta' => [
96-
'session_id' => 'UnderstandFieldProvider::getSessionId',
97-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
98-
'user_id' => 'UnderstandFieldProvider::getUserId',
99-
'env' => 'UnderstandFieldProvider::getEnvironment',
100-
]
101-
],
102-
'exception_log' => [
103-
'enabled' => true,
104-
'meta' => [
105-
'session_id' => 'UnderstandFieldProvider::getSessionId',
106-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
107-
'user_id' => 'UnderstandFieldProvider::getUserId',
108-
'env' => 'UnderstandFieldProvider::getEnvironment',
109-
'url' => 'UnderstandFieldProvider::getUrl',
110-
'method' => 'UnderstandFieldProvider::getRequestMethod',
111-
'client_ip' => 'UnderstandFieldProvider::getClientIp',
112-
'user_agent' => 'UnderstandFieldProvider::getClientUserAgent'
113-
]
114-
]
115-
]
116-
```
117-
118-
The Understand.io service provider contains a powerful field provider class which provides default providers, and you can create or extend new providers.
119-
120-
```php
121-
dd(UnderstandFieldProvider::getSessionId());
122-
// output: c624e355b143fc050ac427a0de9b64eaffedd606
123-
```
124-
125-
#### Default field providers
126-
The following field providers are included in this package:
127-
128-
- `getSessionId` - return sha1 version of session id
129-
- `getRouteName` - return current route name (e.g. `clients.index`).
130-
- `getUrl` - return current url (e.g. `/my/path?with=querystring`).
131-
- `getRequestMethod` - return request method (e.g. `POST`).
132-
- `getServerIp` - return server IP.
133-
- `getClientIp` - return client IP.
134-
- `getClientUserAgent` - return client's user agent.
135-
- `getEnvironment` - return Laravel environment (e.g. `production`).
136-
- `getProcessIdentifier` - return unique token which is unique for every request. This allows you to easily group all events which happen in a single request.
137-
- `getUserId` - return current user id. This is only available if you make sure of the default Laravel auth or the cartalyst/sentry package. Alternatively, if you make use of a different auth package, then you can extend the `getUserId` field provider and implement your own logic.
138-
139-
#### How to extend create your own methods or extend the field providers
140-
```php
141-
142-
UnderstandFieldProvider::extend('getMyCustomValue', function()
143-
{
144-
return 'my custom value';
145-
});
146-
147-
UnderstandFieldProvider::extend('getCurrentTemperature', function()
148-
{
149-
return \My\Temperature\Provider::getRoomTemperature();
150-
});
151-
152-
```
153-
154-
#### Example
155-
Lets assume that you have defined a custom field provider called `getCurrentTemperature` (as above). You should then add this to your config file as follows:
156-
157-
```php
158-
'laravel_log' => [
159-
'meta' => [
160-
...
161-
'temperature' => 'UnderstandFieldProvider::getCurrentTemperature',
162-
...
163-
]
164-
],
165-
```
166-
167-
This additional meta data will then be automatically appended to all of your Laravel log events (`Log::info('my_custom_event')`), and will appear as follows:
168-
169-
```json
170-
171-
{
172-
"message": "my_custom_event",
173-
"custom_temperature":"23"
174-
}
175-
```
48+
By default, all errors and exceptions with code fragments and stack traces will be sent to Understand.io.
17649

50+
In addition, all SQL queries that were executed before each exception or error will also be sent to Understand.io. Note that for security and privacy reasons, we do NOT substitute query parameters. The SQL logging feature can be disabled if you wish - please see [Advanced configuration](#advanced-configuration).
17751

17852
### How to send data asynchronously
17953

18054
##### Async handler
181-
By default each log event will be sent to Understand.io's api server directly after the event happens. If you generate a large number of logs, this could slow your app down and, in these scenarios, we recommend that you make use of a async handler. To do this, set the config parameter `UNDERSTAND_HANDLER` to `async` in your `.env` file.
55+
By default each log event will be sent to Understand.io's api server directly after the event happens. If you generate a large number of logs, this could slow your app down and, in these scenarios, we recommend that you make use of an async handler. To do this, set the config parameter `UNDERSTAND_HANDLER` to `async` in your `.env` file.
18256

18357
```php
18458
# Specify which handler to use - sync, queue or async.
@@ -188,7 +62,7 @@ By default each log event will be sent to Understand.io's api server directly af
18862
UNDERSTAND_HANDLER=async
18963
```
19064

191-
The async handler is supported in most of the systems - the only requirement is that CURL command line tool is installed and functioning correctly. To check whether CURL is available on your system, execute following command in your console:
65+
The async handler is supported in most systems - the only requirement is that the CURL command line tool is installed and functioning correctly. To check whether CURL is available on your system, execute following command in your console:
19266

19367
```
19468
curl -h
@@ -198,14 +72,11 @@ If you see instructions on how to use CURL then your system has the CURL binary
19872

19973
> Keep in mind that Laravel allows you to specify different configuration values in different environments. You could, for example, use the async handler in production and the sync handler in development.
20074
201-
##### Laravel queue handler
202-
Although we generally recommend using the async handler, making use of queues is another another option. Bear in mind that by the default Laravel queue is `sync`, so you will still need to configure your queues properly using something like iron.io or Amazon SQS. See http://laravel.com/docs/queues for more information.
203-
20475
### How to report Laravel 5.0 (`>= 5.0, < 5.1`) exceptions
20576

20677
Laravel's (`>= 5.0, < 5.1`) exception logger doesn't use event dispatcher (https://github.com/laravel/framework/pull/10922) and that's why you need to add the following line to your `Handler.php` file (otherwise Laravel's exceptions will not be sent Understand.io).
20778

208-
- Open ```app/Exceptions/Handler.php``` and put this line ```\UnderstandExceptionLogger::log($e)``` inside ```report``` method.
79+
- Open `app/Exceptions/Handler.php` and put this line `\UnderstandExceptionLogger::log($e)` inside `report``method.
20980

21081
```php
21182
public function report(Exception $e)
@@ -216,81 +87,24 @@ Laravel's (`>= 5.0, < 5.1`) exception logger doesn't use event dispatcher (https
21687
}
21788
```
21889

219-
220-
90+
22191
### Advanced Configuration
22292

223-
22493
1. Publish configuration file
22594

226-
```
227-
php artisan vendor:publish --provider="Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider"
228-
```
229-
230-
2. And you can now make adjustments in your ```config/understand-laravel.php``` file
95+
```
96+
php artisan vendor:publish --provider="Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider"
97+
```
23198

99+
### Upgrading To Version 2 of the Service Provider
100+
101+
1. Add the following configuration variable to your `.env` file.
232102
```php
233-
return [
234-
/**
235-
* Input key
236-
*/
237-
'token' => env('UNDERSTAND_TOKEN'),
238-
239-
/**
240-
* Specifies whether logger should throw an exception of issues detected
241-
*/
242-
'silent' => true,
243-
244-
/**
245-
* Specify which handler to use - sync, queue or async.
246-
*
247-
* Note that the async handler will only work in systems where
248-
* the CURL command line tool is installed
249-
*/
250-
'handler' => env('UNDERSTAND_HANDLER', 'sync'),
251-
252-
'log_types' => [
253-
'eloquent_log' => [
254-
'enabled' => false,
255-
'meta' => [
256-
'session_id' => 'UnderstandFieldProvider::getSessionId',
257-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
258-
'user_id' => 'UnderstandFieldProvider::getUserId',
259-
'env' => 'UnderstandFieldProvider::getEnvironment',
260-
'url' => 'UnderstandFieldProvider::getUrl',
261-
'method' => 'UnderstandFieldProvider::getRequestMethod',
262-
'client_ip' => 'UnderstandFieldProvider::getClientIp',
263-
]
264-
],
265-
'laravel_log' => [
266-
'enabled' => true,
267-
'meta' => [
268-
'session_id' => 'UnderstandFieldProvider::getSessionId',
269-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
270-
'user_id' => 'UnderstandFieldProvider::getUserId',
271-
'env' => 'UnderstandFieldProvider::getEnvironment',
272-
'url' => 'UnderstandFieldProvider::getUrl',
273-
'method' => 'UnderstandFieldProvider::getRequestMethod',
274-
'client_ip' => 'UnderstandFieldProvider::getClientIp',
275-
]
276-
],
277-
'exception_log' => [
278-
'enabled' => true,
279-
'meta' => [
280-
'session_id' => 'UnderstandFieldProvider::getSessionId',
281-
'request_id' => 'UnderstandFieldProvider::getProcessIdentifier',
282-
'user_id' => 'UnderstandFieldProvider::getUserId',
283-
'env' => 'UnderstandFieldProvider::getEnvironment',
284-
'url' => 'UnderstandFieldProvider::getUrl',
285-
'method' => 'UnderstandFieldProvider::getRequestMethod',
286-
'client_ip' => 'UnderstandFieldProvider::getClientIp',
287-
'user_agent' => 'UnderstandFieldProvider::getClientUserAgent'
288-
]
289-
]
290-
]
291-
];
103+
UNDERSTAND_ENABLED=true
292104
```
293105

106+
2. If you previously created a `understand-laravel.php` config file in your `config` directory, please delete it and follow [Advanced configuration](#advanced-configuration) steps to publish a new version if necessary.
107+
294108
### Requirements
295109
##### UTF-8
296110
This package uses the json_encode function, which only supports UTF-8 data, and you should therefore ensure that all of your data is correctly encoded. In the event that your log data contains non UTF-8 strings, then the json_encode function will not be able to serialize the data.
@@ -300,4 +114,3 @@ http://php.net/manual/en/function.json-encode.php
300114
### License
301115

302116
The Laravel Understand.io service provider is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
303-

0 commit comments

Comments
 (0)