-
Notifications
You must be signed in to change notification settings - Fork 156
repaired the ability of nano to be able to output DEBUG messages #286
base: master
Are you sure you want to change the base?
Conversation
…er sets the DEBUG environment variable
module.exports = function logging() { | ||
return function log() { | ||
var eventId = prefix + (~~(Math.random() * 1e9)).toString(36); | ||
debug.call(this, eventId, [].slice.call(arguments, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the pull request. however i'm confused by this.
the log function is normally used to log, and during development can be overridden by debug. seems like this just makes it be a debug message all the time no?
The code that allows a user defined function to be supplied is here: This remains in place. The problem was that this code was also repeated in logger.js. If no overriding log function was provided, then no logging actually happened! The modified test reflects the behaviour that logger module should return a function. Sorry if this wasn't clear in the PR. |
Hi, @dscape. I think the key point here, with which we can all agree, is that this API is not specified concretely nor tested against. AFAICT, the test suite does not test logging at all. (Yes, it hooks the debug package into the logging, but it does not actually test or confirm things.) So, I propose we create a new PR which tests the logger API (in effect defining it concretely), and then after that, we can continue this conversation? |
👍 |
I think the confusion is this: if you look at logger.js, it exports a function which returns a function which returns a function. (That is not an composition error. A function returns a function which returns a third function.) In other words, by looking at this code, one would expect to see it used like so: var loggingSystem = require("./logger.js");
function actuallyLog(eventId, args) {
console.log(eventId + " " + JSON.stringify(args)); // Simple example.
}
var logConfig = {"log": actuallyLog};
var loggerFactory = loggingSystem(logConfig);
// Suppose we have two concerns ("prefixes"): a generic logger plus one about, uh, bats.
var genLogger = loggerFactory();
var batLogger = loggerFactory("bats");
genLogger("Begin!");
genLogger("Something happened", {count:3});
batLogger("Strike!", {type:"aluminum"});
batLogger("Home run!", {type:"wood"});
batLogger("Found a mosquito", [0.3, 0.2, 0.1], {method:"echolocation"});
genLogger("Finished"); Output:
In other words, we would expect three function calls deep, through the metafunctions, to actually log events. If you look at the code in nano.js: https://github.com/dscape/nano/blob/v6.1.4/lib/nano.js#L45 var log = typeof cfg.log === 'function' ? cfg.log : logger(cfg); Here I am confused. The logging module will check var log = cfg && cfg.log;
var logStrategy = typeof log === 'function' ? log : debug; But the code in My next confusion is, that the function If that is the case, then if somebody provides their own Perhaps I have totally overthought myself into misunderstanding. It wouldn't be the first time. But if not, maybe you can agree that perhaps it is time that we nail down the logging API. If anybody has any feedback at all, then I would be grateful and I will happily write up some unit tests to codify that. Thank you very much! |
Change `cloudant.use` to `nano.use`.
There were a few places where this file was out of date. Express 4: * express.createServer() has been deprecated * passing the status via send() has been deprecated * convention is to use 'req' and 'res' instead of 'request' and 'response' Nano 6: * error['status-code'] is now error.statusCode Also there was a syntax error (too many curly braces).
The improvements: * Node 0.12 is no longer supported * Only JSON encode parameters which are not strings to avoid double encoding as per cloudant/nodejs-cloudant#89 * Update package.json for this repo's project name * Added GET /_uuids api call * Added selective encoding of string parameters to the search function
Starting with 1.2.0 CouchDB added a new system database called "_replicator" to handle replications jobs. Replications are now created as entries on that database and the server will schedule and perform the replication accordingly. Entries in the "_replicator" db will be updated. This means that replication now is a completely asynchronous job that is not guaranteed to run right after the replication was started. This commit adds three new object with three object to handle this new type of replication: - replication.enable: To enable the replication of a database. - replication.query: To query the status of a replication job. - replication.disable: To disable the replication of a database. More information on this type of replication can be found: - https://wiki.apache.org/couchdb/Replication#from_1.2.0_onward - http://guide.couchdb.org/draft/replication.html - https://gist.github.com/fdmanana/832610 [Addendum after merging with the new repo] Fixing tests for uuids, since they were not passing.
Hi, |
I noticed that when I ran my application with
I wasn't seeing any debug output from Nano. I had a look at the code and there seemed to be some confusion about when Nano uses the
debug
package and where in the code a customlog
function can be provided.I have refactored the logger.js code so that it represents the default
debug
package function. The code that optionally switches in a custom, user-supplied log function was already handled in nano.js but there seemed to be some of this code leftover in logger.js, which caused no debug messages to ever work (unless you provided your own function).With this PR, the debug messages now work with
I've also added a paragraph in README.md to explain this to users.