This repository has been archived on 2024-07-18. You can view files and clone it, but cannot push or open issues or pull requests.
lwb5/misc/Legacy Worlds.wdgt/lib/Base/Log.js

52 lines
814 B
JavaScript

Base.Log = Base.inherits({
constructor: function (maxSize) {
this.base();
this.log = new Array();
this.maxSize = maxSize ? maxSize : 4096;
},
insert: function (line) {
if (!line) {
return;
}
if (this.log.length == this.maxSize) {
this.log.shift();
}
this.log.push(line);
},
flush: function () {
this.log = new Array();
}
}, {
singleton: null,
initLog: function (maxSize) {
if (!this.singleton) {
this.singleton = new this(maxSize);
}
},
write: function (line) {
if (this.singleton) {
this.singleton.insert(line);
}
},
get: function () {
return (this.singleton ? this.singleton.log : new Array());
},
flush: function () {
if (!this.singleton) {
return new Array();
}
var _r = this.singleton.log;
this.singleton.flush();
return _r;
}
});