what i do:
*console.js:*
export = myCustomLoggerSolution
*someOtherModule.js*
var logger = require(./console.js)
if your app/lib is more complex then the next thing you can do is
- to inject the logger to every module on init, which could by overly
verbose or require a DI solution
- to package and install your logger as dependency, configure it on
startup and require it as 3rdparty dep
of course you could use global in your app, as long as you can make sure
there are no conflicts. not a good way for a lib though.
In fact your monkey patching of the console object is already a messing
with globals, and you dont have to inject it again in using modules.
Am Dienstag, 21. Januar 2014 22:33:38 UTC+1 schrieb Kevin Ingwersen:
>
> Hello there.
>
> I am currently thinking about implementing npmlog into one of my
> applications. It looks smooth and very nice. However, I would like to do
> that for console.log too. Like:
>
> console__log=console.log;
> console.log=function(msg) {
> require(„npmlog“).info(null, msg);
> }
>
> … or, kinda like that. But - what I really ment is, if I had this
> customized console object, how would I expose it to a node module? The
> current way I would think is:
>
> var m = require(„module_xyz“);
> m.console=console;
> // and from within the module:
> m.console.log(…);
>
> … Is there a cleaner way to do that? Do GLOBALS make something different
> here?
>
> Kind regards, Ingwie
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.