From b3bb80a4805e38aef99784026c1e4d053a757f5f Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 25 Aug 2016 22:02:57 +0200 Subject: [PATCH 1/4] Allow custom log function. Not only console --- lib/core.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/core.js b/lib/core.js index 9d45511..3fe2133 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,6 +1,6 @@ 'use strict'; -function log(debug) { +function _log(debug) { if (debug) { var args = Array.prototype.slice.call(arguments); args.shift(); @@ -13,6 +13,7 @@ module.exports.create = function (le) { var PromiseA = require('bluebird'); var utils = require('./utils'); var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); + var log = le.log || _log; // allow custom log var core = { // From 7c62f1fd3ebbfdc6529a015e71a4456e8b4588ce Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 25 Aug 2016 22:04:36 +0200 Subject: [PATCH 2/4] Allow custom log function. Not only console --- lib/middleware.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/middleware.js b/lib/middleware.js index c9fff9c..b8a3cd1 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -2,7 +2,7 @@ var utils = require('./utils'); -function log(debug) { +function _log(debug) { if (debug) { var args = Array.prototype.slice.call(arguments); args.shift(); @@ -15,6 +15,7 @@ module.exports.create = function (le) { if (!le.challenge || !le.challenge.get) { throw new Error("middleware requires challenge plugin with get method"); } + var log = le.log || _log; log(le.debug, "created middleware"); return function (_app) { From 88f5bcc58cbcaba9283da1561f3046fc058a7aba Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 25 Aug 2016 22:09:23 +0200 Subject: [PATCH 3/4] Allow custom log function. Not only console --- index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index dd6f0ec..b50c9fb 100644 --- a/index.js +++ b/index.js @@ -9,6 +9,15 @@ LE.LE = LE; // in-process cache, shared between all instances var ipc = {}; +function _log(debug) { + if (debug) { + var args = Array.prototype.slice.call(arguments); + args.shift(); + args.unshift("[le/index.js]"); + console.log.apply(console, args); + } +} + LE.defaults = { productionServerUrl: ACME.productionServerUrl , stagingServerUrl: ACME.stagingServerUrl @@ -64,6 +73,7 @@ LE.create = function (le) { le.acme = le.acme || ACME.create({ debug: le.debug }); le.store = le.store || require('le-store-certbot').create({ debug: le.debug }); le.core = require('./lib/core'); + var log = le.log || _log; if (!le.challenges) { le.challenges = {}; @@ -187,25 +197,19 @@ LE.create = function (le) { lexOpts.agreeTos = le.agreeTos; return cb(null, { options: lexOpts, certs: certs }); } - if (le.debug) { - console.log('unapproved domain', lexOpts.domains, le.approvedDomains); - } + log(le.debug, 'unapproved domain', lexOpts.domains, le.approvedDomains); cb(new Error("unapproved domain")); }; } le.getCertificates = function (domain, certs, cb) { // certs come from current in-memory cache, not lookup - if (le.debug) { - console.log('le.getCertificates called for', domain, 'with certs for', certs && certs.altnames || 'NONE'); - } + log(le.debug, 'le.getCertificates called for', domain, 'with certs for', certs && certs.altnames || 'NONE'); var opts = { domain: domain, domains: certs && certs.altnames || [ domain ] }; le.approveDomains(opts, certs, function (_err, results) { - if (le.debug) { - console.log('le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:'); - console.log(results.options); - } + log(le.debug, 'le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:'); + log(le.debug, results.options); if (_err) { cb(_err); return; @@ -214,15 +218,11 @@ LE.create = function (le) { var promise; if (results.certs) { - if (le.debug) { - console.log('le renewing'); - } + log(le.debug, 'le renewing'); promise = le.core.certificates.renewAsync(results.options, results.certs); } else { - if (le.debug) { - console.log('le getting from disk or registering new'); - } + log(le.debug, 'le getting from disk or registering new'); promise = le.core.certificates.getAsync(results.options); } From beb4fa1b99219e1459282c5ef5be0e00312544c6 Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Thu, 25 Aug 2016 22:14:16 +0200 Subject: [PATCH 4/4] Extend description with log argument. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 196e1a6..f0bcefd 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ le = LE.create({ , agreeToTerms: leAgree // hook to allow user to view and accept LE TOS //, sni: require('le-sni-auto').create({}) // handles sni callback , debug: false +//, log: function (debug) {console.log.apply(console, args);} // handles debug outputs });