Skip to content

Commit b5c76c4

Browse files
authored
Merge pull request #3 from erashdan/master
make extra config is not mandatory
2 parents 3f8309a + fa01b55 commit b5c76c4

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

README.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ composer require tarfin-labs/laravel-cloudwatch-logger
1414

1515
Config parameters for logging are defined at `config/logging.php`.
1616

17-
You need to add new channel as `cloudwatch` and copy params inside `config/config.php` into it.
17+
You need to add new channel as `cloudwatch` and copy params inside `config/config.php` into it.
1818

19-
``` php
19+
```php
2020
'channels' => [
2121
...
2222

@@ -36,7 +36,7 @@ You need to add new channel as `cloudwatch` and copy params inside `config/confi
3636
'stream' => env('CLOUDWATCH_LOG_STREAM', 'default'),
3737
'retention' => env('CLOUDWATCH_LOG_RETENTION', 7),
3838
'level' => env('CLOUDWATCH_LOG_LEVEL', 'error'),
39-
'extra' => [
39+
'extra' => [ // In case there's extra information to be logged
4040
'env' => env('APP_ENV'),
4141
'php' => PHP_VERSION,
4242
'laravel' => app()->version(),
@@ -46,22 +46,24 @@ You need to add new channel as `cloudwatch` and copy params inside `config/confi
4646
```
4747

4848
Change the log channel inside `.env` file with `cloudwatch`.
49+
4950
```dotenv
5051
LOG_CHANNEL=cloudwatch
5152
```
5253

5354
You can use Laravel's default `Log` class to send your logs to CloudWatch.
54-
````php
55+
56+
```php
5557
\Illuminate\Support\Facades\Log::info('user logged in successfully', [
56-
'id' => 1,
57-
'username' => 'JohnDoe',
58+
'id' => 1,
59+
'username' => 'JohnDoe',
5860
'ip' => '127.0.0.1',
5961
]);
60-
````
62+
```
6163

6264
### Testing
6365

64-
``` bash
66+
```bash
6567
composer test
6668
```
6769

@@ -79,11 +81,11 @@ If you discover any security related issues, please email development@tarfin.com
7981

8082
## Credits
8183

82-
- [Turan Karatuğ](https://github.com/tkaratug)
83-
- [Faruk Can](https://github.com/frkcn)
84-
- [Yunus Emre Deligöz](https://github.com/deligoez)
85-
- [Hakan Özdemir](https://github.com/hozdemir)
86-
- [All Contributors](../../contributors)
84+
- [Turan Karatuğ](https://github.com/tkaratug)
85+
- [Faruk Can](https://github.com/frkcn)
86+
- [Yunus Emre Deligöz](https://github.com/deligoez)
87+
- [Hakan Özdemir](https://github.com/hozdemir)
88+
- [All Contributors](../../contributors)
8789

8890
## License
8991

src/LaravelCloudWatchLoggerFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ public function __invoke(array $config)
3939

4040
$logger->pushHandler($handler);
4141

42-
$logger->pushProcessor(function ($record) use ($config) {
43-
$record['extra'] = $config['extra'];
44-
return $record;
45-
});
42+
if (isset($record['extra'])) {
43+
$logger->pushProcessor(function ($record) use ($config) {
44+
$record['extra'] = $config['extra'];
45+
return $record;
46+
});
47+
}
4648

4749
return $logger;
4850
}

0 commit comments

Comments
 (0)