PHPackages                             caixingyue/laravel-star-log - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. caixingyue/laravel-star-log

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

caixingyue/laravel-star-log
===========================

This is a package that enhances the Laravel log format. It can inject request ID, craftsman ID, queue ID, and supports enhanced capabilities such as routing request log, HTTP client request log, SQL Query log, etc.

v1.0.6(1y ago)135MITPHPPHP ^8.2

Since Sep 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/caixingyue/laravel-star-log)[ Packagist](https://packagist.org/packages/caixingyue/laravel-star-log)[ RSS](/packages/caixingyue-laravel-star-log/feed)WikiDiscussions main Synced today

READMEChangelog (7)Dependencies (5)Versions (8)Used By (0)

Rebuild the log structure based on laravel log
==============================================

[](#rebuild-the-log-structure-based-on-laravel-log)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b113a0f4da6394693be3f0b1a31d05350ddb3519612348c5fb9eed7ef59ef558/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63616978696e677975652f6c61726176656c2d737461722d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/caixingyue/laravel-star-log)[![GitHub Tests Action Status](https://camo.githubusercontent.com/808260761a240c0c85cccc030cf6321df38880a66f27f53071e685d68e0e7854/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63616978696e677975652f6c61726176656c2d737461722d6c6f672f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/caixingyue/laravel-star-log/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ded078b3fb9b2eed1f0330c3eb3fed4eac56932b50eb5897e991614bafa5fa9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63616978696e677975652f6c61726176656c2d737461722d6c6f672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/caixingyue/laravel-star-log/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/727cb963d5d5f9d032935422de5ebcad586985504a91e1443a93605b467b9012/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63616978696e677975652f6c61726176656c2d737461722d6c6f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/caixingyue/laravel-star-log)

This is a package that enhances the Laravel log format. It can inject request ID, craftsman ID, queue ID, and supports enhanced capabilities such as routing request log, HTTP client request log, SQL Query log, etc.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require caixingyue/laravel-star-log
```

You can publish the config file with:

```
php artisan vendor:publish --tag="star-log-config"
```

Usage
-----

[](#usage)

### Log format configuration

[](#log-format-configuration)

After the installation is complete, you need to add a new `channels` information to the `config/logging.php` configuration file. The following is a common reference example, you can modify the configuration as needed.

```
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.
```

### Injecting request ID

[](#injecting-request-id)

If you wish to inject the `request ID`, you may append it to the global `middleware` stack in your application's `bootstrap/app.php` file:

```
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.
```

### Enable request logging

[](#enable-request-logging)

If you would like clients to automatically log request and response information when they request your routes, you may attach this to the global `middleware` stack in your application's `bootstrap/app.php` file:

```
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"}
```

### Routing Configuration

[](#routing-configuration)

Sometimes we want to return the request ID in the response header when responding to troubleshoot problems. Or we may not want to record request logs for certain URLs or methods, or even secret field information. For these situations, you can add relevant configuration to the `starlog.php` configuration file:

When you want to return the request ID in the response, you can set `STAR_LOG_RESPONSE_HEAD_ID` to `true` in the `env` configuration.

```
'route' => [
    'response_head_id' => env('STAR_LOG_RESPONSE_HEAD_ID', false),
],
```

If you do not want to record request logs for certain URLs, you can add the information to be excluded in the `except`.

- For example, you can add `/home` to exclude the path `https://example.com/home` from processing.
- You can use the \* wildcard to match all paths in a pattern. For example, `/admin/*` will exclude all paths starting with `/admin/`.
- If desired, you can also add the full URL including domain name and protocol.
- If you want to exclude certain paths based on the URL's query string, include those as well. For example, `/search?q=laravel`.

```
'route' => [
    'except' => [
        //
    ],
],
```

If you do not want to record requests of certain methods, such as `GET`, `POST`, etc., you can add the information to be excluded in `except_method`.

```
'route' => [
    'except_method' => [
        //
    ],
],
```

For some secret information fields that you do not want to be recorded in the log, you can add the relevant field name in the `secret_fields` field, and the system will automatically replace the data with `******` before recording the data. Currently, we have configured the common fields `current_password`, `password`, and `password_confirmation` as secret fields, which can be adjusted if necessary.

```
'route' => [
    'secret_fields' => [
        'current_password',
        'password',
        'password_confirmation',
    ],
],
```

### Injecting Artisan ID

[](#injecting-artisan-id)

If you wish to inject the `artisan ID`, you may use the `InjectionId` method in your command class:

```
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.
```

### Injecting Queue ID

[](#injecting-queue-id)

If you wish to inject the `queue ID`, you may use the `InjectionId` method in your job 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.
```

Generally, only `handle` can use the `queue ID`. If `__construct` also needs to use it, you can call `$this->initializeInjectionId()` in `__construct` to initialize it.

### Enable HTTP client request logging

[](#enable-http-client-request-logging)

If you want the system to automatically log requests and responses when making HTTP client requests, you can set `STAR_LOG_ENABLE_HTTP_CLIENT` to `true` in the `env` configuration.

```
'http' => [
    'enable' => env('STAR_LOG_ENABLE_HTTP_CLIENT', false),
],

// [2024-09-03 10:52:51.455935] 85234719.INFO[HttpClient@request:39]: GET[https://example.com] - 请求报文: [null]
// [2024-09-03 10:52:51.787507] 85234719.INFO[HttpClient@response:37]: 耗时[0.325134s] - 200[https://example.com] - 响应报文: {"code":"success"}
```

For some secret information fields that you do not want to be recorded in the log, you can add the relevant field name in the `secret_fields` field, and the system will automatically replace the data with `******` before recording the data. Currently, we have configured the common fields `current_password`, `password`, and `password_confirmation` as secret fields, which can be adjusted if necessary.

```
'http' => [
    'secret_fields' => [
        'current_password',
        'password',
        'password_confirmation',
    ],
],
```

### Enable SQL Query logging

[](#enable-sql-query-logging)

If you want the system to automatically log when SQL queries are issued, you can set `STAR_LOG_ENABLE_SQL_QUERY` to `true` in the `env` configuration.

```
'query' => [
    'enable' => env('STAR_LOG_ENABLE_SQL_QUERY', false),
],

// [2024-09-03 10:49:41.908266] 81156302.INFO[System@db:46]: SQL Query: insert into "users" ("name", "email", "email_verified_at", "password", "remember_token", "updated_at", "created_at") values (?, ?, ?, ?, ?, ?, ?) | Bindings: ["Gilda Sawayn IV","jena36@example.net","2024-09-03 10:49:41","$2y$12$lxv6rkqo8DCGmWC.JviQe.rD0mytUTPUm2DnyanWM8gPcceRN7EmS","pn0TkAqvxW","2024-09-03 10:49:41","2024-09-03 10:49:41"] | Time: 0.69ms
```

If you do not want to record certain SQL queries, you can add the SQL to be excluded in the `except`. The SQL statement to be excluded does not have to be complete, as long as it is a part of the SQL.

By default, we will exclude SQL operations on laravel basic tables. If necessary, you can adjust them as needed.

In the exclusion, \* key means that it has effect in all class methods. If you need to limit the restrictions within a class, you can specify the class name as the key, such as `ExampleJob`.

```
'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"',
        ],
    ],
],
```

### Helpers

[](#helpers)

We provide some helpers that can help you get some data in different scenarios.

```
// 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();
```

Generally, in classes that use injected id, we recommend using the $this method.

```
// 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();
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [xingyue cai](https://github.com/caixingyue)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~50 days

Recently: every ~56 days

Total

7

Last Release

366d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/39073687?v=4)[caixingyue](/maintainers/caixingyue)[@caixingyue](https://github.com/caixingyue)

---

Tags

laravelcaixingyuelaravel-star-log

### Embed Badge

![Health badge](/badges/caixingyue-laravel-star-log/health.svg)

```
[![Health](https://phpackages.com/badges/caixingyue-laravel-star-log/health.svg)](https://phpackages.com/packages/caixingyue-laravel-star-log)
```

###  Alternatives

[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M167](/packages/spatie-laravel-health)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M102](/packages/dedoc-scramble)[stephenjude/filament-jetstream

A Laravel starter kit built with Filament inspired by Jetstream.

17760.2k3](/packages/stephenjude-filament-jetstream)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
