0

I've been trying to build out a custom AjaxAppender with jsnlog.js and I'm noticing a strange behavior around the batch size setting. If I set the batch size to something greater than 1 it will work, otherwise it will not.

There is a default configuration for the AjaxAppender that works out of the box, so I would expect that I should be able to get a similar result, but have been unable to do so.

My code is below:

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]
    });
John Babb
  • 931
  • 10
  • 19
  • I understand the default AjaxAppender works with batchSize=1, but yours doesn't. Are you saying there is something in jsnlog.js that is causing this, or is this likely to be an issue in your own code? If it is an issue with jsnlog.js itself, could you create a super simple test project on Github that reproduces the problem - that makes it more likely that the issue will get fixed. – user1147862 May 20 '23 at 05:21

0 Answers0