Giter Site home page Giter Site logo

winston-mongodb's People

Contributors

amit775 avatar awlawl avatar b3rn475 avatar blove avatar chjj avatar curledupsheep avatar dabh avatar denneulin avatar dependabot[bot] avatar ijmir avatar indexzero avatar j13z avatar jaydub2099 avatar jbrems avatar jonuy avatar kashav avatar krohrsb avatar liril-net avatar masterodin avatar mohammedessehemy avatar mpetrak avatar panuhorsmalahti avatar perrin4869 avatar santanu-biswas avatar sixcircuit avatar sourabh8003 avatar sovcik avatar tibeoh avatar yosefd avatar yurijmikhalevich avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winston-mongodb's Issues

handleExceptions is not set when specified in the options

I specified handleExceptions as follows:

winston.add(require('winston-mongodb').MongoDB, {
    db : cn.name, host : cn.host, port : cn.port, capped : true,
    username : cn.user, password : cn.pass, handleExceptions : true
});

but the property handleExceptions of the created logger is undefined.

Bad latest version in NPM/Yarn

The NPM/Yarn said that 1.6.5 is the latest version, when 2.0.0 is the correct one.
I think this is related to the v char on the tag name (i.e. v1.6.5), the algorithm fails to compare the version number so compares them by release date.

logger is dropping logs while it's waiting to authorizeDb and createCollection

https://github.com/winstonjs/winston-mongodb/blob/master/lib/winston-mongodb.js#L123

In the following log queueing code, the queue determination is dependent on this.mainDb,

if (!this.mainDb) {
this._opQuery.push({
method: 'log',
args: arguments
});
return;
}

But... in the following code, we turn on this switch before we authorize and createCollection. Any logs coming in after this.MainDb exists will not be queued. Somewhere between the authorizeDb and createCollection calls, the logging code is dropping the logs. Not in the mood to pull my hair out over it, as clearly there's an obvious bug here, the queue switch should be thrown in the createCollection callback, right before calling processOpQuery. Probably not cool to be trying to write to a database while you're currently authorizing to it, or to a collection while you're creating a collection, in my case the collection already exists, but if it didn't, you could have code trying to log to a collection before you created it.

if ('string' === typeof this.db) {
mongodb.MongoClient.connect(this.db, this.options, function(err, db) {
if (err) {
console.error('winston-mongodb: error initialising logger', err);
return;
}
self.mainDb = db;
authorizeDb(function() {
createCollection(processOpQuery);
});
});
} else {
this.mainDb = this.db;
authorizeDb(function() {
createCollection(processOpQuery);
});
}
};

maybe something like:

this.queueLogs = true;

if (this.queueLogs) {
this._opQuery.push({
method: 'log',
args: arguments
});
return;
}

