From e622918feeac7c7127b3e8b8baac342dd9ac2705 Mon Sep 17 00:00:00 2001 From: devlinjd Date: Tue, 29 Sep 2015 04:15:04 -0400 Subject: [PATCH] Add external logger callback. --- src/fluentcmd.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/fluentcmd.js b/src/fluentcmd.js index 93c94a8..c25fee4 100644 --- a/src/fluentcmd.js +++ b/src/fluentcmd.js @@ -16,7 +16,7 @@ module.exports = function () { , unused = require('./utils/string') , FLUENT = require('fluentlib'); - var rez; + var rez, _log; /** Core resume generation method for HMR. Given a source JSON resume file, a @@ -27,8 +27,9 @@ module.exports = function () { @param dst Path to the destination resume file(s): "rez/resume.all". @param theme Friendly name of the resume theme. Defaults to "default". */ - function hmr( src, dst, theme ) { + function hmr( src, dst, theme, logger ) { + _log = logger || console.log; _opts.theme = theme; dst = (dst && dst.length && dst) || ['resume.all']; @@ -46,7 +47,7 @@ module.exports = function () { // Assemble input resumes var sheets = src.map( function( res ) { - console.log( 'Reading JSON resume: ' + res ); + _log( 'Reading JSON resume: ' + res ); return (new FLUENT.Sheet()).open( res ); }); @@ -83,7 +84,7 @@ module.exports = function () { var fOut = path.join( f.substring( 0, f.lastIndexOf('.') + 1 ) + fObj.ext ); // Generate! - console.log( 'Generating ' + fType.toUpperCase() + ' resume: ' + fOut ); + _log( 'Generating ' + fType.toUpperCase() + ' resume: ' + fOut ); return fObj.gen.generate( rez, fOut, _opts.theme ); } catch( ex ) { @@ -98,7 +99,7 @@ module.exports = function () { var msg = ex.toString(); var idx = msg.indexOf('Error: '); var trimmed = idx === -1 ? msg : msg.substring( idx + 7 ); - console.error( 'ERROR: ' + trimmed.toString() ); + _log( 'ERROR: ' + trimmed.toString() ); } /**