Skip to content

Instantly share code, notes, and snippets.

@jbristowe
Created August 17, 2015 03:57
Show Gist options
  • Save jbristowe/2bb817a3d2adb4f9b58d to your computer and use it in GitHub Desktop.
Save jbristowe/2bb817a3d2adb4f9b58d to your computer and use it in GitHub Desktop.
var listener = new Listener("NativeScript Rocks!!11!");
trace.addEventListener(listener);
trace.clearWriters();
trace.addWriter(new TimestampConsoleWriter());
var Listener = (function () {
function Listener(filter) {
this.filter = filter;
}
Listener.prototype.on = function (object, name, data) {
// validate parameters and do something for trace.notifyEvent()
};
return Listener;
})();
var TimestampConsoleWriter = (function () {
function TimestampConsoleWriter() { }
TimestampConsoleWriter.prototype.write = function (message, category, type) {
if (!console) return;
var msgType = types.isUndefined(type) ? trace.messageType.log : type;
var traceMessage = new Date().toISOString() + " " + category + ": " + message;
switch (msgType) {
case trace.messageType.log:
console.log(traceMessage);
break;
case trace.messageType.info:
console.info(traceMessage);
break;
case trace.messageType.warn:
console.warn(traceMessage);
break;
case trace.messageType.error:
console.error(traceMessage);
break;
}
};
return TimestampConsoleWriter;
})();
trace.disable(); // tracing disabled -- party pooper!
var trace = require("trace");
trace.enable(); // tracing enabled -- let's party!
console.log("Hello, NativeScript!");
// add the binding category to the existing list of trace messages
trace.addCategories(trace.categories.Binding);
// filter out all trace messages except those that are animation and debug categories
trace.setCategories(trace.categories.concat(trace.categories.Animation, trace.categories.Debug));
var data = { /* ... */ };
trace.notifyEvent(this, "NativeScript Rocks!!11!", data);
trace.write("I (heart) NativeScript!", trace.categories.Debug);
trace.setCategories("Questions");
trace.write("NativeScript: Great technology or the greatest technology?", "Questions");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment