wraps functions, constructors and util object style collections of functions in entrance and exit logs using a logger provided by the consumer
This is a small module for adding logging to things without cluttering function definitions with log statements. It is my firm belief that logging and logic should not be mixed, and that separating them will improve readability.
Note: loggify is not a logging module, it is just a module for adding logging to functions, assuming you already have some kind of logger. You could be using Minilog, plain old console or something else, loggify does not care.
// init loggifyvar loggify = require'loggify'logger; // some obj, hopefully with an 'info'function
You can loggify a single function, a collection of functions which are keys on
an object, or even a constructor along with functions on the prototype. The name
and level parameters are optional. The name will default to
objectOrFunction.name if it exists or just an empty string. The level defaults
info, this needs to be a valid member function on the
logger object you
initially passed to
varreturn a + b;mySuperFunc = loggifymySuperFunc 'mySuperFunc' 'warn';mySuperFunc13; // logs function entry + arguments// also logs function exit + return valvar bagOFunctions =return a+b;return a*b;;bagOFunctions = loggifybagOFunctions 'stuff';// overwrites add and multiply with loggified versions// defaults to 'info' log level// will log 'stuff.add', because that's the name suppliedvarthisx = x; thisy = y;;thisx = thisx + distance;return thisx thisy;;Car = loggifyCar 'Car';// loggify the constructor and prototype functions