Created
August 29, 2016 02:51
-
-
Save luoyjx/757cacacb257847a45fd813d376834ae to your computer and use it in GitHub Desktop.
morgan access log config
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
var fs = require('fs'); | |
var app = express(); | |
var logger = require('morgan'); | |
var FileStreamRotator = require('file-stream-rotator'); | |
var logDirectory = config.access_log_path; | |
// ensure log directory exists | |
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory) | |
// create a rotating write stream | |
var accessLogStream = FileStreamRotator.getStream({ | |
date_format: 'YYYYMMDD', | |
filename: logDirectory + '/access-%DATE%.log', | |
frequency: 'daily', | |
verbose: false | |
}) | |
app.use(logger('tiny', {stream: accessLogStream})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment