Merge pull request #50 from GermanBluefox/master

Allow custom log function. Not only console
This commit is contained in:
AJ ONeal 2016-08-26 08:21:54 -06:00 committed by GitHub
commit 7b6360c9b0
4 changed files with 21 additions and 18 deletions

View File

@ -128,6 +128,7 @@ le = LE.create({
, agreeToTerms: leAgree // hook to allow user to view and accept LE TOS , agreeToTerms: leAgree // hook to allow user to view and accept LE TOS
//, sni: require('le-sni-auto').create({}) // handles sni callback //, sni: require('le-sni-auto').create({}) // handles sni callback
, debug: false , debug: false
//, log: function (debug) {console.log.apply(console, args);} // handles debug outputs
}); });

View File

@ -9,6 +9,15 @@ LE.LE = LE;
// in-process cache, shared between all instances // in-process cache, shared between all instances
var ipc = {}; 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 = { LE.defaults = {
productionServerUrl: ACME.productionServerUrl productionServerUrl: ACME.productionServerUrl
, stagingServerUrl: ACME.stagingServerUrl , stagingServerUrl: ACME.stagingServerUrl
@ -64,6 +73,7 @@ LE.create = function (le) {
le.acme = le.acme || ACME.create({ debug: le.debug }); le.acme = le.acme || ACME.create({ debug: le.debug });
le.store = le.store || require('le-store-certbot').create({ debug: le.debug }); le.store = le.store || require('le-store-certbot').create({ debug: le.debug });
le.core = require('./lib/core'); le.core = require('./lib/core');
var log = le.log || _log;
if (!le.challenges) { if (!le.challenges) {
le.challenges = {}; le.challenges = {};
@ -187,25 +197,19 @@ LE.create = function (le) {
lexOpts.agreeTos = le.agreeTos; lexOpts.agreeTos = le.agreeTos;
return cb(null, { options: lexOpts, certs: certs }); return cb(null, { options: lexOpts, certs: certs });
} }
if (le.debug) { log(le.debug, 'unapproved domain', lexOpts.domains, le.approvedDomains);
console.log('unapproved domain', lexOpts.domains, le.approvedDomains);
}
cb(new Error("unapproved domain")); cb(new Error("unapproved domain"));
}; };
} }
le.getCertificates = function (domain, certs, cb) { le.getCertificates = function (domain, certs, cb) {
// certs come from current in-memory cache, not lookup // certs come from current in-memory cache, not lookup
if (le.debug) { log(le.debug, 'le.getCertificates called for', domain, 'with certs for', certs && certs.altnames || 'NONE');
console.log('le.getCertificates called for', domain, 'with certs for', certs && certs.altnames || 'NONE');
}
var opts = { domain: domain, domains: certs && certs.altnames || [ domain ] }; var opts = { domain: domain, domains: certs && certs.altnames || [ domain ] };
le.approveDomains(opts, certs, function (_err, results) { le.approveDomains(opts, certs, function (_err, results) {
if (le.debug) { log(le.debug, 'le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:');
console.log('le.approveDomains called with certs for', results.certs && results.certs.altnames || 'NONE', 'and options:'); log(le.debug, results.options);
console.log(results.options);
}
if (_err) { if (_err) {
cb(_err); cb(_err);
return; return;
@ -214,15 +218,11 @@ LE.create = function (le) {
var promise; var promise;
if (results.certs) { if (results.certs) {
if (le.debug) { log(le.debug, 'le renewing');
console.log('le renewing');
}
promise = le.core.certificates.renewAsync(results.options, results.certs); promise = le.core.certificates.renewAsync(results.options, results.certs);
} }
else { else {
if (le.debug) { log(le.debug, 'le getting from disk or registering new');
console.log('le getting from disk or registering new');
}
promise = le.core.certificates.getAsync(results.options); promise = le.core.certificates.getAsync(results.options);
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
function log(debug) { function _log(debug) {
if (debug) { if (debug) {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
args.shift(); args.shift();
@ -13,6 +13,7 @@ module.exports.create = function (le) {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var utils = require('./utils'); var utils = require('./utils');
var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA); var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA);
var log = le.log || _log; // allow custom log
var core = { var core = {
// //

View File

@ -2,7 +2,7 @@
var utils = require('./utils'); var utils = require('./utils');
function log(debug) { function _log(debug) {
if (debug) { if (debug) {
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
args.shift(); args.shift();
@ -15,6 +15,7 @@ module.exports.create = function (le) {
if (!le.challenge || !le.challenge.get) { if (!le.challenge || !le.challenge.get) {
throw new Error("middleware requires challenge plugin with get method"); throw new Error("middleware requires challenge plugin with get method");
} }
var log = le.log || _log;
log(le.debug, "created middleware"); log(le.debug, "created middleware");
return function (_app) { return function (_app) {