Skip to content

Commit 5c103b6

Browse files
author
Gabriel Hopper
committed
middle-initialize callback with logging level
1 parent a0023c0 commit 5c103b6

File tree

5 files changed

+51
-35
lines changed

5 files changed

+51
-35
lines changed

Diff for: LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2012 jolira
1+
Copyright (c) 2013
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
44
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the

Diff for: index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@
5353
defaults.htmlFiles = [
5454
path.join(templates, "container.html")
5555
];
56-
// [
57-
// "img/glyphicons-halflings.png",
58-
// "img/glyphicons-halflings-white.png"
59-
// ].forEach(function (file) {
60-
// defaults.manifest.push(file);
61-
// });
56+
6257
defaults.links.push({
6358
rel:"apple-touch-startup-image",
6459
href:"startup.png"

Diff for: lib/client-init.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
module.exports = function(logger) {
66
return {
7-
'middle-initialize':function (id) {
7+
'middle-initialize':function (id, cb) {
88
this.set("id", id);
99
logger.info("initialized", this.id, id);
10+
11+
// logger[level]
12+
var loggingLevel = 'debug';
13+
if(process.env.NODE_ENV === "production") {
14+
loggingLevel = 'error';
15+
}
16+
if(cb) {
17+
cb(undefined, {loggingLevel: loggingLevel});
18+
}
19+
1020
}
1121
};
1222
};

Diff for: lib/client-logger.js

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
var params = convert(client.id, id, args),
3131
level = params.shift(),
3232
_logger = logger[level] || logger.info;
33-
3433
return _logger.apply(_logger, params);
3534
});
3635
}

Diff for: public/js/app-middle.js

+38-26
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,31 @@
2828
}
2929
}
3030

31-
function log(socket, level, _args) {
32-
var args = Array.prototype.slice.call(_args),
33-
params = [
34-
"log",
35-
level,
36-
new Date()
37-
];
38-
39-
_.each(args, function (arg) {
40-
var param = convert(arg);
41-
42-
params.push(param);
43-
});
31+
function log(socket, level, loggingLevel, _args) {
32+
33+
var logToServer = false;
34+
if('error' === loggingLevel === level) {
35+
logToServer = true;
36+
} else if ('debug' === loggingLevel) {
37+
logToServer = true;
38+
}
39+
40+
if(logToServer) {
41+
var args = Array.prototype.slice.call(_args),
42+
params = [
43+
"log",
44+
level,
45+
new Date()
46+
];
47+
48+
_.each(args, function (arg) {
49+
var param = convert(arg);
50+
51+
params.push(param);
52+
});
4453

45-
return socket.emit.apply(socket, params);
54+
return socket.emit.apply(socket, params);
55+
}
4656
}
4757

4858
function emitter(socket) {
@@ -116,21 +126,23 @@
116126
platform:device.platform,
117127
version:device.version,
118128
cordova:device.cordova
119-
});
129+
}, function(err, result) {
130+
app.log = function () {
131+
return log(socket, "info", result.loggingLevel, arguments);
132+
};
133+
app.debug = function () {
134+
return log(socket, "debug", result.loggingLevel, arguments);
135+
};
136+
app.error = function () {
137+
return log(socket, "error", result.loggingLevel, arguments);
138+
};
139+
140+
app.log("middle connected");
120141

121-
app.log = function () {
122-
return log(socket, "info", arguments);
123-
};
124-
app.debug = function () {
125-
return log(socket, "debug", arguments);
126-
};
127-
app.error = function () {
128-
return log(socket, "error", arguments);
129-
};
142+
return _cb && _cb(socket);
143+
});
130144

131-
app.log("middle connected");
132145

133-
return _cb && _cb(socket);
134146
});
135147
socket.on('disconnect', function () {
136148
app.middle.connected = false;

0 commit comments

Comments
 (0)