Use Logger for repeater and don't scream if debug is off

This commit is contained in:
Yarek T 2013-02-08 23:26:11 +00:00
Родитель d374de667d
Коммит 54086c61c2
1 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -1,6 +1,8 @@
var util = require('util'),
dgram = require('dgram');
dgram = require('dgram'),
logger = require('../lib/logger');
var l;
var debug;
function RepeaterBackend(startupTime, config, emitter){
var self = this;
this.config = config.repeater || [];
@ -9,7 +11,9 @@ function RepeaterBackend(startupTime, config, emitter){
dgram.createSocket('udp4');
// Attach DNS error handler
this.sock.on('error', function (err) {
console.log('Repeater error: ' + err);
if (debug) {
l.log('Repeater error: ' + err);
}
});
// attach
emitter.on('packet', function(packet, rinfo) { self.process(packet, rinfo); });
@ -21,8 +25,8 @@ RepeaterBackend.prototype.process = function(packet, rinfo) {
for(var i=0; i<hosts.length; i++) {
self.sock.send(packet,0,packet.length,hosts[i].port,hosts[i].host,
function(err,bytes) {
if (err) {
console.log(err);
if (err && debug) {
l.log(err);
}
});
}
@ -30,5 +34,7 @@ RepeaterBackend.prototype.process = function(packet, rinfo) {
exports.init = function(startupTime, config, events) {
var instance = new RepeaterBackend(startupTime, config, events);
l = new logger.Logger(config.log || {});
debug = config.debug;
return true;
};