1. Go to this page and download the library: Download caixingyue/laravel-star-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/ */
caixingyue / laravel-star-log example snippets
use Caixingyue\LaravelStarLog\Formatter\StrengthenFormatter;
'channels' => [
'star_daily' => [
'driver' => 'daily',
'formatter' => StrengthenFormatter::class,
'formatter_with' => [
// Defined as microsecond time
'dateFormat' => 'Y-m-d H:i:s.u'
],
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => env('LOG_DAILY_DAYS', 14),
'replace_placeholders' => true,
],
],
// [2024-09-03 08:32:05.161104] local.INFO[App.Http.Controllers.ExampleController@index:12]: Hello, I am now in the index method under the ExampleController controller and have issued this record.
use Caixingyue\LaravelStarLog\Http\Middleware\AssignRequestId;
->withMiddleware(function (Middleware $middleware) {
$middleware->append(AssignRequestId::class);
})
// [2024-09-03 08:36:10.896827] 7146967637.INFO[App.Http.Controllers.ExampleController@index:12]: Hello, I am now in the index method under the ExampleController controller and have issued this record.
use Caixingyue\LaravelStarLog\Http\Middleware\RouteLog;
->withMiddleware(function (Middleware $middleware) {
$middleware->append(RouteLog::class);
})
// [2024-09-03 08:39:18.923444] 8055622306.INFO[System@request:96]: [Macintosh|OS X|PC端] - [127.0.0.1] - GET[/] - 请求报文: [null]
// [2024-09-03 08:39:18.935572] 8055622306.INFO[App.Http.Controllers.ExampleController@index:12]: Hello, I am now in the index method under the ExampleController controller and have issued this record.
// [2024-09-03 08:39:18.938116] 8055622306.INFO[System@response:118]: 耗时[0.09s] - 内存消耗[2mb] - 响应报文: {"code":"success"}
use Caixingyue\LaravelStarLog\Console\InjectionId;
class Example extends Command
{
use InjectionId;
}
// [2024-09-03 10:20:24.107848] 90819036.INFO[App.Console.Commands.Example@handle:52]: Hello, I have now issued this record under the Example command class.
use Caixingyue\LaravelStarLog\Queue\InjectionId;
class ExampleJob implements ShouldQueue
{
use InjectionId;
}
// [2024-09-03 10:24:37.351645] 57326518.INFO[App.Jobs.ExampleJob@handle:30]: Hello, I have now issued this record under the ExampleJob class.
'query' => [
'except' => [
ExampleJob::class => [
'select * from "users"',
],
'*' => [
'insert into "sessions"',
'insert into "cache"',
'insert into "cache_locks"',
'insert into "jobs"',
'insert into "job_batches"',
'insert into "failed_jobs"',
'delete from "sessions"',
'delete from "cache"',
'delete from "cache_locks"',
'delete from "jobs"',
'delete from "job_batches"',
'delete from "failed_jobs"',
'update "sessions"',
'update "cache"',
'update "cache_locks"',
'update "jobs"',
'update "job_batches"',
'update "failed_jobs"',
'select * from "sessions"',
'select * from "cache"',
'select * from "cache_locks"',
'select * from "jobs"',
'select * from "job_batches"',
'select * from "failed_jobs"',
],
],
],
// Get current request id
StarLog::getRequestId();
// Get the most recent artisan id
StarLog::getArtisanId();
// Get the most recent queue id
StarLog::getQueueId();
// Get all injection id list
StarLog::getInjectionIds();
// Get current artisan or queue id
$this->getId();
// Get current request id
$this->getRequestId();
// Get current artisan id
$this->getArtisanId();
// Get current queue id
$this->getQueueId();