diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-23 18:21:03 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-23 18:21:03 +0100 |
commit | 1fdd8a761158517647633c488fa69950e0a8b443 (patch) | |
tree | c44a8dcc77e0b713a44530ca6c51f42ffde8e0aa /lib/book.js | |
parent | 112782d11837428c260211bb3afeb3263e479593 (diff) | |
download | gitbook-1fdd8a761158517647633c488fa69950e0a8b443.zip gitbook-1fdd8a761158517647633c488fa69950e0a8b443.tar.gz gitbook-1fdd8a761158517647633c488fa69950e0a8b443.tar.bz2 |
Improve logs in book parser
Diffstat (limited to 'lib/book.js')
-rw-r--r-- | lib/book.js | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/lib/book.js b/lib/book.js index 4c1c33f..cc48a03 100644 --- a/lib/book.js +++ b/lib/book.js @@ -152,6 +152,7 @@ Book.prototype.generate = function(generator) { var that = this; that.options.generator = generator || that.options.generator; + that.logInfo("start generation with", that.options.generator, "generator"); return Q() // Clean output folder @@ -210,6 +211,9 @@ Book.prototype.generate = function(generator) { }) .then(function() { return generator.callHook("finish"); + }) + .then(function() { + that.logInfo("generation is finished"); }); }; @@ -243,6 +247,7 @@ Book.prototype.parsePlugins = function() { return plugin; }); + that.logDebug("load plugins:", that.plugins.length, "loaded, ", failed.length, "failed"); if (_.size(failed) > 0) return Q.reject(new Error("Error loading plugins: "+failed.join(",")+". Run 'gitbook install' to install plugins from NPM.")); return Q(); }; @@ -250,14 +255,18 @@ Book.prototype.parsePlugins = function() { // Parse readme to extract defaults title and description Book.prototype.parseReadme = function() { var that = this; + var structure = that.config.getStructure("readme"); + that.logDebug("start parsing readme:", structure); - return that.findFile(that.config.getStructure("readme")) + return that.findFile(structure) .then(function(readme) { if (!readme) throw "No README file"; if (!_.contains(that.files, readme.path)) throw "README file is ignored"; that.readmeFile = readme.path; - return that.template.renderFile(readme.path) + + that.logDebug("readme located at", that.readmeFile); + return that.template.renderFile(that.readmeFile) .then(function(content) { return readme.parser.readme(content); }); @@ -273,10 +282,14 @@ Book.prototype.parseReadme = function() { Book.prototype.parseLangs = function() { var that = this; - return that.findFile(that.config.getStructure("langs")) + var structure = that.config.getStructure("langs"); + that.logDebug("start parsing languages index:", structure); + + return that.findFile(structure) .then(function(langs) { if (!langs) return []; + that.logDebug("languages index located at", langs.path); return that.template.renderFile(langs.path) .then(function(content) { return langs.parser.langs(content); @@ -291,19 +304,20 @@ Book.prototype.parseLangs = function() { Book.prototype.parseSummary = function() { var that = this; - return Q.all([ - that.findFile(that.config.getStructure("summary")), - that.findFile(that.config.getStructure("readme")) - ]) - .spread(function(summary, readme) { + var structure = that.config.getStructure("summary"); + that.logDebug("start parsing summary:", structure); + + return that.findFile(structure) + .then(function(summary) { if (!summary) throw "No SUMMARY file"; // Remove the summary from the list of files to parse that.files = _.without(that.files, summary.path); + that.logDebug("summary located at", summary.path); return that.template.renderFile(summary.path) .then(function(content) { - return summary.parser.summary(content, readme.path); + return summary.parser.summary(content, that.readmeFile); }); }) .then(function(summary) { @@ -316,13 +330,17 @@ Book.prototype.parseSummary = function() { Book.prototype.parseGlossary = function() { var that = this; - return that.findFile(that.config.getStructure("glossary")) + var structure = that.config.getStructure("glossary"); + that.logDebug("start parsing glossary: ", structure); + + return that.findFile(structure) .then(function(glossary) { if (!glossary) return []; // Remove the glossary from the list of files to parse that.files = _.without(that.files, glossary.path); + that.logDebug("glossary located at", glossary.path); return that.template.renderFile(glossary.path) .then(function(content) { return glossary.parser.glossary(content); @@ -337,13 +355,17 @@ Book.prototype.parseGlossary = function() { Book.prototype.parsePage = function(filename) { var that = this; + that.logDebug("start parsing file", filename); + var extension = path.extname(filename); var filetype = parsers.get(extension); if (!filetype) return Q.reject(new Error("Can't parse file: "+filename)); + that.logDebug("render template", filename); return that.template.renderFile(filename) .then(function(content) { + that.logDebug("use file parser", filetype.name, "for", filename); return filetype.parser.page(content); }) .then(function(page) { @@ -458,6 +480,7 @@ Book.prototype.indexPage = function(page) { var nav = this.navigation[page.path]; if (!nav) return; + this.logDebug("index page", page.path); this.searchIndex.add({ url: this.contentLink(page.path), title: nav.title, @@ -470,7 +493,7 @@ Book.prototype.log = function(level) { if (level < this.context.logLevel) return; var args = Array.prototype.slice.apply(arguments); - args[0] = _.findKey(Book.LOG_LEVELS)+":"; + args[0] = _.findKey(Book.LOG_LEVELS).toLowerCase()+":"; this.context.log.apply(null, args); }; Book.prototype.logDebug = _.partial(Book.prototype.log, Book.LOG_LEVELS.DEBUG); |