/* automatically generated by JSCoverage - do not edit */
if (typeof _$jscoverage === 'undefined') _$jscoverage = {};
if (! _$jscoverage['logging/appenders/rollingFileAppender.js']) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'] = [];
  _$jscoverage['logging/appenders/rollingFileAppender.js'][1] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][16] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][21] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][22] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][23] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][24] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][25] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][26] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][27] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][29] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][78] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][82] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][83] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][84] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][85] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][86] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][87] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][88] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][89] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][90] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][91] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][96] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][97] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][98] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][99] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][100] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][101] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][102] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][103] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][104] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][105] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][106] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][107] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][111] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][112] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][115] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][118] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][120] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][125] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][126] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][127] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][128] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][130] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][136] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][137] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][141] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][142] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][143] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][144] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][146] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][147] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][148] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][150] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][153] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][154] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][155] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][156] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][157] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][158] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][160] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][162] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][163] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][164] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][165] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][166] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][168] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][169] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][170] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][174] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][175] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][176] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][180] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][183] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][185] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][192] = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][198] = 0;
}
_$jscoverage['logging/appenders/rollingFileAppender.js'][1]++;
var define = require("../../define.js").define, promise = require("../../promise"), Promise = promise.Promise, PromiseList = promise.PromiseList, base = require("../../base"), hitch = base.hitch, string = base.string, escape = base.regexp.escapeString, style = string.style, format = string.format, FileAppender = require("./fileAppender"), Level = require("../level"), fs = require("fs"), path = require("path");
_$jscoverage['logging/appenders/rollingFileAppender.js'][16]++;
var conversion = {MB: 1048576, KB: 1024, GB: 1073741824};
_$jscoverage['logging/appenders/rollingFileAppender.js'][21]++;
var DEFAULT_SIZE = "10MB";
_$jscoverage['logging/appenders/rollingFileAppender.js'][22]++;
var convertToBytes = (function (str) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][23]++;
  var ret = DEFAULT_SIZE;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][24]++;
  var match = str.match(/(\d+)(MB|KB|GB)$/);
  _$jscoverage['logging/appenders/rollingFileAppender.js'][25]++;
  if (match && match.length == 3) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][26]++;
    var size = parseInt(match[1], 10);
    _$jscoverage['logging/appenders/rollingFileAppender.js'][27]++;
    ret = size * conversion[match[2]];
  }
  _$jscoverage['logging/appenders/rollingFileAppender.js'][29]++;
  return ret;
});
_$jscoverage['logging/appenders/rollingFileAppender.js'][78]++;
exports = module.exports = define(FileAppender, {instance: {constructor: (function (options) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][82]++;
  options = options || {};
  _$jscoverage['logging/appenders/rollingFileAppender.js'][83]++;
  this.maxSize = options.maxSize || DEFAULT_SIZE;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][84]++;
  ! options.name && (options.name = "rollingFileAppender");
  _$jscoverage['logging/appenders/rollingFileAppender.js'][85]++;
  this.maxBackupIndex = options.maxBackupIndex || 10;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][86]++;
  this.__queue = [];
  _$jscoverage['logging/appenders/rollingFileAppender.js'][87]++;
  this.__inRollover = false;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][88]++;
  this["super"](arguments, [options]);
  _$jscoverage['logging/appenders/rollingFileAppender.js'][89]++;
  fs.watchFile(this.__file, hitch(this, "__checkFile"));
  _$jscoverage['logging/appenders/rollingFileAppender.js'][90]++;
  fs.stat(this.__file, hitch(this, (function (err, stat) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][91]++;
  this.__checkFile(stat);
})));
}), __checkFile: (function (stats) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][96]++;
  var ret = new Promise();
  _$jscoverage['logging/appenders/rollingFileAppender.js'][97]++;
  if (! this.__inRollover) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][98]++;
    if (stats.size >= this.maxSize) {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][99]++;
      if (this.maxBackupIndex > 0) {
        _$jscoverage['logging/appenders/rollingFileAppender.js'][100]++;
        this.__inRollover = true;
        _$jscoverage['logging/appenders/rollingFileAppender.js'][101]++;
        this.__onExit().chain(hitch(this, "__rollover")).then(hitch(this, (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][102]++;
  var ws = fs.createWriteStream(this.__file, {flags: "w", encoding: this.__encoding});
  _$jscoverage['logging/appenders/rollingFileAppender.js'][103]++;
  ws.on("open", hitch(this, (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][104]++;
  this.__writeStream = ws;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][105]++;
  this.__inRollover = false;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][106]++;
  this.__checkQueue();
  _$jscoverage['logging/appenders/rollingFileAppender.js'][107]++;
  ret.callback();
})));
})), hitch(ret, "errback", new Error("comb.logging.appenders.RollingFileAppender : error rolling over files")));
      }
      else {
        _$jscoverage['logging/appenders/rollingFileAppender.js'][111]++;
        this.__writeStream = fs.createWriteStream(this.__file, {flags: "w", encoding: this.__encoding});
        _$jscoverage['logging/appenders/rollingFileAppender.js'][112]++;
        ret.callback();
      }
    }
    else {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][115]++;
      ret.callback();
    }
  }
  else {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][118]++;
    ret.callback();
  }
  _$jscoverage['logging/appenders/rollingFileAppender.js'][120]++;
  return ret;
}), append: (function (event) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][125]++;
  if (this._canAppend(event)) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][126]++;
    var ws = this.__writeStream;
    _$jscoverage['logging/appenders/rollingFileAppender.js'][127]++;
    if (! this.__inRollover && ws && ws.writable) {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][128]++;
      this["super"](arguments);
    }
    else {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][130]++;
      this.__queue.push(event);
    }
  }
}), __checkQueue: (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][136]++;
  this.__queue.forEach(this.append, this);
  _$jscoverage['logging/appenders/rollingFileAppender.js'][137]++;
  this.__queue.length = 0;
}), __rollover: (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][141]++;
  var ret = new Promise(), file = this.__file;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][142]++;
  var dir = path.dirname(file), baseName = new RegExp("(" + escape(path.basename(path.basename(file))) + ")(?:\\.(\\d*))*");
  _$jscoverage['logging/appenders/rollingFileAppender.js'][143]++;
  fs.readdir(dir, hitch(this, (function (err, files) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][144]++;
  files = files.filter((function (f) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][146]++;
  var match = f.match(baseName);
  _$jscoverage['logging/appenders/rollingFileAppender.js'][147]++;
  if (match) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][148]++;
    return true;
  }
  else {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][150]++;
    return false;
  }
}));
  _$jscoverage['logging/appenders/rollingFileAppender.js'][153]++;
  files = files.sort((function (a, b) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][154]++;
  var ret = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][155]++;
  if (a > b) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][156]++;
    ret = 0;
  }
  else {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][157]++;
    if (a < b) {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][158]++;
      ret = 1;
    }
  }
  _$jscoverage['logging/appenders/rollingFileAppender.js'][160]++;
  return ret;
}));
  _$jscoverage['logging/appenders/rollingFileAppender.js'][162]++;
  var count = files.length, i = 0;
  _$jscoverage['logging/appenders/rollingFileAppender.js'][163]++;
  var checkFile = hitch(this, (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][164]++;
  if (count > 0) {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][165]++;
    var f = dir + "/" + files[i++];
    _$jscoverage['logging/appenders/rollingFileAppender.js'][166]++;
    if (count > this.maxBackupIndex) {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][168]++;
      count--;
      _$jscoverage['logging/appenders/rollingFileAppender.js'][169]++;
      fs.unlink(f, (function (err) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][170]++;
  err? ret.errback(err): checkFile();
}));
    }
    else {
      _$jscoverage['logging/appenders/rollingFileAppender.js'][174]++;
      var rn = this.__file + "." + count--;
      _$jscoverage['logging/appenders/rollingFileAppender.js'][175]++;
      fs.rename(f, rn, (function (err) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][176]++;
  err? ret.errback(err): checkFile();
}));
    }
  }
  else {
    _$jscoverage['logging/appenders/rollingFileAppender.js'][180]++;
    ret.callback();
  }
}));
  _$jscoverage['logging/appenders/rollingFileAppender.js'][183]++;
  checkFile();
})));
  _$jscoverage['logging/appenders/rollingFileAppender.js'][185]++;
  return ret;
}), getters: {maxSize: (function () {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][192]++;
  return this.__maxSize;
})}, setters: {maxSize: (function (size) {
  _$jscoverage['logging/appenders/rollingFileAppender.js'][198]++;
  this.__maxSize = size? convertToBytes(size): DEFAULT_SIZE;
})}}});
_$jscoverage['logging/appenders/rollingFileAppender.js'].source = ["var define = require(\"../../define.js\").define,","        promise = require(\"../../promise\"),","        Promise = promise.Promise,","        PromiseList = promise.PromiseList,","        base = require(\"../../base\"),","        hitch = base.hitch,","        string = base.string,","        escape = base.regexp.escapeString,","        style = string.style,","        format = string.format,","        FileAppender = require(\"./fileAppender\"),","        Level = require(\"../level\"),","        fs = require(\"fs\"),","        path = require(\"path\");","","var conversion = {","    MB : 1048576,","    KB : 1024,","    GB : 1073741824","};","var DEFAULT_SIZE = \"10MB\";","var convertToBytes = function(str) {","    var ret = DEFAULT_SIZE;","    var match = str.match(/(\\d+)(MB|KB|GB)$/);","    if (match &amp;&amp; match.length == 3) {","        var size = parseInt(match[1], 10);","        ret = size * conversion[match[2]];","    }","    return ret;","}","","/**"," * @class Appends messages to a file. Rolls files over when a size limit has been reached. Once the max file size has"," * been reached it is rolled over to a file called &lt;logName&gt;.log.n where n is a number."," *"," * &lt;p&gt;Example. RollingFileAppender is current writing to myLog.log, the log reaches is max size to it is"," * renamed to myLog.log.1 and a new myLog.log is created.&lt;/p&gt;"," *"," * &lt;p&gt;If maxBackupIndex is reached then the log at that index is deleted. If maxBackupIndex is set to 0 then no log is"," * rolled over.&lt;/p&gt;"," *"," * @name RollingFileAppender"," * @augments comb.logging.appenders.FileAppender"," * @memberOf comb.logging.appenders"," *"," * @param {Object} [options] options to assign to this Appender"," * @param {String} [options.name=\"appender\"] the name of this Appender. If you want two of the same type of appender"," *                                           on a logger it must have a different name."," * @param {String} [options.pattern=\"[{[yyyy-MM-ddTHH:mm:ss:SSS (z)]timeStamp}] {[- 5]levelName} {[-20]name} - {message}\"]"," *  &lt;p&gt;Available Options for formatting see {@link comb.string.format} for formatting options&lt;/p&gt;"," *  &lt;ul&gt;"," *      &lt;li&gt;timeStamp - the timestamp of the event being logged&lt;/li&gt;"," *      &lt;li&gt;level - the {@link comb.logging.Level} of the event&lt;/li&gt;"," *      &lt;li&gt;levelName - the name of the level being logged&lt;/li&gt;"," *      &lt;li&gt;name - the name of the logger logging the event&lt;/li&gt;"," *      &lt;li&gt;message - the message being logged&lt;/li&gt;"," * &lt;/ul&gt;"," * @param {comb.logging.Level|String} [options.level=comb.logging.Level.INFO] the logging level of this appender"," *      &lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; the level can be different from the logger in the case that you want a particular logger"," *      to only log particular event of a level. For example an appender that only logs errors. BEWARE that if the"," *      appenders level is lower than the logger is will not recieve any messages.&lt;/p&gt;"," *"," * @param {String} [options.file=\"./log.log\"] the file to log events to."," * @param {String} [options.encoding=\"utf8\"] the encoding of the file."," * @param {Boolean} [options.overwrite=false] if true the log file is overwritten otherwise it is appended to."," * @param {String} [options.maxSize=\"10MB\"] the maxSize of a file. Valid options include \"KB\", \"MB\", or \"GB\""," *"," * &lt;pre class=\"code\"&gt;"," *     maxSize = \"100MB\""," *     //or"," *     maxSize = \"100KB\""," *     //or"," *     maxSize = \"1GB\""," * &lt;/pre&gt;"," *"," * @param {Number} [options.maxBackupIndex=10] the maximum number of files to rollOver."," */","exports = module.exports = define(FileAppender, {","            instance : {","","                constructor : function(options) {","                    options = options || {};","                    this.maxSize = options.maxSize || DEFAULT_SIZE;","                    !options.name &amp;&amp; (options.name = \"rollingFileAppender\");","                    this.maxBackupIndex = options.maxBackupIndex || 10;","                    this.__queue = [];","                    this.__inRollover = false;","                    this.super(arguments, [options]);","                    fs.watchFile(this.__file, hitch(this, \"__checkFile\"));","                    fs.stat(this.__file, hitch(this, function(err, stat) {","                        this.__checkFile(stat);","                    }));","                },","","                __checkFile : function(stats) {","                    var ret = new Promise();","                    if (!this.__inRollover) {","                        if (stats.size &gt;= this.maxSize) {","                            if (this.maxBackupIndex &gt; 0) {","                                this.__inRollover = true;","                                this.__onExit().chain(hitch(this, \"__rollover\")).then(hitch(this, function() {","                                    var ws = fs.createWriteStream(this.__file, { flags: \"w\", encoding: this.__encoding});","                                    ws.on(\"open\", hitch(this, function() {","                                        this.__writeStream = ws;","                                        this.__inRollover = false;","                                        this.__checkQueue();","                                        ret.callback();","                                    }));","                                }), hitch(ret, \"errback\", new Error(\"comb.logging.appenders.RollingFileAppender : error rolling over files\")));","                            } else {","                                this.__writeStream = fs.createWriteStream(this.__file, { flags: \"w\", encoding: this.__encoding});","                                ret.callback();","                            }","                        } else {","                            ret.callback();","                        }","                    } else {","                        ret.callback();","                    }","                    return ret;","                },","","","                append : function(event) {","                    if (this._canAppend(event)) {","                        var ws = this.__writeStream;","                        if (!this.__inRollover &amp;&amp; ws &amp;&amp; ws.writable) {","                            this.super(arguments);","                        } else {","                            this.__queue.push(event);","                        }","                    }","                },","","                __checkQueue : function() {","                    this.__queue.forEach(this.append, this);","                    this.__queue.length = 0;","                },","","                __rollover : function() {","                    var ret = new Promise(), file = this.__file;","                    var dir = path.dirname(file), baseName = new RegExp(\"(\" + escape(path.basename(path.basename(file))) + \")(?:\\\\.(\\\\d*))*\");","                    fs.readdir(dir, hitch(this, function(err, files) {","                        files = files.filter(","                                function(f) {","                                    var match = f.match(baseName);","                                    if (match) {","                                        return true;","                                    } else {","                                        return false;","                                    }","                                });","                        files = files.sort(function(a, b) {","                            var ret = 0;","                            if (a &gt; b) {","                                ret = 0;","                            } else if (a &lt; b) {","                                ret = 1;","                            }","                            return ret;","                        });","                        var count = files.length, i = 0;","                        var checkFile = hitch(this, function() {","                            if (count &gt; 0) {","                                var f = dir + \"/\" + files[i++];","                                if (count &gt; this.maxBackupIndex) {","                                    //drop the file;","                                    count--;","                                    fs.unlink(f, function(err) {","                                        err ? ret.errback(err) : checkFile();","                                    });","                                } else {","                                    //rename the file","                                    var rn = this.__file + \".\" + count--;","                                    fs.rename(f, rn, function(err) {","                                        err ? ret.errback(err) : checkFile();","                                    });","                                }","                            } else {","                                ret.callback();","                            }","                        });","                        checkFile();","                    }));","                    return ret;","                },","","","                getters : {","","                    maxSize : function() {","                        return this.__maxSize;","                    }","                },","","                setters : {","                    maxSize : function(size) {","                        this.__maxSize = size ? convertToBytes(size) : DEFAULT_SIZE;","                    }","                }","            }","        });"];
