承接 artim/logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artim/logger

最新稳定版本:0.2.4

Composer 安装命令:

composer require artim/logger

包简介

Logger in file for laravel

README 文档

README

How to start

At first we need install package:

composer require artim/logger

Add LARAVEL_START const to artisan file in root directory:

define('LARAVEL_START', microtime(true));

This is necessary to fix the start time of request processing.

Then we need append ArtimLoggerServiceProvider.php to app.php config. Here you can see the effect of configuration settings on the information that will be logged.

class ArtimLoggerServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        $this->publishes([
            __DIR__ . '/../config/artim-logger.php' => config_path('artim-logger.php'),
        ], 'config');
    }

    public function register(): void
    {
        $this->app->make(LogRegistrator::class)->set();
        $this->app->make(HttpRegistrator::class)->set();

        if (config('artim-logger.logs.application')) {
            $this->app->make(AppLogRegistrator::class)->set();
        }

        if (config('artim-logger.logs.db')) {
            $this->app->make(DBLogRegistrator::class)->set();
        }

        $this->mergeConfigFrom(__DIR__ . '/../config/artim-logger.php', 'artim-logger');
    }
}
class AppLogRegistrator extends AbstractRegistrator
{
    public function set(): void
    {
        $this->app->terminating(function () {
            $data = [
                'type' => 'application',
                'startedAt' => LARAVEL_START,
                'endedAt' => microtime(true),
                'peakMemoryUsage' => get_formatted_peak_memory_usage(),
            ];

            if (config('artim-logger.logs.request')) {
                $data['request'] = request();
            }

            \Log::info('App terminating', $data);
        });
    }
}

Then we need add Http facade to list of aliases in app.php:

'Http' => \Artim\Logger\Http\Http::class,

Now you can append configuration for logger in logging.php:

'artim' => [
    'driver' => 'monolog',
    'level' => env('LOG_LEVEL', 'debug'),
    'handler' => \Monolog\Handler\RotatingFileHandler::class,
    'formatter' => \Artim\Logger\Logger\File\JsonFormatter::class,
    'handler_with' => [
        'filename' => storage_path('logs/laravel-artim.log'),
    ],
],

It will write logs to storage/logs/laravel-test.log file:

\Log::info('Some log message', ['property' => 'some value of the property']);
{
  "message": "Some log message",
  "context": {
    "property": "some value of the property",
    "user": null,
    "token": "cd3856c0bc1abae60ebd8f1df9d0ebb8"
  },
  "level": 200,
  "level_name": "INFO",
  "channel": "local",
  "datetime": "2023-03-18T18:58:13.262363+00:00",
  "extra": {}
}

If you want to track the action of your application inside the queues, you can use the class Artim\Logger\Job

namespace Artim\Logger\Job;

use Illuminate\Contracts\Queue\ShouldQueue;

abstract class Job implements ShouldQueue
{
    use LogToken;

    protected string $logToken;
}

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固