authorizeDb(function () {
createCollection(function(err) {
self.queueLogs = false;
processOpQuery()
}
}

Here's my code, the readme.txt explains it, but simple enough. Just gets in that sweet spot where we're calling authorizeDb and createCollection and tries to log... to no avail.

https://gist.github.com/dankahle/06d21584a6bed63cc7cf

winston-mongodb to store aplication logs issue

Hello,


First there is a little mistake on the github publication :
var MongoDB = require('winston-mongoDB').MongoDB;

When I tried to make the module work, I saw that the require is not 'winston-mongoDB' but 'winston-mongodb'.

So, I need to make some logs of actions done by users on a website. My work is in node.js
I am trying to make working winston-mongodb to store a log (for example, a sentence) in a mongodb database

I installed mongodb on a ubuntu 10.04. Here is my source code in CoffeeScript, and in Javascript.

In CoffeeScript :

class CreateLogPreference
constructor: (personId=1, preferenceAction='test', entityType='truc', entityId=1) ->
@personid=personId
@preferenceAction=preferenceAction
@entityType=entityType
@EntityID=entityId

 winston = require('winston');

 winston.log('info', 'The personId : ' + @personId + ' did a preference Action of : ' + @preferenceAction + ' on the entity Id:' + @entityId + ' Type:' + @entityType);

 MongoDB = require('winston-mongodb').MongoDB;
 options = { db: 'log' };
 winston.add(MongoDB, options);

module.exports = CreateLogPreference;

Converted in javascript :

(function() {
var CreateLogPreference;
CreateLogPreference = (function() {
function CreateLogPreference(personId, preferenceAction, entityType, entityId) {
var MongoDB, options, winston;
if (personId == null) {
personId = 1;
}
if (preferenceAction == null) {
preferenceAction = 'test';
}
if (entityType == null) {
entityType = 'truc';
}
if (entityId == null) {
entityId = 1;
}
this.personId = personId;
this.preferenceAction = preferenceAction;
this.entityType = entityType;
this.entityId = entityId;
winston = require('winston');
winston.log('info', 'The personId : ' + this.personId + ' did a preference Action of : ' + this.preferenceAction + ' on the entity Id:' + this.entityId + ' Type:' + this.entityType);
MongoDB = require('winston-mongodb').MongoDB;
options = {
db: 'log'
};
winston.add(MongoDB, options);
}
return CreateLogPreference;
})();
module.exports = CreateLogPreference;
}).call(this);

Then I use this code :

var Logger = require('./CreateLogPreference.js');
var logger = new Logger();

And it displays:
info: The personId : 1 did a preference Action of : test on the entity Id:1 Type:truc

That's the log I want to store, but when I do a "show collections" on the database 'log', I still see nothing. How can I write this sentence in the mongoDB in the 'log' database ?

This project being recent, I don't find a lot of resources on the web.

Any clue ?
Thank you.

Best regards.

Cannot find module 'winston-mongodb'

Installed winston-mongoldb with npm (npm install winston-mongodb) it installs successfully. I then start my server (node server.js) and get the following error:

module.js:338
throw err;
^
Error: Cannot find module 'winston-mongodb'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)

I can find winston-mongodb inside the node_modules folder. This is how I load the module:
var winston = require('winston');
var MongoDB = require('winston-mongodb').MongoDB;

Is there something in the new release that break this? (Downgraded to 0.5.1 and everything works fine)

Timestamp format

How can we set format of Timestamp to a real timestamp ?

not 2016-06-12T15:42:33.337Z
but 1465746153

nextTick gotchas

I've run into two gotchas with a process.nextTick that I thought people should know about. Here's the code that I'm referring to:

https://github.com/indexzero/winston-mongodb/blob/master/lib/winston-mongodb.js#L97

Gotcha #1: In my application, I'm defining a handler for process.on('uncaughtException'). It performs a log, then in the callback from the logger, it rethrows the error.

Because we have Error -> log -> nextTick -> throw Error, this goes into a recursive loop and overflows the database, and the app never finishes exiting and restarting. So as an application programmer, you should be very careful putting a throw in the callback coming back from logging, as it behaves differently than a synchronous throw would.

Gotcha #2: If you trigger logging, then immediately afterwards throw an exception, the logging will never happen because the nextTick delays execution, and the throw exits the program before it gets a chance to log.

These are definitely not problems with the winston-mongodb library, but it was non-intuitive to me as a programmer, so I wanted to record it in case other people stumble across it. Might be a good candidate for adding some notes in the documentation.

Real small issue with logging hostnames

Sorry but a real small issue when recording the hostnames (too small for a pull + i'm lazy). Basically in lib/winston-mongodb.js on line 183 its:

entry.hostname = this.hostname;

when it should be:

entry.hostname = self.hostname;

Nodejitsu support

My attempts to use winston-mongodb on nodejitsu platform failed because of its explicit dependency on [email protected].
It seems that nodejitsu runs on SunOS and [email protected] actually does not support sunos.

npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: [email protected]
npm ERR! notsup Valid OS:    linux,darwin,freebsd
npm ERR! notsup Valid Arch:  any
npm ERR! notsup Actual OS:   sunos
npm ERR! notsup Actual Arch: x64

A possible solution would be to update mongodb dependancy version from [email protected] to [email protected] but I'm not sure it continue to work seamlessly.

Exceptions when mongo server is not available

TypeError: Object false has no method 'collection'
at Array.0 (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:74:14)
at flushPending (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:134:21)
at onError (C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:144:5)
at C:\anode\repo\node_modules\winston-mongodb\lib\winston-mongodb.js:150:14
at C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\db.js:170:16
at [object Object]. (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\server.js:299:7)
at [object Object].emit (events.js:67:17)
at [object Object]. (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:97:15)
at [object Object].emit (events.js:70:17)
at Socket. (C:\anode\repo\node_modules\winston-mongodb\node_modules\mongodb\lib\mongodb\connection\connection.js:386:10)

Problems installing on Ubuntu 14.04

[email protected] install /home/kokujin/development/research/text_express/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos

(node-gyp rebuild) || (exit 0)

make: Entering directory /home/kokujin/development/research/text_express/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build' CXX(target) Release/obj.target/kerberos/lib/kerberos.o make: g++: Command not found make: *** [Release/obj.target/kerberos/lib/kerberos.o] Error 127 make: Leaving directory/home/kokujin/development/research/text_express/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:269:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Linux 3.16.0-49-generic
gyp ERR! command "node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/kokujin/development/research/text_express/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v2.0.1
gyp ERR! not ok
[email protected] node_modules/winston-mongodb

log will create the collection before _ensureCollection does

I'm having an issue when using winston-mongodb in a production app where I initialize logging after a connection to mongo is established but while other async processes that may log are running. It creates the collection during log events, making it uncapped because ensureCollection hasn't run yet. I'm exploring other ways to solve this, but this does seem like something the module should handle.

Decolorize log messages received through stream

I use express for my node.js apps, which in turn uses morgan for logging. I use the following code for redirecting morgan logging to winston:

var express = require('express');
var winston = require('winston');
var MongoDB = require('winston-mongodb').MongoDB;

winston.setLevels( winston.config.npm.levels );
winston.addColors( winston.config.npm.colors );

var logger = new (winston.Logger)({
    transports: [
        new winston.transports.Console({
            level: 'info',
            colorize: true,
            timestamp: true
        }),
        new winston.transports.MongoDB({
            level: 'info',
            label: true,
            timestamp: true,
            handleExceptions: true,
            db: 'appdb,
            collection: 'applog',
            tryReconnect: true
        })
    ],
    exceptionHandlers: [
        new winston.transports.File({
            filename: 'log/exceptions.log',
            humanReadableUnhandledException: true,
            timestamp: true
        })
    ]
});

logger.stream = {
    write: function(message, encoding){
        logger.info(message.slice(0, -1));
    }
};

app.use(morgan('dev', { stream: logger.stream }));

This works fine for the Console transport, however, since morgan colorizes parts of the log message, It results in the message getting saved in mongodb collection with the color codes as following:

\u001b[0mGET /v1/countries \u001b[32m200 \u001b[0m5.956 ms - 8276\u001b[0m

I tried replacing logger.stream in my code as following:

logger.stream = {
    write: function(message, encoding){
        logger.info(message.slice(0, -1).replace(/\u001b\[[0-9]{1,2}m/g, ''));
    }
};

This removes the color codes but then it also removes the colors for Console transport. Slice removes the unnecessary newline at the beginning of the morgan log entry

I want to keep the colors for Console transport but want to remove it from File & MongoDB transports. For File transport I can use the formatter option, but don't have that option in MongoDB transport.

Is there any readily available solution for this?

The simplest solution that I can think of is to change the code line of in winston-mongodb:

entry.message = msg;

to

entry.message = msg.replace(/\u001b\[[0-9]{1,2}m/g, '');

I am really not sure why would anyone would want to save the color code in MongoDB log, but assuming that someone might actually require the color coded log entry, decolorize can be added as an option for the MongoDB transport, and then the code can be:

entry.message = self.decolorize ? msg.replace(/\u001b\[[0-9]{1,2}m/g, '') : msg;

If this is an acceptable feature/solution, I am willing to submit a PR for this.

Timestamp Index

The query calls are getting slower and slower with more and more log items. The reason is the missing index for timestamp. I am getting the last items which means MongoDB has to process all of them to order them by date.

Could you please create an index?

Here is a code snippet:

db.createCollection(self.collection, opts, function(err, coll) {
    if (err) {
        return cb(err);
    }

    coll.createIndex({ timestamp: -1 }, function (err) {
        cb(err, db);
    });
});

A couple of error conditions are silently ignored by winston-mongodb. Would be good to log them on the console at least.

Regards,
Christoph

npm test doesn't work

if i clone the repo, install deps, i get the following error if i run npm test

> [email protected] test /Users/booyaa/Dropbox/Coding/node/winston-mongodb
> vows test/*-test.js --spec


module.js:340
    throw err;
          ^
Error: Cannot find module 'winston/test/transports/transport'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/booyaa/Dropbox/Coding/node/winston-mongodb/test/winston-mongodb-test.js:14:17)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0
updating package.json to use 0.6.x 

snooping around the code in flatiron/winston it looks like transport.js only appears in 0.6.x. updating winston-mongodb's package.json to use winston 0.6.x gets a different error:

> [email protected] test /Users/booyaa/Dropbox/Coding/node/winston-mongodb
> vows test/*-test.js --spec


  ♢ winston-mongodb

  An instance of the MongoDB Transport when passed valid options
    ✓ should have the proper methods defined

/Users/booyaa/Dropbox/Coding/node/winston-mongodb/node_modules/mongodb/lib/mongodb/connection/server.js:359
        throw err;
              ^
RangeError: Maximum call stack size exceeded
npm ERR! Test failed.  See above for more details.
npm ERR! not ok code 0

cappedMax not working??

I know the config I'm using is getting picked up because i use the 'label' option and now i see that label on every document. but the cappedMax is not being honored.. my config is below. What's up?
...
new(winston.transports.MongoDB)({
db: config.db,
level: 'info',
handleExceptions: true,
exitOnError: false,
cappedMax: 25,
label: "TEST LABEL"

    })

v1.6.4 Initialization Error

Upgrading to v1.6.4 starts throwing the following error:

winston-mongodb, initialization error:  { MongoError: index not found with name [timestamp_1]
    at Function.MongoError.create (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/error.js:31:11)
    at /Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:483:72
    at authenticateStragglers (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:429:16)
    at Connection.messageHandler (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:463:5)
    at Socket.<anonymous> (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/connection.js:309:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)
  name: 'MongoError',
  message: 'index not found with name [timestamp_1]',
  nIndexesWas: 1,
  ok: 0,
  errmsg: 'index not found with name [timestamp_1]',
  code: 27 }
winston-mongodb, initialization error:  { MongoError: index not found with name [timestamp_1]
    at Function.MongoError.create (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/error.js:31:11)
    at /Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:483:72
    at authenticateStragglers (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:429:16)
    at Connection.messageHandler (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/pool.js:463:5)
    at Socket.<anonymous> (/Users/sbiswas/Documents/Code/SalesTracker/salestracker-web/node_modules/mongodb-core/lib/connection/connection.js:309:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)
  name: 'MongoError',
  message: 'index not found with name [timestamp_1]',
  nIndexesWas: 1,
  ok: 0,
  errmsg: 'index not found with name [timestamp_1]',
  code: 27 }

Checked relevant tables in MongoDB and the they do have the index named timestamp_1.

Reverting back to v1.6.1 removes this error.
Looks like there is a bug in v1.6.4

db "preconnected db" setting makes the module async

If you open a mongo connection, you have to wait for it to open as this module will try to db.createCollection() right off the bat. If I pass in a connection string, the module waits for the callback. I could of course return a promise from my db module and wait on that promise for this module's init, but then this module would be async too, returning a promise to all modules using a logger (can't happen). So, pass in the string. Just out of curiosity, how exactly was the "existing db connection" to work? I.e. how are you to expect this connection to be ready when it's opening is async.

Can't think of an easy way around this. If your module can wait for the connection string options to db.createCollection, then can't it wait for this other as well? Maybe the solution is to ask for a "connected db" promise instead and wait on that. A little hassle for them, but on the other hand, how can you assume the connection will be ready? Help me out if I'm missing something here.

Adds a space to the beginning of the message

For some reason my messages all have two spaces at the beginning (level and meta are normal). I'm assuming this is via this module as logging to a file and the console work just fine.

Example:
"message": " This is a message"

Replica Sets Not Working

I currently have a dbUri specified in my options object, however it appears this code in lib/winston-mongodb.js is only allowing me to use the one host (as replicaSet is not parsed by muri package)?

    } else if (uriOptions.hosts && uriOptions.hosts[0]) {
      options.host = uriOptions.hosts[0].host;
      options.port = uriOptions.hosts[0].port;
    }

Therefore when using dbUri, no writes to the DB are working with this package.

Having trouble streaming logs

I'm trying to stream the logs but I get "[Error: Connection was destroyed by application]" like every 10 seconds. Additionally it seems to call me with the same message sometimes:

var lastMsg, logStream = mongodbLogger.stream({includeIds:true});
logStream.on('log', function (log) {
    if (lastMsg == String(log._id)) {
        // I have no idea why this happens, but it does.
        return;
    }
    lastMsg = String(log._id);
    /* Here I print it out or do stuff */
}).on('error', function (e) {
    /* This happens a lot, and then it stops streaming */
    console.log('winston streaming error.',e);
});

No license included in repository

Hi @indexzero,

Would you consider adding a license to the repository? It's currently missing one and according to TOS:

[Not posting a license] means that you retain all rights to your source code and that nobody else may reproduce, distribute, or create derivative works from your work. This might not be what you intend.

Even if this is what you intend, if you publish your source code in a public repository on GitHub, you have accepted the Terms of Service which do allow other GitHub users some rights. Specifically, you allow others to view and fork your repository.

If you want to share your work with others, we strongly encourage you to include an open source license.

If you don't intend on putting a license up that's fine, but if you do want to use an open source license please do so. I'd be happy to fork/PR for you if you just let me know which license you want to put in (MIT/BSD/Apache/etc.)

Thanks!

"/?%2E" causes a server crash.

The following server code with request to http://localhost:3000/?%2E crashes the server:

var express = require('express'),
    expressWinston = require('express-winston');
    winstonMongoDB = require('winston-mongodb');

var app = express();

app.use(expressWinston.logger({
  transports: [
    new (winstonMongoDB.MongoDB)({
      level: 'error',
      db: 'test',
      collection: 'test'
    })
  ]
}));

app.listen(3000);

The exception thrown:

/node_modules/winston-mongodb/node_modules/mongodb/lib/mongodb/connection/base.js:242
        throw message;
              ^
Error: key . must not contain '.'
    at Error (<anonymous>)
    at Function.checkKey (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1444:13)
    at serializeObject (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:356:14)
    at packElement (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:855:23)
    at serializeObject (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:360:15)
    at packElement (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:855:23)
    at serializeObject (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:360:15)
    at Function.serializeWithBufferAndIndex (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:332:10)
    at BSON.serializeWithBufferAndIndex (/node_modules/winston-mongodb/node_modules/mongodb/node_modules/bson/lib/bson/bson.js:1526:15)
    at InsertCommand.toBinary (/node_modules/winston-mongodb/node_modules/mongodb/lib/mongodb/commands/insert_command.js:146:37)

Typescript support

Is it possible to add a winston-mongodb.d.ts file to support Typescript syntax ?

Replicaset in mongodb

how config multiples hosts in new version, for example my config is:

new (winston.transports.MongoDB)({
name: 'mongo-info',
db: "mongodb://user:pass@host1,host2/db_name"
collection: '',
storeHost: true,
level: 'info',
timestamp: true
}),

but new version 1.6 does not work...

Connect to MongoDB using with different authentication database

Hi,

After searching many hours I need to create this issue.Cause I didn't optimal solution.I rent mongodb as a service from one company and they created user which is not using "admin" database for authentication database.For this reason I changed mongoose connection as descripted in this issue.
[https://github.com/Automattic/mongoose/issues/1114](Mongoose Issue 1114)

But when I tried this code :

var logger = new(winston.Logger)({
    transports: [
        new(winston.transports.Console)(),
        new(winston.transports.MongoDB)({
            db: 'mongodb://localhost/dataDB?authSource=customAuthDB',
            username: config.dbUsername,
            password: config.dbPassword,
            handleExceptions: config.winstonErrorHandle
        })
    ],
    exitOnError: false
});

I am getting this error :

winston-mongodb: error initialising logger { 
[MongoError: Authentication failed.]
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
code: 18,
errmsg: 'Authentication failed.' }

So I got stuck when I am authenticate with using customAuthDB. How can I fix this ?

Failed to build

I cannot build this on Ubuntu 14.4.2. Tried 1.2.x and 1.1.x

> [email protected] install /var/www/test/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
> (node-gyp rebuild) || (exit 0)

make: Entering directory `/var/www/test/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build'
  CXX(target) Release/obj.target/kerberos/lib/kerberos.o
In file included from ../lib/kerberos.cc:1:0:
../lib/kerberos.h:5:27: fatal error: gssapi/gssapi.h: No such file or directory
 #include <gssapi/gssapi.h>
                           ^
compilation terminated.
make: *** [Release/obj.target/kerberos/lib/kerberos.o] Error 1
make: Leaving directory `/var/www/test/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/share/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.16.0-38-generic
gyp ERR! command "nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /var/www/test/node_modules/winston-mongodb/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos
gyp ERR! node -v v0.10.25
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok 
[email protected] node_modules/winston-mongodb
└── [email protected] ([email protected], [email protected], [email protected])

Add more data

Hi,

Is there any way to set more data to the entries ?
I use 'hostname' and 'label' and i'd like to add another one like 'scriptName' for example.

error when querying too many logs

When i do a query with a "big" limit for example:

var options = {
    from: new Date - 24 * 60 * 60 * 1000,
    until: new Date,
    limit: 2000
};

I get this reply:
"logs": {
"name": "MongoError"
}"

Support for MongoDB 3.0

Hi,

I've briefly started using with my project, works really well in my development environment. Thanks :)

MongoDB 3.x has just been released and it would be great if this module supported the new driver. I'd like to use it in production in future.

Tests don't run

I've tried running the tests, but I'm getting MongoError: Connection Closed By Application. When debugging, I can trace the error back to a RangeError from the call stack being blown.

I've tested on:

  • OS X 10.9.2, Node 0.10.26, MongoDB 2.4.9, mongodb 1.3.23
  • Ubuntu 12.04 (Precise), Node 0.10.21, MongoDB 2.4.8, mongodb 1.3.19

Node application hangs

Hello -
I am using winston-mongo v1.1.0.
I have a simple app.js that runs a few .log commands. Initially, I did this just using Winston native file and console based transports. This worked fine. The app starts up, logs to the file/console, and shuts down normally. But, when I require winston-mongo in my app.js and add it as a transport, when I run the otherwise same app.js the node application successfully logs to Mongo but does not shut down. I have to ctrl-c to end the process. Can you provide any insight to what I'm doing wrong?

  • EJB

Logged data are altered

When I call my data asynchronously after being logged, it has been modified.

As it's not easy to describe, I created an example here

Note that if I remove winston.transports.MongoDB from winston transports, everything is ok.

Unable to reconnect if MongoDB is not running when winston-mongodb starts

If winston-mongodb is already running, it is able to reconnect to MongoDB automatically. However, if MongoDB is not running when winston-mongodb starts, winston-mongodb throws the following error and the MongoDB connection is broken permanently.

winston-mongodb: error initialising logger { [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
  name: 'MongoError',
  message: 'connect ECONNREFUSED 127.0.0.1:27017' }

Wonder if there is any quick way to resolve this issue. I am using winston-mongodb in a critical project and reconnect is very important. I appreciate any insights.

Thanks a lot!
Jingzhao

Renaming default collection breaks stuff

In 1.1.0, the default collection was changed from 'logs' to 'log'. I would classify this as a breaking change, because although logs continue to be written, that is only half of the story. Logs are not useful without a means to view or filter them, and they are no longer visible to any other code that reads the 'logs' collection. This unexpectedly broke my server code.

I know you can work around this by changing the application to specify the collection name, but that's not really the point. The idea of defaults is so that you don't have to specify them. Under semver rules, breaking changes should only be made when the major version number changes, not minor ones.

Winston Mongo is dead?

So it seems there is not much activity on this package. Is there any willingness to maintain it further?

Logs not stored in collection

Hi,

I try to add a MongoDB transport type. The collection is created but no data is stored...

logger.js

var winston = require('winston');
require('winston-mongodb').MongoDB;

winston.configure({
	transports: [
		new (winston.transports.Console)({ json: false, colorize: true }),
		new (winston.transports.MongoDB)({ db: 'mongodb://localhost/tests', collection: 'logs', level: 'info', capped: true }),
	]
});

module.exports = winston;

And in one of my file:

var logger = require('./logger.js')

winston.log('info', 'transaction ok');
// or
logger.info('transaction ok');

The log display in my terminal but never stored in collection. What is wrong?

Thanks guys for your help ;)

Unable to create multiple transport instances

I wanted to do something like this:

var logger = new (winston.Logger) ({
  transports: [
    new winston.transports.MongoDB({dbUri: uri, collection: 'logs_info', level: 'info'}),
    new winston.transports.MongoDB({dbUri: uri, collection: 'logs_error', level: 'error'})
  ]
});

where I log to the same database, but different levels would go into different collections. I found that doing this would result in a "Transport already attached: mongodb" error though.

Is this something that actually is supported but I'm going about it in the wrong way? Or is there a reason it's not supported and that I shouldn't be trying to do this?

MongoError: Index name can not be empty

Hello there,

I am getting this error when trying to connect

MongoError: Index name can not be empty

But using the same db without winston works just fine, Can you please advice.

Thanks.

Setting safe: true in the options doesn't guarantee log message getting written

Added safe: true in the options for the MongoDB transport. Then I log a message and throw an error immediately after. Message shows up in console but not mongo. Adding handleExceptions: true also fails to log anything in mongo. I am considering implementing a custom transport with synchronous logging to mongo. Is this necessary, or am I using the transport incorrectly?

key with dots are not fully sanitized. only the first dot removed

/Users/john/Development/myProject/node_modules/mongodb/lib/utils.js:98
    process.nextTick(function() { throw err; });
                                  ^

Error: key a[dot]b.c must not contain '.'
    at Error (native)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:731:19)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:596:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:596:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:596:17)
    at serializeObject (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:294:18)
    at serializeInto (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/parser/serializer.js:754:17)
    at serialize (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/lib/bson/bson.js:49:27)
    at Query.toBin (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/connection/commands.js:143:25)
    at executeWrite (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:69:20)
    at WireProtocol.insert (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:80:3)
    at Server.insert (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:502:35)
    at executeWriteOperation (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:896:37)
    at ReplSet.insert (/Users/john/Development/myProject/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:920:3)
    at ReplSet.insert (/Users/john/Development/myProject/node_modules/mongodb/lib/replset.js:371:18)
    at insertDocuments (/Users/john/Development/myProject/node_modules/mongodb/lib/collection.js:703:19)
    at insertOne (/Users/john/Development/myProject/node_modules/mongodb/lib/collection.js:409:3)
    at Collection.insertOne (/Users/john/Development/myProject/node_modules/mongodb/lib/collection.js:397:44)
    at /Users/john/Development/myProject/node_modules/winston-mongodb/lib/winston-mongodb.js:271:11
    at Db.collection (/Users/john/Development/myProject/node_modules/mongodb/lib/db.js:449:20)
    at /Users/john/Development/myProject/node_modules/winston-mongodb/lib/winston-mongodb.js:253:16
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickDomainCallback [as _tickCallback] (node.js:390:13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.