Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs winston loggin to mongodb

I tried to make advanced logging for my project.

var winston = require('winston');
var MongoDB = require('winston-mongodb').MongoDB;
var logger = new(winston.Logger)({
    transports : [
        new(winston.transports.MongoDB)({
            db : 'logs'
        })
    ]
});
module.exports = logger;

And I got an error:

/opt/City13/node_modules/winston-mongodb/node_modules/mongodb/lib/url_parser.js:16
throw Error("URL must be in the format mongodb://user:pass@host:port/dbnam
      ^
Error: URL must be in the format mongodb://user:pass@host:port/dbname
at Error (<anonymous>)
at module.exports (/opt/City13/node_modules/winston-mongodb/node_modules/mongodb/lib/url_parser.js:16:11)
at Function.MongoClient.connect (/opt/City13/node_modules/winston-mongodb/node_modules/mongodb/lib/mongo_client.js:95:16)
at new exports.MongoDB (/opt/City13/node_modules/winston-mongodb/lib/winston-mongodb.js:124:25)
at Object.<anonymous> (/opt/City13/logger/index.js:5:7)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

I tried to add host ip adress to settings, but it was not working.

like image 241
Niro Avatar asked Dec 25 '22 21:12

Niro


1 Answers

this configuration worked for me:

    var logger = new (winston.Logger)({
    transports: [
        new(winston.transports.MongoDB)({
            db : 'mongodb://localhost:27017/Book-catalog',
            collection: 'logs'
        })
       ]
    });

('Book-catalog' is the name of my database)

like image 183
Jadran Grba Avatar answered Jan 21 '23 16:01

Jadran Grba