devnav2902/utilitylog is a Laravel package for write a custom message in log.
It currently has 0 GitHub stars and 267 downloads on Packagist (latest version 1.0.1).
Install it with composer require devnav2902/utilitylog.
Discover more Laravel packages by devnav2902
or browse all Laravel packages to compare alternatives.
Last updated
This package help you write a custom log message, customize based on LineFormatter - Monolog
Install the latest version with command:
composer require devnav2902/utilitylog
UtilityLog::writeLog('error', 'Foo');
UtilityLog::writeLog('info', 'Bar');
// in try-catch block
try {
throw new \Exception('Something happened!');
} catch (\Throwable $th) {
UtilityLog::writeLog('error', 'Error in try-catch block', $th);
}
// contextual information
UtilityLog::writeLog('info', 'User {id} failed to login.', null, ['id' => $user->id]);
This package use LineFormatter (Monolog), so you can set a custom format like this:
"[%channel%][%level_name%] %datetime%\n%message% %extra%\n\n"
You can modify in config file, here is default config:
<?php
return [
'customize_formatter' => "[%channel%][%level_name%] %datetime%\n%message% %extra%\n\n",
'date_format' => 'Y-m-d H:i:s',
'message_json_option' => JSON_PRETTY_PRINT,
'allow_inline_linebreaks' => true,
'ignore_empty_context_and_extra' => true,
'include_stacktraces' => false
];
This use for params of LineFormatter:
class CustomizeFormatter
{
/**
* Customize the given logger instance.
*/
public function __invoke(Logger $logger): void
{
foreach ($logger->getHandlers() as $handler) {
$lineFormatter = new LineFormatter(
config('utilitylog.customize_formatter'),
config('utilitylog.date_format'),
config('utilitylog.allow_inline_linebreaks'),
config('utilitylog.ignore_empty_context_and_extra'),
config('utilitylog.include_stacktraces')
);
$handler->setFormatter($lineFormatter);
}
}
}
:writing_hand: If you want to change default of config, you can use a command:
php artisan vendor:publish --tag=utilitylog-config
This will copy file from package to your laravel project folder config\utilitylog.php.
:writing_hand: You can view log file in storage\logs by go to url: /view-log or /view-log?date=Y-m-d with Y-m-d is date format, example: 2024-05-01, this will open file: laravel-2024-05-01.log.
You can customize view by publish view use this command:
php artisan vendor:publish --tag=utilitylog-views
This package works with PHP 8.1 or above.
Utilitylog is licensed under the MIT License - see the LICENSE file for details