package io.delphi.qa.auto.awsmfrw.common_baby;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

public interface IsaLogging extends IsaConstants {

  String TEST_NAME = "testname";

  default Logger log(){
      return LoggerFactory.getLogger(this.getClass().getName());
  }

  static void  log(Class<? extends IsaLogging> aClass, String msg) {
    if (envConfig.isLocal()) {
      LoggerFactory.getLogger(aClass.getName()).info(msg);
    }
  }

  /**
   * Adds the test name to MDC so that sift appender can use it and log the new log events to a
   * different file
   *
   * @param name name of the new log file
   * @throws Exception
   */
  default void startTestCaseLog(String name) {
    MDC.put(TEST_NAME, name);
  }

  /**
   * Removes the key (log file name) from MDC
   *
   * @return name of the log file, if one existed in MDC
   */
  default String stopTestCaseLog() {
    String name = MDC.get(TEST_NAME);
    MDC.remove(TEST_NAME);
    return name;
  }
}
