Skip to content

Commit

Permalink
Merge pull request #74 from runk/fix-logger
Browse files Browse the repository at this point in the history
Fix logger
runk authored Oct 23, 2018
2 parents f3549e1 + 46714e9 commit cbd4446
Showing 7 changed files with 363 additions and 1,356 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
cache/*
*.log
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- "4.8"
- "6.9"
- "8.4"
- "10"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ npm --proxy http://npm-proxy-cache:8080 --https-proxy http://npm-proxy-cache:808

## Limitations

- Works only with node `4.9.1` and above.
- Works only with node `6` and above.


----
19 changes: 19 additions & 0 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';
const log4js = require('log4js');

module.exports = function(opts) {
const appenders = { stdout: { type: 'stdout' } };
if (opts.logPath) {
appenders.file = { type: 'file', filename: opts.logPath };
}

const categories = {
default: {
appenders: Object.keys(appenders),
level: opts.verbose ? 'debug' : 'info'
}
};

log4js.configure({ appenders, categories });
return log4js.getLogger();
};
12 changes: 3 additions & 9 deletions lib/proxy.js
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ const os = require('os');
const url = require('url');
const path = require('path');
const request = require('request');
const log4js = require('log4js');
const Cache = require('./cache');
const getLogger = require('./logger');


// To avoid 'DEPTH_ZERO_SELF_SIGNED_CERT' error on some setups
@@ -39,14 +39,8 @@ exports.powerup = function(opts) {
path: opts.storage, ttl: opts.ttl, friendlyNames: opts.friendlyNames
});

if (opts.logPath) {
log4js.configure({
appenders: { 'proxy': { type: 'file', filename: opts.logPath } },
categories: { default: { appenders: ['proxy'], level: opts.verbose ? 'debug' : 'info' }}
});
}

this.log = log4js.getLogger('proxy');

this.log = getLogger(opts);

// Fake https server aka MITM
const mitm = https.createServer(options, exports.httpHandler);
1,680 changes: 337 additions & 1,343 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
},
"dependencies": {
"commander": "^2.17.1",
"log4js": "^2.11.0",
"log4js": "^3.0.6",
"mkdirp": "^0.5.1",
"mv": "^2.1.1",
"request": "^2.88.0"
@@ -49,6 +49,6 @@
"url": "https://github.com/runk/npm-proxy-cache/issues"
},
"engines": {
"node": ">=0.10"
"node": ">=6"
}
}

0 comments on commit cbd4446

Please sign in to comment.