Skip to content

Commit 1318ef0

Browse files
committed
update readme
1 parent 67ba96f commit 1318ef0

File tree

1 file changed

+45
-217
lines changed

1 file changed

+45
-217
lines changed

README.md

Lines changed: 45 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,68 @@
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)
118

9+
- [Quick start](#quick-start)
10+
- [Upgrading To Version 2](#upgrading-to-version-2-of-the-service-provider)
1211

1312
### Introduction
1413

1514
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.
1615

1716
### Quick start
1817

19-
1. Add package to your project.
20-
21-
```
22-
composer require understand/understand-laravel5
23-
```
24-
25-
2. Add the ServiceProvider to the providers array in ```config/app.php```
26-
27-
```php
28-
'Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider',
29-
```
30-
31-
3. Set Understand.io input key in your `.env` file
32-
33-
```php
34-
UNDERSTAND_TOKEN=your-input-token-from-understand-io
35-
```
36-
37-
4. Send your first event
38-
39-
```php
40-
// anywhere inside your Laravel app
41-
\Log::info('Understand.io test');
42-
```
18+
1. Add the package to your project
4319

44-
- We recommend that you make use of a async handler - [How to send data asynchronously](#how-to-send-data-asynchronously)
45-
- 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).
46-
- For advanced configuration please read about - [Advanced configuration](#advanced-configuration)
47-
48-
49-
### How to send events/logs
50-
51-
#### 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')```).
53-
54-
```php
55-
\Log::info('my message', ['my_custom_field' => 'my data']);
5620
```
57-
58-
[Laravel logging documentation](http://laravel.com/docs/errors#logging)
59-
60-
#### 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,
21+
composer require understand/understand-laravel5:^2
7222
```
7323

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-
24+
2. Add the ServiceProvider to the `providers` array in `config/app.php`
25+
7726
```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-
]
27+
Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider::class,
11628
```
11729

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-
30+
3. Set your Understand.io input token in your `.env` file
31+
12032
```php
121-
dd(UnderstandFieldProvider::getSessionId());
122-
// output: c624e355b143fc050ac427a0de9b64eaffedd606
33+
UNDERSTAND_ENABLED=true
34+
UNDERSTAND_TOKEN=your-input-token-from-understand-io
12335
```
12436

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-
});
37+
4. Send your first error
15138

39+
```php
40+
// anywhere inside your Laravel app
41+
\Log::error('Understand.io test error');
15242
```
15343

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:
44+
- We recommend that you make use of a async handler - [How to send data asynchronously](#how-to-send-data-asynchronously)
45+
- 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).
46+
- For advanced configuration please read about - [Advanced configuration](#advanced-configuration)
15647

157-
```php
158-
'laravel_log' => [
159-
'meta' => [
160-
...
161-
'temperature' => 'UnderstandFieldProvider::getCurrentTemperature',
162-
...
163-
]
164-
],
165-
```
16648

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:
49+
### How to send events/logs
16850

169-
```json
51+
#### Laravel logs
52+
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')`).
17053

171-
{
172-
"message": "my_custom_event",
173-
"custom_temperature":"23"
174-
}
54+
```php
55+
\Log::info('my message', ['my_custom_field' => 'my data']);
17556
```
57+
#### PHP/Laravel exceptions
58+
By default, all errors and exceptions with code fragments and stack traces will be sent to Understand.io.
17659

60+
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).
17761

17862
### How to send data asynchronously
17963

18064
##### 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.
65+
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.
18266

18367
```php
18468
# Specify which handler to use - sync, queue or async.
@@ -188,7 +72,7 @@ By default each log event will be sent to Understand.io's api server directly af
18872
UNDERSTAND_HANDLER=async
18973
```
19074

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:
75+
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:
19276

19377
```
19478
curl -h
@@ -198,14 +82,11 @@ If you see instructions on how to use CURL then your system has the CURL binary
19882

19983
> 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.
20084
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-
20485
### How to report Laravel 5.0 (`>= 5.0, < 5.1`) exceptions
20586

20687
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).
20788

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

21091
```php
21192
public function report(Exception $e)
@@ -216,81 +97,29 @@ Laravel's (`>= 5.0, < 5.1`) exception logger doesn't use event dispatcher (https
21697
}
21798
```
21899

219-
220-
100+
221101
### Advanced Configuration
222102

223-
224103
1. Publish configuration file
225104

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
105+
```
106+
php artisan vendor:publish --provider="Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider"
107+
```
231108

109+
### Upgrading To Version 2 of the Service Provider
110+
111+
1. Update your `package.json` file, change the version of `understand/understand-laravel5` package and run `composer update understand/understand-laravel5`.
112+
```json
113+
"understand/understand-laravel5": "^2.0",
114+
```
115+
116+
2. Add the following configuration variable to your `.env` file.
232117
```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-
];
118+
UNDERSTAND_ENABLED=true
292119
```
293120

121+
3. 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.
122+
294123
### Requirements
295124
##### UTF-8
296125
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 +129,3 @@ http://php.net/manual/en/function.json-encode.php
300129
### License
301130

302131
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)