writing in both files
See original GitHub issueThis is writing in both log file success and error.log if i called with log.fail I would expect it should write in error-date.log file. I don’t know what’s wrong here
const fs = require('fs');
var winston = require('winston');
const env = process.env.NODE_ENV;
const logDir = 'logs';
if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
const now = new Date();
var logger = winston.createLogger({
transports: [
new (require('winston-daily-rotate-file'))({
filename: `${logDir}/success-%DATE%.log`,
timestamp: now,
datePattern: 'DD-MM-yyyy',
prepend: true,
json: false,
level: 'info',
}),
new (require('winston-daily-rotate-file'))({
filename: `${logDir}/error-%DATE%.log`,
timestamp: now,
datePattern: 'DD-MM-yyyy',
prepend: true,
json: false,
level: 'error',
}),
],
exitOnError: false,
});
const log = {
fail: function (ee) {
logger.error(`${now.toISOString()} - ${JSON.stringify(ee)}`);
},
success: function (ee) {
logger.info(`${now.toISOString()} - ${JSON.stringify(ee)}`);
},
};
module.exports = log;
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python - Writing from a file to two files
My current script creates both files. The DOB.txt file is populated but makes duplicate lines. The POSTCODE.txt file is empty. Any help will...
Read more >How to write the difference between two files into a file
If you want the difference between the two files, use diff rather than comm . e.g. diff -u a.txt b.txt > c.txt.
Read more >Reading and Writing to text files in Python
There are two types of files that can be handled in python, normal text ... Read and Write ('r+'): Open the file for...
Read more >Reading and Writing in Text Files with multiple programs ...
Reading and Writing in Text Files with multiple programs accessing it simultaneously · Read – Gives read access to the file. · ReadWrite...
Read more >Reading and Writing Files in Python (Guide)
In this tutorial, you'll learn about reading and writing files in Python. You'll cover everything from what a file is made up of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is not really how levels work in log mechanisms. What you could do, if this is a requirement, is to have your log module contain 2 loggers, each with a separate transport configured. For example:
Hi @mattberther , Is there any way not to write error i.e level: error log in info log, Basically i would like to create two separate log based on success and error.