Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Implementation of --silent #120

Open
wants to merge 2 commits into from

1 participant

Rene van Lieshout
Rene van Lieshout

Hello,

I've had some issues with the output of Juggernaut, UTF-8 and Foreman and found out it didn't do anything with --silent yet. Added some basic functionality for that.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 7, 2012
  1. Rene van Lieshout
Commits on Mar 6, 2012
  1. Rene van Lieshout
This page is out of date. Refresh to see the latest.
3  lib/juggernaut/channel.js
View
@@ -1,4 +1,5 @@
var util = require("util");
+var logger = require("./logger");
var Events = require("./events");
Channel = module.exports = require("./klass").create();
@@ -16,7 +17,7 @@ Channel.extend({
var channels = message.getChannels();
delete message.channels;
- util.log(
+ logger.log(
"Publishing to channels: " +
channels.join(", ") + " : " + message.data
);
5 lib/juggernaut/client.js
View
@@ -1,4 +1,5 @@
var util = require("util");
+var logger = require("./logger");
var Channel = require("./channel");
var Events = require("./events");
@@ -19,14 +20,14 @@ Client.include({
},
subscribe: function(name){
- util.log("Client subscribing to: " + name);
+ logger.log("Client subscribing to: " + name);
var channel = Channel.find(name)
channel.subscribe(this);
},
unsubscribe: function(name){
- util.log("Client unsubscribing from: " + name);
+ logger.log("Client unsubscribing from: " + name);
var channel = Channel.find(name);
channel.unsubscribe(this);
3  lib/juggernaut/connection.js
View
@@ -1,4 +1,5 @@
var util = require("util");
+var logger = require("./logger");
var Client = require("./client");
Connection = module.exports = require("./klass").create();
@@ -13,7 +14,7 @@ Connection.include({
},
onmessage: function(data){
- util.log("Received: " + data);
+ logger.log("Received: " + data);
try {
var message = Message.fromJSON(data);
9 lib/juggernaut/events.js
View
@@ -12,12 +12,19 @@ Events.publish = function(key, value){
};
Events.subscribe = function(channel, client) {
+ var handshake = client.connection.stream.manager.handshaken[client.session_id]
+ var referer = null;
+ if (handshake["headers"]) {
+ referer = handshake["headers"]["referer"];
+ }
+
this.publish(
"subscribe",
{
channel: channel.name,
meta: client.meta,
- session_id: client.session_id
+ session_id: client.session_id,
+ referer: referer
}
);
};
17 lib/juggernaut/logger.js
View
@@ -0,0 +1,17 @@
+var util = require("util");
+
+var Logger = (function() {
+ this.silent = false;
+
+ function log(msg) {
+ if (!this.silent) {
+ util.log(msg);
+ }
+ }
+
+ return {
+ log: log
+ };
+})();
+
+module.exports = Logger;
3  lib/juggernaut/publish.js
View
@@ -1,4 +1,5 @@
var util = require("util");
+var logger = require("./logger");
var redis = require("./redis");
var Message = require("./message");
var Channel = require("./channel");
@@ -8,7 +9,7 @@ Publish.listen = function(){
this.client = redis.createClient();
this.client.on("message", function(_, data) {
- util.log("Received: " + data);
+ logger.log("Received: " + data);
try {
var message = Message.fromJSON(data);
5 lib/juggernaut/server.js
View
@@ -1,6 +1,7 @@
var http = require("http");
var https = require("https");
var util = require("util");
+var logger = require("./logger")
var path = require("path");
var fs = require("fs");
var io = require("socket.io");
@@ -30,7 +31,7 @@ Server.include({
response.writeHead(err.status || 500, err.headers);
response.end();
} else { // The file was served successfully
- util.log("Serving " + request.url + " - " + res.message);
+ logger.log("Serving " + request.url + " - " + res.message);
}
});
@@ -47,6 +48,8 @@ Server.include({
this.io.sockets.on("connection", function(stream){ Connection.inst(stream) });
},
+ silent: false,
+
listen: function(port){
port = parseInt(port || process.env.PORT || 8080);
this.httpServer.listen(port);
4 server.js
View
@@ -2,6 +2,8 @@
var argv = require("optimist").argv,
util = require("util");
+var logger = require("./lib/juggernaut/logger");
+
var help = [
"usage: juggernaut [options] ",
"",
@@ -17,5 +19,7 @@ if (argv.h || argv.help) {
return util.puts(help);
}
+logger.silent = argv.silent;
+
Juggernaut = require("./index");
Juggernaut.listen(argv.port);
Something went wrong with that request. Please try again.