chameleon-m/phalcon-logger

Phalcon logger

v0.4.0 2017-10-07 22:06 UTC

This package is not auto-updated.

Last update: 2024-09-28 03:56:48 UTC


README

Latest Version Software License Total Downloads Build Status

如何安装

使用 Composer (推荐)

安装框架的最佳方式是使用 Composer,如果您还没有安装它

在终端中运行代码

composer create-project Chameleon-m/phalcon-logger /path/to/install

使用 Git

首先您需要克隆项目,更新供应商

git clone https://github.com/Chameleon-m/phalcon-logger.git ./project
cd project
composer update

数据库

对于 PostgreSQL

psql -h <host> -d <database> -U <user_name> -p <port> -a -w -f tests/_data/dump.sql

或者运行迁移(使用 phalcon devtools):phalcon migration run

有两种方法可用

POST /api/logs

POST /api/logs?queue=1 - 推入队列(需要运行任务 php cli.php logs queue -v -t 以保存)

其中的数据通过 json 传递。例如

POST curl -X POST -d '{"entity":"Event","entityId":1000,"date":"2017-12-12 12:12:12","userId":3,"action":"create","diff":{"before":"test1","after":"test2"}}' http://phalcon-logger.dev/api/logs

{
    "entity": "Event",
    "entityId": 1000,
    "date": "2017-12-12 12:12:12",
    "userId": 3,
    "action": "create",
    "diff": {
        "before": "test1",
        "after": "test2"
    }
}

日期以 Postgresql 时间戳格式传递。

GET /api/logs

查询可能的过滤器

  • from - 与 to 配对的过滤器。表示过滤开始的日期。
  • to - 与 from 配对的过滤器。表示过滤结束的日期。
  • entity - 实体名称。
  • entityId - 实体 id 数组。
  • action - 动作名称。
  • userId - 用户 id 数组。

响应如下

GET curl -X GET http://phalcon-logger.dev/api/logs?page=3

{
    "items": [
        {
            "id": 1,
            "entity": "Event",
            "entityId": 1000,
            "date": "2017-12-12 12:12:12",
            "userId": 3,
            "action": "create",
            "diff": {
                "before": "test1",
                "after": "test2"
            }
        },
        {...},
        {...},
    ],
    "first": 1,
    "before": 2,
    "current": 3,
    "last": 8,
    "next": 4,
    "total_pages": 8,
    "total_items": 72,
    "limit": 10
}

属性 - 描述

items - 当前页面要显示的记录集
current - 当前页
before - 当前页的前一页
next - 当前页的下一页
last - 记录集中的最后一页
total_pages - 页数总数
total_items - 源数据中的项目总数

测试

首先您需要重新生成基础类以测试所有套件

vendor/bin/codecept build

一旦创建数据库并重新生成基础类,请在终端上运行测试

vendor/bin/codecept run

或为详细输出

vendor/bin/codecept run --debug

要求

  • PHP 7.0 及以上
  • Phalcon 3.2.0
  • Composer

许可证

本项目是开源软件,许可协议为 MIT 许可。

有关更多信息,请参阅 LICENSE 文件。