/**
 * (c) COPYRIGHT PESACH WEINSTOCK 1998-2011
 */

function LogStream() {
  this.stream = "";
  this.prefix = "";
  this.first = true;
  this.println = function(s, shallow) {
    this.print(s, shallow);
    this.newLine();
  };
  this.print = function(s, shallow) {
    this.stream += (this.first ? this.prefix : "");
    if ( s && s.debug && typeof s.debug == 'function')
      s.debug(this, shallow);
    else if ( typeof s == 'function' && shallow )
      this.stream += "function";
    else
      this.stream += s;
    this.first = false;
  };
  this.newLine = function(s) {
    this.stream += "\n";
    this.first = true;
  };
  this.entab = function(pre) {
    pre = pre || "  ";
    this.prefix += pre;
  };
  this.detab = function(n) {
    n = n || 2;
    this.prefix = this.prefix.substr(0, this.prefix.length - n);
  };
  this.toString = function() { return this.stream; };
}

function toStringLog() {
  var ls = new LogStream();
  this.debug(ls);
  return ls.stream;
}

window.LogStream = LogStream;
window.toStringLog = toStringLog;

