1. Go to this page and download the library: Download themehybrid/hybrid-log library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Monolog\Handler\NullHandler;
use function Hybrid\storage_path;
use function Hybrid\Tools\env;
return [
/*
|--------------------------------------------------------------------------
| Default Log Channel
|--------------------------------------------------------------------------
|
| This option defines the default log channel that gets used when writing
| messages to the logs. The name specified in this option should match
| one of the channels defined in the "channels" configuration array.
|
*/
'default' => env( 'LOG_CHANNEL', 'stack' ),
/*
|--------------------------------------------------------------------------
| Deprecations Log Channel
|--------------------------------------------------------------------------
|
| This option controls the log channel that should be used to log warnings
| regarding deprecated PHP and library features. This allows you to get
| your application ready for upcoming major versions of dependencies.
|
*/
'deprecations' => [
'channel' => env( 'LOG_DEPRECATIONS_CHANNEL', 'null' ),
'trace' => false,
],
/*
|--------------------------------------------------------------------------
| Log Channels
|--------------------------------------------------------------------------
|
| Here you may configure the log channels for your application. Out of
| the box, hybrid uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Drivers: "single", "daily", "slack", "syslog",
| "errorlog", "monolog",
| "custom", "stack"
|
*/
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => explode( ',', (string) env( 'LOG_STACK', 'single,daily' ) ),
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path( 'logs/hybrid-core.log' ),
'level' => env( 'LOG_LEVEL', 'debug' ),
],
'daily' => [
'driver' => 'daily',
'path' => storage_path( 'logs/hybrid-core.log' ),
'level' => env( 'LOG_LEVEL', 'debug' ),
'days' => 14,
],
'null' => [
'driver' => 'monolog',
'handler' => NullHandler::class,
],
// Used when no other channel can be resolved. Keep it simple.
'emergency' => [
'path' => storage_path( 'logs/hybrid-core.log' ),
],
'sentry' => [
'driver' => 'sentry',
'level' => Logger::ERROR, // The minimum monolog logging level at which this handler will be triggered
'bubble' => true, // Whether the messages that are handled can bubble up the stack or not
],
],
];
Log::channel( 'daily' )->info( 'Something happened.' );
// Write to several channels in one call.
Log::stack( [ 'single', 'daily' ] )->info( 'Something happened.' );
// Build a channel on the fly, without adding it to config.
Log::build( [
'driver' => 'single',
'path' => storage_path( 'logs/audit.log' ),
] )->info( 'Something happened.' );
Context::addIf( 'key', 'value' ); // Only writes when the key is absent.
Context::push( 'breadcrumbs', 'step' ); // Appends to an array.
Context::pop( 'breadcrumbs' );
Context::increment( 'queries' );
Context::only( [ 'user_id' ] );
Context::except( [ 'user_id' ] );
Context::flush();
$result = Context::scope( function () {
Log::info( 'Inside the scope.' ); // Includes job_id.
return $this->handle();
}, [ 'job_id' => $id ] );
use function Hybrid\Log\logger;
use function Hybrid\Log\logs;
use function Hybrid\Log\context;
use function Hybrid\Log\info;
logger( 'A debug message.', [ 'key' => 'value' ] );
logger()->error( 'Something broke.' ); // No arguments returns the logger.
logs(); // The LogManager.
logs( 'daily' ); // A specific channel.
context( 'user_id' ); // Read.
context( [ 'user_id' => 7 ] ); // Write.
context(); // The Context repository.
info( 'An informational message.' );