Skip to content

Commit cbd4446

Browse files
authored
Merge pull request #74 from runk/fix-logger
Fix logger
2 parents f3549e1 + 46714e9 commit cbd4446

File tree

7 files changed

+363
-1356
lines changed

7 files changed

+363
-1356
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
cache/*
3+
*.log

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
language: node_js
22
node_js:
3-
- "4.8"
43
- "6.9"
54
- "8.4"
65
- "10"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ npm --proxy http://npm-proxy-cache:8080 --https-proxy http://npm-proxy-cache:808
102102

103103
## Limitations
104104

105-
- Works only with node `4.9.1` and above.
105+
- Works only with node `6` and above.
106106

107107

108108
----

lib/logger.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
const log4js = require('log4js');
3+
4+
module.exports = function(opts) {
5+
const appenders = { stdout: { type: 'stdout' } };
6+
if (opts.logPath) {
7+
appenders.file = { type: 'file', filename: opts.logPath };
8+
}
9+
10+
const categories = {
11+
default: {
12+
appenders: Object.keys(appenders),
13+
level: opts.verbose ? 'debug' : 'info'
14+
}
15+
};
16+
17+
log4js.configure({ appenders, categories });
18+
return log4js.getLogger();
19+
};

lib/proxy.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const os = require('os');
77
const url = require('url');
88
const path = require('path');
99
const request = require('request');
10-
const log4js = require('log4js');
1110
const Cache = require('./cache');
11+
const getLogger = require('./logger');
1212

1313

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

42-
if (opts.logPath) {
43-
log4js.configure({
44-
appenders: { 'proxy': { type: 'file', filename: opts.logPath } },
45-
categories: { default: { appenders: ['proxy'], level: opts.verbose ? 'debug' : 'info' }}
46-
});
47-
}
48-
49-
this.log = log4js.getLogger('proxy');
42+
43+
this.log = getLogger(opts);
5044

5145
// Fake https server aka MITM
5246
const mitm = https.createServer(options, exports.httpHandler);

0 commit comments

Comments
 (0)