I suggest not including Winston at all. Winston is very popular and contains many nice features that your users may not use, and I believe that your module should be small enough so that the user always uses all its functions. If there is a case where they do not want to use the built-in recorder, well, I think it is not small enough. With that said, a module that records material when necessary for debugging is useful.
If you want the developer to use your module to debug your module using logs, I suggest you turn on debugging mode, which you can turn on / off.
You can use something like this to help you: https://www.npmjs.org/package/debug
And if the user wants to integrate his own logging system, I suggest that you can pass on the logging function to your module. Something like this (let me name your rock-the-sock module:
var rockTheSock = require('rock-the-sock'); var rockTheSock.logger = function (level, message, metadata) { console.log('level :', level, message, metadata);
And then in your module you will have a default registrar that can be overridden as shown above.
socket.io is a good example of how this is done (although you really don't need the configure method, which is just twists):
Here you can override the default registrar socket.io: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO
Where as a registrar is implemented as follows: https://github.com/LearnBoost/Socket.IO/blob/0.9.14/lib/logger.js
And if something ever goes wrong, try throwing an error or throwing an error event or call the error callback (no matter what is applicable). Silently registering it is not a good idea. If you report this, then let the user code process it. Perhaps the error was expected (you have no idea what crazy ways your modules use!).
Farid Nouri Neshat Apr 04 '14 at 16:20 2014-04-04 16:20
source share