-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit be0ead1
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/.idea | ||
/vendor | ||
/node_modules | ||
package-lock.json | ||
composer.phar | ||
composer.lock | ||
phpunit.xml | ||
.phpunit.result.cache | ||
.DS_Store | ||
Thumbs.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Laravel Custom Logging | ||
|
||
This package provides us with an additional `origin` variable for logs to determine the source of the log. | ||
|
||
## Installation | ||
|
||
You can install the package via composer: | ||
|
||
```bash | ||
composer require coreproc/laravel-custom-logging | ||
``` | ||
|
||
Publish the config file: | ||
|
||
```bash | ||
php artisan vendor:publish --provider="Coreproc\LaravelCustomLogging\CustomLoggingServiceProvider" | ||
``` | ||
|
||
## Usage | ||
|
||
Typically, we use this in the `stderr` channel. Here is an example of the configuration: | ||
|
||
```php | ||
'channels' => [ | ||
'stderr' => [ | ||
'driver' => 'monolog', | ||
'level' => env('LOG_LEVEL', 'debug'), | ||
'handler' => StreamHandler::class, | ||
'formatter' => Monolog\Formatter\JsonFormatter::class, | ||
'formatter_with' => [ | ||
'includeStacktraces' => true, | ||
'batchMode' => Monolog\Formatter\JsonFormatter::BATCH_MODE_JSON, | ||
'appendNewline' => true, | ||
], | ||
'with' => [ | ||
'stream' => 'php://stderr', | ||
], | ||
'processors' => [\Coreproc\LaravelCustomLogging\AddOriginProcessor::class], | ||
], | ||
], | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "coreproc/laravel-custom-logging", | ||
"description": "Custom logging for AWS cloudwatch containers", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Coreproc\\LaravelCustomLogging\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Coreproc\\LaravelCustomLogging\\CustomLoggingServiceProvider" | ||
] | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Chris Bautista", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'container_role' => env('CONTAINER_ROLE', 'web'), | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Coreproc\LaravelCustomLogging; | ||
|
||
use Monolog\LogRecord; | ||
use Monolog\Processor\ProcessorInterface; | ||
|
||
class AddOriginProcessor implements ProcessorInterface | ||
{ | ||
public function __invoke(LogRecord $record): array|LogRecord | ||
{ | ||
return new \Coreproc\LaravelCustomLogging\LogRecord( | ||
$record->datetime, | ||
$record->channel, | ||
$record->level, | ||
$record->message, | ||
$record->context, | ||
$record->extra | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Coreproc\LaravelCustomLogging; | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class CustomLoggingServiceProvider extends ServiceProvider | ||
{ | ||
public function boot(): void | ||
{ | ||
// Publish config file | ||
$this->publishes([ | ||
__DIR__ . '/../config/custom-logging.php' => config_path('custom-logging.php'), | ||
], 'custom-logging-config'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Coreproc\LaravelCustomLogging; | ||
|
||
class LogRecord extends \Monolog\LogRecord | ||
{ | ||
public function toArray(): array | ||
{ | ||
$array = parent::toArray(); | ||
return array_merge(['origin' => 'app.' . config('custom-logging.container_role')], $array); | ||
} | ||
} |