-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andreas Schleifer
committed
Jul 4, 2014
0 parents
commit 828f05c
Showing
7 changed files
with
490 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/.idea | ||
/data | ||
/logs | ||
/tmp | ||
|
||
config.js | ||
|
||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
var fs = require('fs'); | ||
|
||
function Logger(config) { | ||
"use strict"; | ||
|
||
this._level_error = 0; | ||
this._level_warning = 1; | ||
this._level_notice = 2; | ||
this._level_debug = 3; | ||
|
||
this._file = null; | ||
|
||
this._level = config.level; | ||
this._debugKeys = config.debugKeys; | ||
this._console = config.console; | ||
|
||
if (null !== config.file) { | ||
this._file = fs.createWriteStream(config.file, { | ||
flags: 'a+' | ||
}); | ||
this._file.on('error', function (err) { | ||
console.log('Error on open log file: ', err.message); | ||
}); | ||
} | ||
} | ||
|
||
Logger.prototype.destroy = function () { | ||
"use strict"; | ||
|
||
if (null !== this._file) { | ||
this._file.end(); | ||
} | ||
}; | ||
|
||
Logger.prototype.error = function (msg) { | ||
"use strict"; | ||
|
||
if (this._level < this._level_error) { | ||
return; | ||
} | ||
|
||
this._logConsole('ERROR: ' + msg); | ||
this._logFile('ERROR: ' + msg); | ||
}; | ||
|
||
Logger.prototype.warning = function (msg) { | ||
"use strict"; | ||
|
||
if (this._level < this._level_warning) { | ||
return; | ||
} | ||
|
||
this._logConsole('WARNING: ' + msg); | ||
this._logFile('WARNING: ' + msg); | ||
}; | ||
|
||
Logger.prototype.notice = function (msg) { | ||
"use strict"; | ||
|
||
if (this._level < this._level_notice) { | ||
return; | ||
} | ||
|
||
this._logConsole('NOTICE: ' + msg); | ||
this._logFile('NOTICE: ' + msg); | ||
}; | ||
|
||
Logger.prototype.debug = function (key, msg) { | ||
"use strict"; | ||
|
||
if (this._level < this._level_debug) { | ||
return; | ||
} | ||
|
||
if (0 !== this._debugKeys.length | ||
&& -1 === this._debugKeys.indexOf(key) | ||
) { | ||
return; | ||
} | ||
|
||
this._logConsole('DEBUG (' + key + '): ' + msg); | ||
this._logFile('DEBUG (' + key + '): ' + msg); | ||
}; | ||
|
||
Logger.prototype._logConsole = function (msg) { | ||
"use strict"; | ||
|
||
if (true === this._console) { | ||
console.log(msg); | ||
} | ||
}; | ||
|
||
Logger.prototype._logFile = function (msg) { | ||
"use strict"; | ||
|
||
if (null !== this._file) { | ||
this._file.write(msg + "\n", 'utf-8'); | ||
} | ||
}; | ||
|
||
module.exports = Logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# HTTP Proxy | ||
|
||
## Setup | ||
|
||
`npm install` | ||
|
||
Copy `config.js.default` to `config.js` and modify to the desired values | ||
|
||
## Run | ||
|
||
`node http-proxy.js` | ||
|
||
## Configure | ||
|
||
module.exports = { | ||
ip: 'proxy.example.com', // this is what the | ||
port: 80, // proxy will listen to | ||
|
||
sourceServer: 'somehost.com', // this is what the proxy | ||
sourcePort: 80, // will read from | ||
|
||
sourceTimeout: 2000, // timeout for requests | ||
// to source (ms) | ||
|
||
log: { // logging: | ||
|
||
file: './http-proxy.log', // set to null to not use | ||
// file logging | ||
|
||
console: true, // set to false to not | ||
// log to stdout | ||
|
||
level: 0, // 0: error, 1: warnings | ||
// 2: notices, 3: debug | ||
|
||
debugKeys: [ // Empty Array: log all debug | ||
|
||
'Request', // Special keys to be debugged | ||
'CacheSize', // ^^ | ||
'GarbageCollection' // ^^ | ||
] | ||
}, | ||
cacheSize: 100, // Number of resources | ||
// to be cached before | ||
// evictions will occure | ||
|
||
garbageCollectionInterval: 1000 // intervall with that the | ||
// garbage collection will evict | ||
// entries | ||
}; |
Oops, something went wrong.