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

winston-mongodb to store aplication logs issue #1

Closed
fordox31 opened this issue Aug 25, 2011 · 0 comments
Closed

winston-mongodb to store aplication logs issue #1

fordox31 opened this issue Aug 25, 2011 · 0 comments

Comments

@fordox31
Copy link

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.

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

No branches or pull requests

2 participants