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

com.scmspain.karyon.accesslog.formatters.CombinedApacheLog Maven / Gradle / Ivy

The newest version!
package com.scmspain.karyon.accesslog.formatters;

import com.google.inject.Inject;
import com.scmspain.karyon.accesslog.AccessLog;

public class CombinedApacheLog implements AccessLogFormatter {

  private CommonApacheLog commonApacheLogFormatter;

  @Inject
  CombinedApacheLog(CommonApacheLog commonApacheLogFormatter) {
    this.commonApacheLogFormatter = commonApacheLogFormatter;
  }

  @Override
  public String format(AccessLog logLine) {
    return String.format(
      "%s \"%s\" \"%s\"",
      commonApacheLogFormatter.format(logLine),
      valueOrDefault(logLine.referer()),
      valueOrDefault(logLine.userAgent())
    );
  }

  private String valueOrDefault(String value) {
    return (null != value && !value.isEmpty()) ? value : "-";
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy