Stack Logger
Easily build up a log trail while writing modules.
Usage Notes
// There are 4 StackLogger types, corresponding to console methodsStackLoggerErrorStackLoggerWarnStackLoggerInfoStackLoggerLog // These are aliases of the generic StackLoggerStackLogger// is the same as // A StackLogger can be initialized with its topmost messagevar _error = StackLogger // StackLogger combines stacked messages with '\n\t'_error // equiv.: console.error('My Error Generating Class has an Error:\n\tBad input.') // StackLogger is meant to be used to build up a trail of information while writing modules// This helps narrow down where errors are coming from, especially in certain contexts (like async// callbacks) where stack traces aren't always that helpful { // StackLogger.push and StackLogger.pop are immutable updates, so _error is unaltered. var _methodError = _error; // some time later... _methodError; // console error output: // 'My Error Generating Class has an Error:' // ' Method: [MyErrorGeneratingClass::method]' // ' That\'s no good. Stop that.' _error // console error output: // 'My Error Generating Class has an Error:' // ' I am still here.' // Let's try using StackLogger in some async code. We'll need this function: { return { logger } } // Now let's send a GET request from the method we're currently in: $ // Now if the GET request fails, our console error will tell use that we were in this method} // StackLogger also has #pop()var _error = _methodError; // => StackLogger _error // console error output: 'My Error Generating Class has an Error:\n\tHello!' _error = _error // => StackLogger _error // consoler error output: 'Hello!'