1.0.5 • Published 8 years ago

express-simple-log v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

express-simle-log

这是一个简单的日志记录中间件。 会在 node 运行的目录生成一个 log.json。 结构如下:

[
    {
        type: "信息",
        content: "你要打印的东西",
        createTime: "new Date()"
    }
]

安装

npm install express-simple-log --save

使用

var express = require('express');
var log = require('express-simple-log');
var app = express();
app.use(log({
    console: true
}))

opt

现在只有个一个参数, 就是 console, 默认是 false。 当 opt.console 设置为 true 的时候, 日记内容会 console 在控制台打印出来。 like:

app.use('/', function(req, res, next){
    req.log('访问首页成功!');
})
// log.josn 就会好像这样
[
    {
        type: "信息",
        content: "访问首页成功",
        createTime: "new Date()"
    }
];

// 控制台会打印出
{type: "信息", content: "访问首页成功",createTime: "new Date()"}

req.log

req.log 办法接受一个参数,可以不传, 得到 log.json 的json 文本。 如果是字符串, 该条日记类型默认为信息 type: "信息"。 如果是对象, 对象结构参考 { type: "成功", content: "添加用户成功!"}

opt.type == deleteLog

如果日志类型是 deleteLog, 那么 content 内容应该是类型, 标志要删除的类型

// 删除又有类型为 ip 的日志
req.log({
    type: 'deleteLog',
    content: 'ip'
})
1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago