{"id":22246676,"url":"https://github.com/rmsnow/logmgmt","last_synced_at":"2025-03-25T11:24:58.710Z","repository":{"id":119331878,"uuid":"136889136","full_name":"RMSnow/Logmgmt","owner":"RMSnow","description":"Log Management: A module of Cloud Class Platform.","archived":false,"fork":false,"pushed_at":"2018-06-11T07:36:13.000Z","size":45584,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T10:30:42.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.dxtwangxiao.com/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RMSnow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-11T07:21:08.000Z","updated_at":"2018-06-11T07:36:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"cad32792-7d36-41b7-8714-d097e6eb1e21","html_url":"https://github.com/RMSnow/Logmgmt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RMSnow%2FLogmgmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RMSnow%2FLogmgmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RMSnow%2FLogmgmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RMSnow%2FLogmgmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RMSnow","download_url":"https://codeload.github.com/RMSnow/Logmgmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245451350,"owners_count":20617497,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-03T05:28:47.712Z","updated_at":"2025-03-25T11:24:58.685Z","avatar_url":"https://github.com/RMSnow.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 日志服务\n\n---\n\n## 综述\n\n本服务为其他服务提供日志管理的功能，主要包含以下三个方面：\n\n - 接收日志：其他服务通过在配置文件`.yml`中增加日志映射属性，即可将产生的日志自动传送至本服务，详见[服务配置日志方法](#yml).\n - 查询日志：访问本服务提供的[api](#query)，可查询日志列表.\n - 删除日志：访问本服务提供的[api](#delete)，可删除日志列表\n\n此外，服务还拥有如下功能：  \n - 日志分析：针对某服务的近期日志进行一定的分析.  \n - 应用层日志的接收与查询.  \n\n## 环境配置\n\n服务可通过`logmgmt.yml`文件更改下列配置信息：  \n```\nname: logmgmt\nurl: \nip: \nlogmgmtPort: \nsyslogPort: \nmongodbHost: \nmongodbPort: \nmongodbUserName: \nmongodbPassword: \n\nserver:\n  type: simple\n  connector:\n    type: http\n    port: \n```\n各属性的说明如下表所示：  \n\n|       属性名       |             说明              |          默认值          |\n| :-------------: | :-------------------------: | :-------------------: |\n|      name       |            本服务名称            |        -        |\n|       url       |          注册api的url          | - |\n|       ip        |         注册api的ip地址          |     -     |\n|   logmgmtPort   | 注册api的端口（进行日志**查询**与**删除**） |         -          |\n|   syslogPort    |       接收（**增加**）日志的端口       |         -          |\n|   mongodbHost   |            数据库主机            |     -     |\n|   mongodbPort   |            数据库端口            |         -         |\n| mongodbUserName |          数据库管理员用户名          |        -         |\n| mongodbPassword |          数据库管理员密码          |        -         |\n\n\n在服务器上进行首次配置时，应依次执行下列命令：\n\n1. MongoDB安装  \n2. 创建数据库  \n    `use logs`\n3. 创建用户  \n`db.createUser({user:\"logmgt\",pwd:\"logmgt\",roles:[{\"role\":\"readWrite\",\"db\":\"logs\"}]})`\n4. 检查用户权限  \n`db.auth(\"logmgt\",\"logmgt\")`，若返回值为`1`，则用户权限设置成功  \n1. 数据库操作  \n  \n（1）显示所有数据库：`show dbs`  \n\n（2）创建/切换数据库：`use logs`  \n\n2. 集合（表）操作  \n  \n（1）显示所有集合：`show collections`  \n\n（2）删除集合：`db.[COLLECTION NAME].drop()`  \n\n（3）查询文档：`db.[COLLECTION NAME].find().pretty()`  \n\n（4）查询集合中文档总数：`db.[COLLECTION NAME].find().pretty().count()`  \n\n3. 更多命令详见：[MongoDB](http://www.yiibai.com/mongodb/mongodb_query_document.html)  \n  \n日志服务可接收其他服务自动传送的日志，只需在其他服务的`.yml`配置文件中添加如下信息：  \n\n### 举例\n\n以日志服务为例，原配置文件为：  \n\n```\nname: courseservice\nip: 119.29.132.15\nport: 7000\nurl: http://123.207.73.150\n\nserver:\n  type: simple\n  connector:\n    type: http\n    port: 7000\n```\n\n添加日志的映射功能后为：\n\n```\nname: courseservice\nip: 119.29.132.15\nport: 7000\nurl: http://123.207.73.150\n\nserver:\n  requestLog:\n    appenders:\n      - type: syslog\n        host: localhost\n        port: 9898\n        facility: local0\n        threshold: ALL\n\n  type: simple\n  connector:\n    type: http\n    port: 7000\n\nlogging:\n\n  appenders:\n    - type: syslog\n      host: localhost\n      port: 9898\n      threshold: ALL\n```\n注：在使用时，`requestLog`与`logging`的`host`属性值应与本服务的`host`相同，`port`属性值应与本服务的`syslogPort`属性值相同。  \n\n## 日志分类\n\n如上方的配置信息所显示，本服务存储的日志共有两类：`logging`与`requestLog`。两类日志的介绍，以及资源所对应的`URI`如下表所示：\n\n|   类别    |  名称  |                说明                |    URI     |\n| :-----: | :--: | :------------------------------: | :--------: |\n| logging | 运行日志 | 服务运行时所产生的日志，主要包括INFO信息与**报错信息**等 | `loggings` |\n| request | 访问日志 |        服务的api受外界访问时所产生的日志        | `requests` |\n\n|  类别  | HTTP动词 |        Path        |\n| :--: | :----: | :----------------: |\n| 运行日志 |  GET   | `/api/v1/loggings` |\n| 访问日志 |  GET   | `/api/v1/requests` |\n\n访问api的总路径为：`[API前缀] Path [参数列表]`.  \n\n其中`[API前缀]`见[附录](#prefix)，`Path`如上表所示，`[参数列表]`将在下文详细叙述。 \n\n### 查询运行日志\n\n查询运行日志`logging`时，需使用如下的参数列表：  \n\n|      参数       |     说明      |             示例             |  备注  |\n| :-----------: | :---------: | :------------------------: | :--: |\n|  serviceName  |     服务名     |      `courseservice`       |  必选  |\n|    fromId     | 起始ID（不包括本身） | `5a23732ee6022d0372e6e570` |  可选  |\n|     level     |    日志级别     |            见下表             |  可选  |\n|     host      |     主机名     |        `localhost`         |  可选  |\n| fromTimeStamp | 起始日期（包括本身）  |            见下表             |  可选  |\n|  toTimeStamp  | 截止日期（包括本身）  |            见下表             |  可选  |\n|  errDetails   |  详细错误信息查看   |            `1`             |  可选  |\n|     limit     |    查询总数量    |            `50`            |  可选  |\n\n查询到的结果将按照时间降序排列，即优先显示最近生成的日志。  \n\n#### 参数`level`\n\n其中，`level`代表运行日志的级别，各`level`值所对应的日志级别如下所示：\n\n```\n0       Emergency: system is unusable\n1       Alert: action must be taken immediately\n2       Critical: critical conditions\n3       Error: error conditions\n4       Warning: warning conditions\n5       Notice: normal but significant condition\n6       Informational: informational messages\n7       Debug: debug-level messages\n```\n`level`值越低的日志，优先级越高。\n\n对`level`的传参使用**多值查询**，具体使用方法：用8位的二进制数表示是否查询各级别日志，且每个数位对应的级别如下：\n\n    Emergency | Alert | Critical | Error | Warning | Notice | Informational | Debug  \n      \n    128       | 64    | 32       | 16    | 8       | 4      | 2             | 1\n\n如：二进制数`[00011010]`，即参数`level = 26`表示的是查看`Error`、`Warning`、`Informational`这三种类型的日志。\n\n#### 参数`timestamp`\n\n`fromTimeStamp`与`toTimeStamp`可采用如下两种方式：\n\n|  种类  |         格式          |          示例           |\n| :--: | :-----------------: | :-------------------: |\n|  1   | yyyy-MM-dd hh:mm:ss | `2017-11-24 23:11:40` |\n|  2   |     yyyy-MM-dd      |     `2017-11-24`      |\n\n#### 参数`errDetails`\n\n`errDetails`参数的默认值为`0`，表示**不查看错误细节**，将其值改为`1`，即可查看错误日志的具体报错堆栈信息。  \n\n\n#### 示例\n注：如下所述的示例均为本地数据库查询，在实际使用时需修改API前缀，详见[附录说明](#prefix)。  \n\n在本地数据库中，查找服务名为`test`的日志：  \n\n`localhost:9999/application/api/v1/loggings?serviceName=test\u0026level=16\u0026fromTimeStamp=2017-12-03 11:44:46`  \n\n查询成功时，返回结果为：\n\n```\n{\n    \"msg\": \"1 results.\",\n    \"status\": 200,\n    \"data\": [\n        {\n            \"id\": \"5a23732ee6022d0372e6e56f\",\n            \"facility\": \"16\",\n            \"timestamp\": \"2017-12-03 11:44:46\",\n            \"level\": 3,\n            \"host\": \"snow.local\",\n            \"serviceName\": \"test\",\n            \"className\": \"io.dropwizard.jersey.errors.LoggingExceptionMapper\",\n            \"message\": \"[dw-20 - GET /application/api/v2/course] Error handling a request: ef745256c764503d [BASIC ERROR-DETAILS] java.lang.NullPointerException: null\",\n            \"errDetails\": null\n        }\n    ]\n}\n```\n对返回结果的说明，详见[附录](#status)。  \n\n### 查询访问日志\n\n查询访问日志`requestLog`时，需使用如下的参数列表：  \n\n|      参数      |     说明      |             示例             |  备注  |\n| :----------: | :---------: | :------------------------: | :--: |\n| serviceName  |     服务名     |      `courseservice`       |  必选  |\n|    fromId    | 起始ID（不包括本身） | `5a23732ee6022d0372e6e570` |  可选  |\n|     host     |     主机名     |        `localhost`         |  可选  |\n| fromDateTime | 起始日期（包括本身）  |            见下表             |  可选  |\n|  toDateTime  | 截止日期（包括本身）  |            见下表             |  可选  |\n|    method    |    访问方法     |           `GET`            |  可选  |\n|    status    |    返回状态码    |           `500`            |  可选  |\n|    limit     |    查询总数量    |            `50`            |  可选  |\n\n查询到的结果将按照时间降序排列，即优先显示最近生成的日志。  \n\n#### 参数`datatime`\n\n其中，`fromDateTime`与`toDateTime`可采用如下两种方式：\n\n|  种类  |         格式          |          示例           |\n| :--: | :-----------------: | :-------------------: |\n|  1   | yyyy-MM-dd hh:mm:ss | `2017-11-24 23:11:40` |\n|  2   |     yyyy-MM-dd      |     `2017-11-24`      |\n\n#### 参数`method`\n\n对参数`method`的查询支持**单值查询**与**多值查询**：\n\n    DELETE | PATCH | PUT | POST | GET\n    16     | 8     | 4   | 2    | 1  \n\n其中，单值查询即传入参数`DELETE`、`GET`等。对于多值查询，用5位二进制数表示是否查询某个方法。如，二进制数`[01011]`，即传入参数`method = 11`表示查询`GET`、`POST`、`PATCH`这三种方法的日志。\n\n\n#### 示例\n在本地数据库中，查找服务名为`test`的日志：  \n\n`localhost:9999/application/api/v1/requests?serviceName=test`  \n\n成功时返回结果：\n```\n{\n    \"msg\": \"3 results.\",\n    \"status\": 200,\n    \"data\": [\n        {\n            \"id\": \"5a237324e6022d0372e6e56d\",\n            \"host\": \"snow.local\",\n            \"serviceName\": \"test\",\n            \"className\": \"dw-21\",\n            \"facility\": 16,\n            \"clientIP\": \"0:0:0:0:0:0:0:1\",\n            \"datetime\": \"2017-12-03 11:44:35\",\n            \"method\": \"GET\",\n            \"url\": \"/application/api/v2/class\",\n            \"status\": 200,\n            \"client\": \"PostmanRuntime/6.4.1\"\n        },\n        {\n            \"id\": \"5a23732ae6022d0372e6e56e\",\n            \"host\": \"snow.local\",\n            \"serviceName\": \"test\",\n            \"className\": \"dw-27\",\n            \"facility\": 16,\n            \"clientIP\": \"0:0:0:0:0:0:0:1\",\n            \"datetime\": \"2017-12-03 11:44:41\",\n            \"method\": \"GET\",\n            \"url\": \"/application/api/v2/courseware\",\n            \"status\": 200,\n            \"client\": \"PostmanRuntime/6.4.1\"\n        },\n        {\n            \"id\": \"5a23732ee6022d0372e6e570\",\n            \"host\": \"snow.local\",\n            \"serviceName\": \"test\",\n            \"className\": \"dw-20\",\n            \"facility\": 16,\n            \"clientIP\": \"0:0:0:0:0:0:0:1\",\n            \"datetime\": \"2017-12-03 11:44:46\",\n            \"method\": \"GET\",\n            \"url\": \"/application/api/v2/course\",\n            \"status\": 500,\n            \"client\": \"PostmanRuntime/6.4.1\"\n        }\n    ]\n}\n```\n\n|  类别  | HTTP动词 |        Path        |\n| :--: | :----: | :----------------: |\n| 运行日志 | DELETE | `/api/v1/loggings` |\n| 访问日志 | DELETE | `/api/v1/requests` |\n\n访问api的总路径为：`[API前缀] Path [参数列表]`.  \n\n其中`[API前缀]`见[附录](#prefix)，`Path`如上表所示，`[参数列表]`将在下文详细叙述。\n\n### 删除运行日志\n\n删除运行日志`logging`时，需使用如下的参数列表：  \n\n|      参数       |     说明     |       示例        |  备注  |\n| :-----------: | :--------: | :-------------: | :--: |\n|  serviceName  |    服务名     | `courseservice` |  必选  |\n|     level     |    日志级别    |       `6`       |  可选  |\n|     host      |    主机名     |   `localhost`   |  可选  |\n| fromTimeStamp | 起始日期（包括本身） |      如上文所示      |  可选  |\n|  toTimeStamp  | 截止日期（包括本身） |      如上文所示      |  可选  |\n\n#### 示例\n在本地数据库中，删除服务名为`courseservice`的日志：  \n\n`localhost:9999/application/api/v1/requests?serviceName=courseservice`  \n\n删除失败时，返回结果为：  \n```\n{\n    \"msg\": \"NOT FOUND\",\n    \"status\": 404,\n    \"data\": \"\"\n}\n```\n### 删除访问日志\n\n删除访问日志`requestLog`时，需使用如下的参数列表：  \n\n|      参数      |     说明     |       示例        |  备注  |\n| :----------: | :--------: | :-------------: | :--: |\n| serviceName  |    服务名     | `courseservice` |  必选  |\n|     host     |    主机名     |   `localhost`   |  可选  |\n| fromDateTime | 起始日期（包括本身） |      如上文所示      |  可选  |\n|  toDateTime  | 截止日期（包括本身） |      如上文所示      |  可选  |\n|    method    |    访问方法    |      `GET`      |  可选  |\n|    status    |   返回状态码    |      `500`      |  可选  |\n\n#### 示例\n在本地数据库中，删除服务名为`test`的日志：  \n\n`localhost:9999/application/api/v1/loggings?serviceName=test\u0026level=6`  \n\n删除成功时，返回结果为： \n```\n{\n    \"msg\": \"12 results has been deleted.\",\n    \"status\": 200,\n    \"data\": \"\"\n}\n```\n\n## 日志分析\n\n### 综述\n\n本服务提供日志分析功能：通过对某服务一天内产生日志的分析，获得下列反馈信息：  \n\n- 该服务最常被调用的api以及数量  \n\n- 该服务运行时产生的错误数\n\n- 该服务的异常请求数  \n\n- 该服务最近一小时内，每隔5分钟的每秒请求数\n\n- 该服务最近30天每天服务访问量  \n\n  日志服务拥有下列两个计划任务：  \n\n- 每隔5分钟，需计算一次各服务的每秒访问次数.  \n\n- 每隔1小时，需将记录存入MongoDB数据库.  \n\n下面将分别阐述两个计划任务对应的api.\n\n### 每秒访问次数计算\n|HTTP动词|Path|\n|:-:|:-:|\n|POST|`/api/v1/records/rates`|\n\n#### 示例\n以本地的日志服务为例，每隔5分钟，需要访问下列api：  \n\n    localhost:9999/application/api/v1/records/rates  \n\n其返回值为：\n```\n{\n    \"msg\": \"Successfully calculate rates for [NUM] services.\",\n    \"status\": 200,\n    \"data\": \"\"\n}\n```\n其中，`[NUM]`为当前日志服务所管理的服务总数。\n\n### 每小时记录存储\n|HTTP动词|Path|\n|:-:|:-:|\n|POST|`/api/v1/records`|\n\n#### 示例\n以本地的日志服务为例，每隔1小时，需要访问下列api：  \n\n    localhost:9999/application/api/v1/records  \n\n其返回值为：\n```\n{\n    \"msg\": \"1 records have been added.\",\n    \"status\": 200,\n    \"data\": [\n        {\n            \"id\": null,\n            \"serviceName\": \"test\",\n            \"timestamp\": \"2017-12-22 21:43:17\",\n            \"apiRequestTable\": {\n                \"subject\": 3\n            },\n            \"loggingErrors\": 0,\n            \"requestExceptions\": 0,\n            \"hourRequests\": 3,\n            \"secondRequestsRate\": [\n                {\n                    \"timescale\": \"2017-12-22 21:43:14\",\n                    \"requests\": 3,\n                    \"rate\": 0\n                },\n                ... \n            ]\n        }\n    ]\n}\n```\n若没有生成任何记录，则返回值为：\n```\n{\n    \"msg\": \"None Records\",\n    \"status\": 404,\n    \"data\": \"\"\n}\n```\n### 日志分析记录查询\n\n日志分析接口提供了如下的查询功能：\n\n|HTTP动词|Path|\n|:-:|:-:|\n|GET|`/api/v1/records`|\n\n#### 请求参数列表\n|      参数       |     说明     |       示例        |  备注  |\n| :-----------: | :--------: | :-------------: | :--: |\n|  serviceName  |    服务名     | `courseservice` |  必选  |\n\n#### 返回参数说明\n|         参数         |            说明             |\n| :----------------: | :-----------------------: |\n|     timestamp      |          服务器运行时间          |\n|    serviceName     |            服务名            |\n|  apiRequestTable   | API访问表，记录该服务一天内的所有URI访问次数 |\n|  requestException  |       该服务一天内的异常请求数        |\n|   loggingErrors    |       该服务一天内的运行错误数        |\n| latestRequestRates |    该服务最近一小时内，每5分钟的请求数     |\n|   dailyRequests    |       该服务一天内的访问请求总数       |\n| recentDaysRequestsTable |      该服务最近一个月内，每天的访问请求数      |\n\n#### 示例\n以本地的日志服务为例，访问如下的api：\n\n    localhost:9999/application/api/v1/records/analysis?serviceName=test  \n\n其返回值为：  \n```\n{\n    \"msg\": \"The daily analysis of test\",\n    \"status\": 200,\n    \"data\": {\n        \"recentDaysRequestsTable\": [\n            {\n                \"timescale\": \"2017-11-23 23:00:43\",\n                \"requests\": 0,\n                \"rate\": 0\n            },\n            {\n                \"timescale\": \"2017-11-24 23:00:43\",\n                \"requests\": 0,\n                \"rate\": 0\n            },\n\n            ...\n\n            {\n                \"timescale\": \"2017-12-22 23:00:43\",\n                \"requests\": 16,\n                \"rate\": 0\n            }\n        ],\n        \"apiRequestTable\": {\n            \"course\": 1,\n            \"subject\": 10,\n            \"class\": 5\n        },\n        \"requestExceptions\": 1,\n        \"loggingErrors\": 1,\n        \"serviceName\": \"test\",\n        \"timestamp\": \"2017-12-22 23:00:43\",\n        \"latestRequestRates\": [\n            {\n                \"timescale\": \"2017-12-22 21:43:14\",\n                \"requests\": 3,\n                \"rate\": 0\n            },\n\n            ...\n\n        ],\n        \"dailyRequests\": 16\n    }\n}\n```\n\n## 应用层日志接收\n\n能够通过api访问接收应用层（客户端）传来的日志，日志的基本格式如下：  \n\n|属性|类型|说明|\n|:-:|:-:|:-:|\n|ip|String|访问客户端ip|\n|userId|String|操作用户id|\n|responseTime|long|响应时间|\n|api|String|调用api及其参数|\n|status|String|返回状态码|\n|error|String|错误|\n|msg|String|消息|\n通过传入日志的相关参数来进行日志接收。  \n\n|HTTP动词|Path|\n|:-:|:-:|\n|POST|`/api/v1/clients`|\n\n添加一条应用层日志，所需参数如下：  \n\n|      参数      |     说明     |  备注  |\n| :----------: | :--------: | :--: |\n| ip  |    访问客户端ip     | 必选  |\n|     userId     |    操作用户id     |  必选 |\n| responseTime | 响应时间 | 必选  |\n|  api  | 调用api及其参数 | 必选  |\n|    status    |    返回状态码    | 必选 |\n|    error    |   错误    | 必选 |\n|    msg    |   消息   | 必选  |\n\n#### 示例\n以本地的日志服务为例，添加一条应用层日志：  \n\n    localhost:9999/application/api/v1/clients?ip=192.168.1.101\u0026userId=snow\u0026responseTime=2000\u0026api=courseserive\u0026status=200\u0026error=none\u0026msg=normal  \n\n添加成功时，返回：\n```\n{\n    \"msg\": \"The log have been added.\",\n    \"status\": 200,\n    \"data\": [\n        {\n            \"id\": \"5a4b414de6022d07699513d2\",\n            \"timestamp\": \"2018-01-02 16:22:37\",\n            \"ip\": \"192.168.1.101\",\n            \"userId\": \"snow\",\n            \"responseTime\": 2000,\n            \"api\": \"courseserive\",\n            \"status\": \"200\",\n            \"error\": \"none\",\n            \"msg\": \"normal\"\n        }\n    ]\n}\n```\n通过传入日志的相关参数来进行应用层日志的条件查询。  \n\n|HTTP动词|Path|\n|:-:|:-:|\n|GET|`/api/v1/clients`|\n\n查询应用层日志，可以使用的参数如下：  \n\n|      参数      |     说明     |  备注  |\n| :----------: | :--------: | :--: |\n|fromTimestamp|起始时间|可选|\n|toTimestamp|结束时间|可选|\n| ip  |    访问客户端ip     | 可选  |\n|     userId     |    操作用户id     |  可选|\n|  api  | 调用api及其参数 | 可选  |\n|    status    |    返回状态码    | 可选 |\n|limit|返回的日志数量|可选|\n\n查询到的结果将按照时间降序排列，即优先显示最近生成的日志。  \n\n#### 示例\n以本地的日志服务为例，进行如下的条件查询：  \n\n    localhost:9999/application/api/v1/clients?fromTimestamp=2018-01-01\u0026toTimestamp=2018-01-03\u0026ip=192.168.1.100  \n\n添加成功时，返回：\n```\n{\n    \"msg\": \"3 results.\",\n    \"status\": 200,\n    \"data\": [\n        {\n            \"id\": \"5a4a5e5fe6022d0eedbc6498\",\n            \"timestamp\": \"2018-01-02 00:14:23\",\n            \"ip\": \"192.168.1.100\",\n            \"userId\": \"snow\",\n            \"responseTime\": 2000,\n            \"api\": \"courseserive\",\n            \"status\": \"200\",\n            \"error\": \"none\",\n            \"msg\": \"normal\"\n        },\n        {\n            \"id\": \"5a4a5e63e6022d0eedbc6499\",\n            \"timestamp\": \"2018-01-02 00:14:27\",\n            \"ip\": \"192.168.1.100\",\n            \"userId\": \"snow\",\n            \"responseTime\": 2000,\n            \"api\": \"courseserive\",\n            \"status\": \"200\",\n            \"error\": \"none\",\n            \"msg\": \"normal\"\n        },\n        {\n            \"id\": \"5a4a5ef0e6022d0eedbc649a\",\n            \"timestamp\": \"2018-01-02 00:16:48\",\n            \"ip\": \"192.168.1.100\",\n            \"userId\": \"snow\",\n            \"responseTime\": 2000,\n            \"api\": \"courseserive\",\n            \"status\": \"200\",\n            \"error\": \"none\",\n            \"msg\": \"normal\"\n        }\n    ]\n}\n```\n\n无记录时，返回值为：\n```\n{\n    \"msg\": \"None Logs\",\n    \"status\": 404,\n    \"data\": \"\"\n}\n```\n\n服务器异常时，返回值为：\n```\n{\n    \"msg\": \"Errors in querying logs.\",\n    \"status\": 500,\n    \"data\": \"\"\n}\n```\n\n## 附录\n\n### 返回结果\n\n返回结果格式如下：\n\n```\n{\n    \"msg\" : 字段,\n    \"status\" : 状态码,\n    \"data\" : 数组或对象\n}\n```\n\n### HTTP状态码\n\n状态码`status`说明：\n\n```\nSuccessful 200\n\nClient Error 4XX:\n404 NOT FOUND - [*]：用户发出的请求针对的是不存在的记录，服务器没有进行操作，该操作是幂等的。\n\nServer Error 5XX:\n500 INTERNAL SERVER ERROR - [*]：服务器发生错误，用户将无法判断发出的请求是否成功。\n```\n### API前缀\n\n访问本服务时，API前缀为：`[主机名]:[logmgmtPort]/application`.  \n\n如：在本地访问时，前缀为`localhost:9999/application`.  \n\n### 日志级别\n\n各`level`值所对应的日志级别如下所示：\n\n```\n0       Emergency: system is unusable\n1       Alert: action must be taken immediately\n2       Critical: critical conditions\n3       Error: error conditions\n4       Warning: warning conditions\n5       Notice: normal but significant condition\n6       Informational: informational messages\n7       Debug: debug-level messages\n```\n其中，`level`值越低的日志，优先级越高。  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmsnow%2Flogmgmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frmsnow%2Flogmgmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frmsnow%2Flogmgmt/lists"}