loggly connection

99 views
Skip to first unread message

Wes Williams

unread,
Aug 23, 2011, 12:06:43 PM8/23/11
to nodejs
I have started using loggly (considering winston as well) for logging
and it was easy to get setup. I have a worry though that if I am using
this in multiple modules I am requiring that I will have more
connections and have a scaling issue at some point. Is there a better
way than a global reference to keep a shared connection/client for
loggly?

Maybe my newness to node.js and asynchronous event driven development
has not allowed me to see a better option. Ideas?

Thanks,
wes

Charlie Robbins

unread,
Aug 25, 2011, 1:27:48 AM8/25/11
to nod...@googlegroups.com
Wes,

Can you provide a code snippet to better illustrate your concerns? By default, npm will try to install the minimal number of versions on disk, so when you call

var loggly = require('loggly');

It will most likely be the same object. In the same vein, winston has a default logger which (should) always be the same object even with non-trivial module dependencies. So you could do something like:

var winston = require('winston');

winston.use('loggly', {
  // your loggly config goes here
});

Cheers,
Charlie

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Wes Williams

unread,
Aug 25, 2011, 12:49:04 PM8/25/11
to nod...@googlegroups.com
Charlie,

First, thanks for the response.

When I have two of my own modules that both require loggly and create a client with something like the following: 

loggerClient = require('loggly').createClient({ subdomain: 'mydomain' });

What happens?  Do I have two connections open? Is a connection created with each log requests? Basically, what do I need to think about from a scalability perspective?

Thanks,
Wes
--
Regards,
Wes Williams

wes.wi...@gmail.com
twitter: weswilliamz
linked in: http://www.linkedin.com/in/weswilliamz
blog: weswilliamz.blogspot.com

Joseph Moniz

unread,
Aug 25, 2011, 9:49:25 PM8/25/11
to nod...@googlegroups.com
Wes,

Seeing how they are custom modules you can just write them so that
methods within them take a loggly connection/client as a parameter.

This example on passing an express server to a module should get you
going in the right direction.
https://github.com/visionmedia/express/tree/master/examples/mvc

Some people call it dependency injection, i call it clean code.

- Joseph Moniz

Wes Williams

unread,
Aug 25, 2011, 10:58:03 PM8/25/11
to nod...@googlegroups.com

Thanks, I can do that.

dennis zhuang

unread,
Aug 26, 2011, 9:52:10 AM8/26/11
to nod...@googlegroups.com

Charlie Robbins

unread,
Aug 26, 2011, 1:08:49 PM8/26/11
to nod...@googlegroups.com
Wes,

Yes, in the code sample you have provided you will have two instances of a loggerClient. This is why winston introduced the "default logger" concept.

module1.js

var winston = require('winston');
winston.use('loggly', { /* your loggly config */ });

winston.info('something');

module2.js

var winston = require('winston');
winston.info('something-else');

In this case both instances of `winston` in module1.js and module2.js are the same Object. I would recommend bootstrapping your logger in a top-level include as is done in the example Joesph supplied: https://github.com/visionmedia/express/blob/master/examples/mvc/mvc.js ... although this example doesn't use winston you get the idea.

--Charlie

Wes Williams

unread,
Aug 26, 2011, 1:45:53 PM8/26/11
to nod...@googlegroups.com
Excellent, I will make the move to winston. Thanks for the info.

wes
Reply all
Reply to author
Forward
0 new messages