-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] support to create log directory if it doesn't exist for file tr…
…ansport (#1556) * feat: support to create log dir if it doesn't exist for file transport * test: add test cases
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const winston = require('../../lib/winston'); | ||
|
||
/* eslint-disable no-sync */ | ||
|
||
describe('winston/transports/file/createLogDir', function () { | ||
const logDir = path.resolve(__dirname, '../fixtures/temp_logs'); | ||
|
||
beforeEach(function () { | ||
fs.rmdirSync(logDir); | ||
}); | ||
|
||
it('should create directory if it does not exist', function () { | ||
winston.createLogger({ | ||
transports: [ | ||
new winston.transports.File({ | ||
filename: path.join(logDir, 'file.log') | ||
}) | ||
] | ||
}); | ||
|
||
assert(fs.existsSync(logDir)); | ||
}); | ||
|
||
it('should create directory if it does not exist when write to the stream', function () { | ||
const streamfile = path.join(logDir, 'simple-stream.log'); | ||
const stream = fs.createWriteStream(streamfile); | ||
|
||
winston.createLogger({ | ||
transports: [ | ||
new winston.transports.File({ | ||
stream: stream | ||
}) | ||
] | ||
}); | ||
|
||
assert(fs.existsSync(logDir)); | ||
}); | ||
}); |