# koa-sam-log

> Log output middleware for koa

Latest version **1.0.3** (published 2018-12-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install koa-sam-log
pnpm add koa-sam-log
yarn add koa-sam-log
bun add koa-sam-log
```

## 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-12-10 |
| First published | 2018-11-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | samfung09 |
| Maintainers | samfung09 |
| Keywords | koa, middleware, log4js, logger |

## Links

- npm: https://www.npmjs.com/package/koa-sam-log
- Repository: https://github.com/samfung09/koa-sam-log
- Homepage: https://github.com/samfung09/koa-sam-log#readme
- Issues: https://github.com/samfung09/koa-sam-log/issues
- npm.io page: https://npm.io/package/koa-sam-log

## Dependencies (1)

- [log4js](https://npm.io/package/log4js.md) ^3.0.6

## 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-12-10
- 1.0.2 — 2018-11-06
- 1.0.1 — 2018-11-06
- 1.0.0 — 2018-11-06

## README

## koa-sam-log koa2的日志输出中间件
基于log4js 3.0.6版本
### 安装
```
npm install koa-sam-log --save
```
### 基本使用
```javascript
const myLog = require('koa-sam-log');

// myLog函数传入一个appender和一些其他配置
app.use(myLog({ 
    type: 'dateFile',   //按日期创建文件，文件名为 filename + pattern
    filename: 'logs/',
    pattern: 'yyyy-MM-dd.log',
    alwaysIncludePattern: true
},{
    env: app.env,      //如果是development则可以同时在控制台中打印
    level: 'info'      //logger level
}));
```
app.use()之后，即可使用ctx.log.info(), ctx.log.error()等log4js的方法

最终打印信息内包括客户端ip, user-agent, method, path, MobileOrPC, responseTime等信息
```
[2018-11-07T00:24:08.406] [INFO] default - {"ip":"::1","method":"GET","path":"/","userAgent":"PC","responseTime":"0.001s","message":"恭喜你用koa-sam-log中间件成功打印日志"}
```

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