Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Use Logger for repeater and don't scream if debug is off
Browse files Browse the repository at this point in the history
  • Loading branch information
YarekTyshchenko committed Feb 8, 2013
1 parent d374de6 commit 54086c6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions backends/repeater.js
@@ -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 || [];
Expand All @@ -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); });
Expand All @@ -21,14 +25,16 @@ 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);
}
});
}
};

exports.init = function(startupTime, config, events) {
var instance = new RepeaterBackend(startupTime, config, events);
l = new logger.Logger(config.log || {});
debug = config.debug;
return true;
};

0 comments on commit 54086c6

Please sign in to comment.