A node.js module that brings common sense to console logging.
npm install secretary
The potential configuration options are as follows:
var sec = ;
One of the key features of secretary is the ability to
litter your code with thoughtfully place console logging throughout your code,
and have it filtered out at runtime by the flag that was supplied with the output. This way, you're always in control of the verbosity of your output,
during development and during production. It also does away with the need for quick-and-dirty console.logs that you delete shortly afterwards.
We implement flags by chaining
flag() in front of any log call, and passing it the flag level we want to set.
If we assume the following configuration:
minFlag: 1maxFlag: 5minRunningFlag: 3
And then run the following code:
We will see the following output:
Integrity check successfulServer starting on port 3000
By it's nature,
flag() sets what the flag level is for the next
log() call. Thus, the following is valid usage:
sec;sec; // Evaluated with flag level 4
It is also possible to use
log() without any chain to
flag() which results in the minimum running flag to be applied to the log, meaning it will always be displayed no matter what.
console.log(), secretary supports the formatting of data.
log() can take multiple arguments in a
printf() sort of way.
The first argument passed to
log() is always assumed and expected to be the desired output string. If other arguments are included, they are all assumed to be data that need to be formatted into the string. String formatting is done by the
util.format() method, so all rules that apply there apply here.
The basic supported placeholders are listed below:
For the entire range of
util.format() rules, see here.
Examples of this in use:
sec;// 'Hello, Mister.'
sec;// 'Hello 1 2 3'