Last active
June 25, 2017 03:39
-
-
Save MichinobuMaeda/a22c161d7612ab9a5d78132b166b40c6 to your computer and use it in GitHub Desktop.
how to store bunyan log stream into mongoose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bunyan = require('bunyan') | |
const mongoose = require('mongoose') | |
const Schema = mongoose.Schema; | |
const Log = mongoose.model('Log', new Schema({ | |
name: String, | |
hostname: String, | |
pid: Number, | |
level: Number, | |
msg: String, | |
time: { type: Date, index: true }, | |
v: Number, | |
}, { | |
versionKey: 'ver', | |
})); | |
const MongooseLogStream = class { | |
write(rec) { | |
try { new Log(JSON.parse(rec)).save() } | |
catch(e) { console.error(e) } | |
} | |
} | |
const log = bunyan.createLogger({ | |
name: "my log store", | |
streams: [{stream: new MongooseLogStream()}] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment