# egg-accesslog

> accesslog for egg

Latest version **1.0.3** (published 2018-06-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-accesslog
pnpm add egg-accesslog
yarn add egg-accesslog
bun add egg-accesslog
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2018-06-06 |
| First published | 2017-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | xbf321 |
| Maintainers | xbf321 |
| Keywords | egg, eggPlugin, egg-plugin, accesslog, access-log |

## Links

- npm: https://www.npmjs.com/package/egg-accesslog
- Repository: https://github.com/xbf321/egg-accesslog
- Homepage: https://github.com/xbf321/egg-accesslog#readme
- Issues: https://github.com/eggjs/egg/issues
- npm.io page: https://npm.io/package/egg-accesslog

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.3 (latest) — 2018-06-06
- 1.0.2 — 2018-01-10
- 1.0.1 — 2017-09-27
- 1.0.0 — 2017-09-18

## README

# egg-accesslog

accesslog for egg。

某些情况，nginx 和 应用服务器，不在一台机器上，而有时恰恰需要在应用服务器上记录（如统计 PV，定位错误等）访问日志。

## Install

```bash
$ npm i egg-accesslog --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.accesslog = {
  enable: true,
  package: 'egg-accesslog',
};
```

> 如果使用 nginx 或其他反向代理服务器，请 **必须** 设置 **proxy = true**，不然获得的 ip 是本机ip，非远程机器的 ip.

    ```
    // {app_root}/config/config.default.js
    config.proxy = true
    ```

## Configuration

```js
// {app_root}/config/config.default.js
// 默认不需要配置，除非自定义 accesslog 格式
exports.accesslog = {
    /**
    * 自定义格式
    * {Object} data 数据对象
    *   - {String} ip 
    *   - {String} method
    *   - {String} url 
    *   - {String} host
    *   - {String} protocol 
    *   - {String} httpVersion
    *   - {String} statusCode
    *   - {String} contentLength 
    *   - {String} userAgent
    *   - {String} referer
    *   - {String} datetime
    *   - {String} responseTime
    *   - {String} xForwardedFor
    * @return {String} 返回格式
    **/
    format: function(data, ctx) {
        return `${data.ip}`;
    }
};
```
> accesslog 日志保存的路径，依据系统 *logger.dir* 的路径。

## Example

默认格式：

datetime ip "method url protocol/httpVersion" responseTime statusCode contentLength "referer" "userAgent" "host" "xForwardedFor"

```
2017-09-18 17:00:18,350 127.0.0.1 "GET /debug http/1.0" 12 200 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36" "127.0.0.1:7001" "192.168.1.1"
```

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/egg-accesslog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
