{"size": 1374, "ext": "js", "max_stars_repo_path": "lib/log4js/Log4jsReportPortalAppender.js", "max_stars_repo_name": "minhhoangvn/reportportal-javascript-agent", "max_stars_repo_stars_event_min_datetime": "2020-12-06T04:28:06.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-17T16:38:12.000Z", "max_issues_repo_path": "lib/log4js/Log4jsReportPortalAppender.js", "max_issues_repo_name": "minhhoangvn/reportportal-javascript-agent", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/log4js/Log4jsReportPortalAppender.js", "max_forks_repo_name": "minhhoangvn/reportportal-javascript-agent", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.35, "max_line_length": 78, "alphanum_fraction": 0.6615720524}
class Log4jsReportPortal {
  constructor(agent) {
    this.agent = agent;
    this.reportPortalAppender = this.reportPortalAppender.bind(this);
    this.configure = this.configure.bind(this);
  }
  reportPortalAppender(layout, timezoneOffset) {
    // This is the appender function itself
    return loggingEvent => {
      if (this.agent) {
        const logLevel = loggingEvent.level;
        const { currentItem } = this.agent.agentContex.getItem();
        const ctx = this.agent.agentContex;
        const currentState = ctx.state.getCurrentState();
        const isTestItem = currentState === 'TEST' || currentState === 'STEP';
        const isValidToSendLogData = currentItem && isTestItem;
        if (isValidToSendLogData) {
          this.agent.client.sendLog(currentItem, {
            message: layout(loggingEvent, timezoneOffset),
            level: logLevel.levelStr,
          });
        }
      }
    };
  }
  configure(config, layouts) {
    // the default layout for the appender
    let layout = layouts.colouredLayout;
    // check if there is another layout specified
    if (config.layout) {
      // load the layout
      layout = layouts.layout(config.layout.type, config.layout);
    }
    //create a new appender instance
    return this.reportPortalAppender(layout, config.timezoneOffset);
  }
}

exports.Log4jsReportPortal = Log4jsReportPortal;
