mperdeck / jsnlog.js

Tiny JavaScript logging library, simple and well documented. Lots of options to filter logging data.
js.jsnlog.com
Other
130 stars 43 forks source link

Custom AjaxAppender does not execute if batchsize is set to one #83

Open john-babb-tss opened 1 year ago

john-babb-tss commented 1 year ago

I'm not sure if this is a bug or not, but it looks like the custom ajax AjaxAppender will only work if you have a batch size > 1. Can you take a look at this and let me know why this is an issue, and or, if this is a expected?

private initializeLogger() {
        this.rootlogger = this.JL('tss');
        const beforeSendExample = (xhr) => {
          xhr.setRequestHeader('X-Correlation-Id', this.correlationService.current.id);
        };
        this.ajaxAppender = JL.createAjaxAppender('ajaxAppenderTss');
        this.ajaxAppender.setOptions({
          level : JL.getAllLevel(),
          sendWithBufferLevel : JL.getErrorLevel(),
          storeInBufferLevel : -2147483648,
          bufferSize : 0, // buffering switch off by default
          batchSize : 1, // -------------------------------                      DOES NOT WORK
         // batchSize : 2, // -------------------------------                    This does work.
          maxBatchSize : 20,
          batchTimeout : 2147483647,
          sendTimeout : 5000,
          beforeSend: beforeSendExample
        });
        this.consoleAppender = JL.createConsoleAppender('consoleAppenderTss');
        this.rootlogger =  this.rootlogger.setOptions({
          level: JL.getAllLevel(),
          appenders: [this.ajaxAppender, this.consoleAppender]
        });
    }