I testing the logging library Winston for Node.js. I use VS Code as an IDE.
When using the normal function to store the logs into a file or print the logs into the debug console, everything works as exptected. To File:
When trying to push the logs to a MongoDB the logs will be transfered as expected but the tool is not terminating. I always have to stop the process excution manually. What is the issue here?
It is like the debugger is not disconnecting properly as the end is missing like at the other transporter options:
"Waiting for the debugger to disconnect..."
This is my code (I got it from a youtube tutorial, but apparently it is working smooth on the side of the guy providing the tutorial):
prod-logger.js
const { format, createLogger, transports } = require('winston');
const { timestamp, combine, colorize, errors, json } = format;
require('winston-mongodb');
require('dotenv').config()
const db_name = process.env.MONGODBNAME
function buildProdLogger(){
return createLogger({
format: combine(
timestamp(),
errors({stack: true}),
json(),
),
defaultMeta: { service: 'user-service' },
/* transports: [new transports.File({
filename: './logs/logs.log'})], */
/* transports: [new transports.Console({
filename: './logs/logs.log'})], */
transports: new transports.MongoDB({
leve:'error',
db: db_name,
options: { useUnifiedTopology: true },
collection: 'collection1'
})
});
}
module.exports = buildProdLogger;
logger/index.js
const buildDevLogger = require('./dev-logger');
const buildProdLogger = require('./prod-logger');
let logger = null;
if (process.env.NODE_ENV === 'development'){
logger = buildDevLogger
} else {
logger = buildProdLogger
}
module.exports = logger();
index.js (this is my main function)
const logger = require('./logger');
logger.info('text info');
logger.warn('text warn');
logger.error('text error');
Via Active questions tagged javascript - Stack Overflow https://ift.tt/9OibGms
Comments
Post a Comment