Coder Social home page Coder Social logo

module-log-middleware's Introduction

日志中间件

安装

composer require wss0823/module-log-middleware

中间件依赖 uniondrug/middleware 中间件基础组件。

修改 app.php 配置文件,加上Middleware服务,服务名称LogMiddleware

return [
    'default' => [
        ......
        'providers'           => [
            ......
             \Uniondrug\Middleware\MiddlewareServiceProvider::class,
            \Uniondrug\ModuleLogMiddleware\LogMiddleware::class,
        ],
    ],
];

增加配置文件 middleware.php,加入如下配置

return [
    'default' => [
        // 应用定义的中间件
        'middlewares' => [
            // 注册名为token的中间件
            'addLog' => \Uniondrug\ModuleLogMiddleware\LogMiddleware::class,
        ],
        // 将token中间件放在全局中间列表中
        'global' => [
            'addLog'
        ],
        'addLog' => [
            'whitelist' => [
                //请求controllers 路由名称
                'amap' => [
                    //请求function 路由名称 & 路由备注
                    'search' => '地图查询',
                ],
            ]
        ]
    ]
];

在db注册的数据库中增加如下表

CREATE TABLE `http_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  `request_id` varchar(32) NOT NULL DEFAULT '' COMMENT '请求链id',
  `http_url` varchar(32) NOT NULL DEFAULT '' COMMENT '请求地址',
  `http_url_content` varchar(240) NOT NULL DEFAULT '' COMMENT '请求地址简介',
  `user_agent` varchar(240) NOT NULL DEFAULT '' COMMENT '请求来源',
  `ip` varchar(120) DEFAULT '' COMMENT 'IP地址',
  `request_body` text COMMENT '请求入参json',
  `gmt_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
  `gmt_updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  PRIMARY KEY (`id`),
  KEY `idx_request_id` (`request_id`) USING HASH COMMENT '请求链',
  KEY `idx_http_url` (`http_url`) USING HASH COMMENT '请求地址',
  KEY `idx_user_agent` (`user_agent`) USING BTREE COMMENT '请求来源'
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='请求日志表';

module-log-middleware's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.