log_tracer.js 1.1 KB
Newer Older
1
function LogTracer(module) {
2
    if (Tracer.call(this)) {
J
Jason Park 已提交
3 4 5 6
        LogTracer.prototype.init.call(this);
        return true;
    }
    return false;
7 8 9 10
}

LogTracer.prototype = $.extend(true, Object.create(Tracer.prototype), {
    constructor: LogTracer,
J
Jason Park 已提交
11 12 13 14
    init: function () {
        this.$wrapper = this.capsule.$wrapper = $('<div class="wrapper">');
        this.$container.append(this.$wrapper);
    },
J
minor  
Jason Park 已提交
15 16
    _print: function (msg) {
        tm.pushStep(this.capsule, {type: 'print', msg: msg});
17
        return this;
18 19 20 21
    },
    processStep: function (step, options) {
        switch (step.type) {
            case 'print':
22
                this.print(step.msg);
23 24 25 26 27 28
                break;
        }
    },
    refresh: function () {
        this.scrollToEnd(Math.min(50, this.interval));
    },
J
Jason Park 已提交
29 30 31 32 33
    clear: function () {
        Tracer.prototype.clear.call(this);

        this.$wrapper.empty();
    },
34
    print: function (message) {
J
Jason Park 已提交
35
        this.$wrapper.append($('<span>').append(message + '<br/>'));
36 37
    },
    scrollToEnd: function (duration) {
J
Jason Park 已提交
38
        this.$container.animate({scrollTop: this.$container[0].scrollHeight}, duration);
39 40
    }
});