Skip to content

Commit

Permalink
Simplify log file rotation example
Browse files Browse the repository at this point in the history
The rfs module will automatically create the log directory (https://www.npmjs.com/package/rotating-file-stream#function-filenameindex) so this example doesn't need to manually check for or create the directory.
  • Loading branch information
davidjb committed Oct 4, 2018
1 parent 572dd93 commit ec9651b
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,20 +309,18 @@ app.get('/', function (req, res) {
Simple app that will log all requests in the Apache combined format to one log
file per day in the `log/` directory using the
[rotating-file-stream module](https://www.npmjs.com/package/rotating-file-stream).
The `rotating-file-stream` module will automatically create the log directory in
this example if it doesn't already exist.

```js
var express = require('express')
var fs = require('fs')
var morgan = require('morgan')
var path = require('path')
var rfs = require('rotating-file-stream')

var app = express()
var logDirectory = path.join(__dirname, 'log')

// ensure log directory exists
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory)

// create a rotating write stream
var accessLogStream = rfs('access.log', {
interval: '1d', // rotate daily
Expand Down

0 comments on commit ec9651b

Please sign in to comment.