nix-logger / nix-logger-laravel
Nix Logger
Installs: 4 563
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- illuminate/contracts: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- monolog/monolog: ^2 || ^3
- nix-logger/nix-logger: ^1.3
Requires (Dev)
- laravel/pint: ^1.13
README
Installation
Install the nix-logger/nix-logger-laravel
package:
composer require nix-logger/nix-logger-laravel
Add the service provider
Add provider NixLogger\Laravel\NixLoggerServiceProvider::class
Check Version
php artisan --version
# Laravel Framework xx.xx.xx
- For Laravel < 11, update `config/app.php
// config/app.php 'providers' => [ Illuminate\Auth\AuthServiceProvider::class, NixLogger\Laravel\NixLoggerServiceProvider::class, ]
- For Laravel >= 11, update
bootstrap/providers.php
// bootstrap/providers.php return [ Illuminate\Auth\AuthServiceProvider::class, NixLogger\Laravel\NixLoggerServiceProvider::class, ];
Add the Facade
- For Laravel < 11, update
config/app.php
// config/app.php 'aliases' => [ 'NixLogger' => NixLogger\Laravel\Facades\NixLogger::class, ]
- For Laravel >= 11, update
bootstrap/app.php
// bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'NixLogger' => NixLogger\Laravel\Facades\NixLogger::class, ]); })
Configuration
Configure your Nix-Logger by edit the .env
file
# .env NIX_LOGGER_API_KEY="" NIX_LOGGER_LEVEL=critical,error,warning LOG_CHANNEL="stack" LOG_STACK="daily,nix-logger" # APP_ENV=
If you’d like to configure Nix-Logger further, create and edit a config/nix-logger.php
file
Setting Log report
In config/logging.php
, add the nix-logger
logging channel by adding the following under the channels
key:
'stack' => [ 'driver' => 'stack', 'channels' => ['single', 'nix-logger'], 'ignore_exceptions' => false, ], 'nix-logger' => [ 'driver' => 'custom', 'via' => \NixLogger\Laravel\Logger\NixLogger::class, ],
For stderr
'channels' => [ 'stderr' => [ 'driver' => 'monolog', 'level' => env('LOG_LEVEL', 'debug'), 'handler' => \NixLogger\Laravel\Handlers\NixLoggerStreamHandler::class, 'formatter' => env('LOG_STDERR_FORMATTER'), 'with' => [ 'stream' => 'php://stderr', ], 'processors' => [PsrLogMessageProcessor::class], ], ]
Usage
Use NixLogger Debug
php artisan tinker
\NixLogger::error('Test Error');
Text with example exception
Route::get('/error', function () { throw new Exception('This is a test exception'); return [ 'message' => 'This is a test response', ]; });
Open browser and navigate to http://localhost:8000/error