All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.heavenark.infrastructure.log.model.ArkLogEntity Maven / Gradle / Ivy

The newest version!
package com.heavenark.infrastructure.log.model;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.heavenark.infrastructure.log.exception.ArkLogRuntimeException;
import com.heavenark.infrastructure.log.util.ArkLogPublicUtil;
import lombok.Data;

import java.util.Date;

/**
 * Push entity
 *
 * @since 2.6.0
 * @author 冰糕Luminous BGLuminous Luminous
 */
@Data
public class ArkLogEntity {
  // from project
  private String project;
  // docker container id
  private String containerId;
  // log type
  private ArkLogType type;
  // log occurrence time
  private Long occurrenceTime;
  // log occurrence class
  private String occurrenceClass;
  // log occurrence thread
  private String occurrenceThread;
  // basic log
  private String basicLog;
  // log trace
  private String trace;

  /**
   * Get current entity json string
   *
   * @return json
   */
  public String stringify() {
    try {
      return new ObjectMapper().writeValueAsString(this);
    } catch (NoClassDefFoundError error) {
      throw new ArkLogRuntimeException(
          "Json stringify operation triggered, But missing jackson parse dependency.\n"
              + "Detail see: https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind");
    } catch (Exception ex) {
      String err = String.format("Json stringify got error: %s%nData:%s", ex.getMessage(), this);
      ArkLogPublicUtil.internalLog(this.getClass(), ArkLogType.ERR, err);
    }
    return null;
  }

  /**
   * Generate final log
   *
   * @param base log base format
   * @return --
   */
  public String genFinalLog(String base) {
    String date = ArkLogPublicUtil.getDate(true, new Date(occurrenceTime));
    String preLog = trace == null ? basicLog : basicLog + trace;
    return String.format(
        base, date, project, type.getIdf(), occurrenceThread, occurrenceClass, preLog);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy