kopia lustrzana https://github.com/c9/core
Add vfs.log to log from client directly to vfs server
rodzic
8eea16b8fb
commit
31d92edd1b
|
@ -0,0 +1,10 @@
|
|||
|
||||
module.exports = function(vfs, options, register) {
|
||||
register(null, {
|
||||
log: function(message, callback) {
|
||||
console.log("VFSLOG: " + message);
|
||||
console.error("VFSERROR: " + message);
|
||||
callback();
|
||||
}
|
||||
})
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/** Sends client side logs to vfs via the websocket connection **/
|
||||
|
||||
define(function (require, exports, module) {
|
||||
"use strict";
|
||||
|
||||
main.consumes = ["Plugin", "ext", "c9"];
|
||||
main.provides = ["vfs.log"];
|
||||
return main;
|
||||
|
||||
function main(options, imports, register) {
|
||||
var Plugin = imports.Plugin;
|
||||
var c9 = imports.c9;
|
||||
var ext = imports.ext;
|
||||
var plugin = new Plugin("Ajax.org", main.consumes);
|
||||
|
||||
var loaded = false;
|
||||
var server = null;
|
||||
|
||||
function load() {
|
||||
if (loaded) return false;
|
||||
loaded = true;
|
||||
|
||||
ext.loadRemotePlugin("log", {
|
||||
code: require("text!./log-service.js"),
|
||||
redefine: true
|
||||
}, function(err, remote) {
|
||||
if (err) return console.error(err);
|
||||
|
||||
server = remote;
|
||||
});
|
||||
|
||||
c9.on("stateChange", function(e) {
|
||||
if (e.state & c9.NETWORK) {
|
||||
load();
|
||||
}
|
||||
else {
|
||||
loaded = false;
|
||||
server = null;
|
||||
}
|
||||
}, plugin);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function log() {
|
||||
if (!server) return console.error("Cannot log, client is offline");
|
||||
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var message = "";
|
||||
args.forEach(function (arg) {
|
||||
if (typeof arg === "object") {
|
||||
return message += JSON.stringify(arg);
|
||||
}
|
||||
message += arg;
|
||||
});
|
||||
|
||||
server.log(message);
|
||||
}
|
||||
|
||||
plugin.on("load", function() {
|
||||
load();
|
||||
});
|
||||
|
||||
plugin.on("unload", function() {
|
||||
loaded = false;
|
||||
server = null;
|
||||
});
|
||||
|
||||
plugin.freezePublicAPI({
|
||||
log: log
|
||||
});
|
||||
|
||||
register(null, {
|
||||
"vfs.log": plugin
|
||||
});
|
||||
}
|
||||
})
|
Ładowanie…
Reference in New Issue