Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 54086c61c2c8eb0bc37b32982a7e3d59bf9781e1 1 parent d374de6
@yarekt yarekt authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 backends/repeater.js
View
16 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 || [];
@@ -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;
};
Please sign in to comment.
Something went wrong with that request. Please try again.