What is the default location of Winston logs?
-
24-06-2021 - |
Pergunta
I am using something like this:
var winston = require('winston'), logger = new (winston.Logger)({
transports: [
new (winston.transports.Console) (),
new (winston.transports.File) ({filename: 'test.log'})
]
});
logger.log('Hello world');
I cannot find the log file test.log
anywhere on my system and no exception or info in the console either.
Solução
Nevermind, I found the answer. If you do not specify directory, it is in the same directory as the code.
Outras dicas
Paste the following snippet in your winston.helper.js
// create directory for logs first
if (!fs.existsSync("logs")) {
fs.mkdirSync("logs");
}
OR
You can write a command in your package.json
script For e.g.
"dev": "mkdir logs | ..."
set the route of the file name like this '${__dirname}/filename' if this not working change the colon into back quote
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow