Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

after pushing logs to mongoDB script keeps running and is not ending #211

Open
smartini87 opened this issue Nov 13, 2022 · 5 comments
Open

Comments

@smartini87
Copy link

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.
grafik

I would expect the debugger to disconnect- but it is not.
grafik

I must click on "stop process" to kill the infitine loop.
grafik

The script is pretty straight forward as I am playing around a little with the mongoDB connection.
Am I doing something wrong?


logger.info('text info');
logger.warn('text warn');
logger.error('text error');

The transporter setup:

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.MongoDB({
                level:'error',
                db: db_name,
                options: { useUnifiedTopology: true },
                collection: 'colllection1',
            })
      });
}

module.exports = buildProdLogger;
@wbt
Copy link

wbt commented Nov 15, 2022

Are you closing the logger?

@smartini87
Copy link
Author

How would I do that and where to insert it?

@wbt
Copy link

wbt commented Nov 17, 2022

logger.close() at the end of the substantive work (and after you're done logging).

@smartini87
Copy link
Author

smartini87 commented Nov 17, 2022

const logger = require('./logger');

function run(){
    logger.info('text info');
    logger.warn('text warn');
    logger.error('text error');
    logger.close();
}

run();

Still stuck in the process, not the result I expected.

Edit: Is there a way to disconnect the connection to the MongoDB? Maybe this is the reason.

@wbt
Copy link

wbt commented Nov 18, 2022

That could be! As I'm not a user of the MongoDB piece myself, is there a good way you can get visibility into that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants