Commit 861fd5c0 authored by Preksha Beohar-Slb's avatar Preksha Beohar-Slb
Browse files

Update method and formatting

parent e38ddcfc
Pipeline #49581 passed with stages
in 5 minutes and 5 seconds
......@@ -20,7 +20,7 @@
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.10.0-test</version>
<version>0.10.0-SNAPSHOT</version>
<packaging>jar</packaging>
......
......@@ -34,127 +34,125 @@ import java.util.Map;
@RequestScope
public class JaxRsDpsLog implements AutoCloseable {
@Value("${LOG_PREFIX}")
@Value("${LOG_PREFIX}")
private String LOG_PREFIX;
private ILogger log;
private DpsHeaders headers;
@Inject
public JaxRsDpsLog(ILogger log, DpsHeaders headers){
this.log = log;
this.headers = headers;
}
private ILogger log;
private DpsHeaders headers;
public void audit(AuditPayload auditPayload) {
log.audit(LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
public void audit(final String loggerName, final AuditPayload auditPayload) {
log.audit(loggerName, LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
public void audit(final AuditPayload auditPayload, final LogLevel logLevel) {
if (logLevel.equals(LogLevel.DEBUG) ){
log.auditDebugLog(LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
}
public void request(Request httpRequest) {
log.request(LOG_PREFIX + ".request", httpRequest, this.getLabels());
}
public void request(final String loggerName, final Request httpRequest) {
log.request(loggerName, LOG_PREFIX + ".request", httpRequest, this.getLabels());
}
public void info(String message) {
log.info(LOG_PREFIX + ".app", message, this.getLabels());
}
public void info(final String loggerName, final String message) {
log.info(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void debug(String message) {
log.debug(LOG_PREFIX + ".app", message, this.getLabels());
}
public void debug(final String loggerName, final String message) {
log.debug(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void warning(String message) {
log.warning(LOG_PREFIX + ".app", message, this.getLabels());
}
public void warning(final String loggerName, final String message) {
log.warning(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
private String prepareWarningMessage(List<String> messages) {
int sn = 0;
StringBuilder sb = new StringBuilder();
for (String s : messages) {
sb.append(String.format("%d: %s", sn++, s)).append(System.lineSeparator());
}
return sb.toString();
}
public void warning(List<String> messages) {
if (messages == null || messages.isEmpty()) {
return;
}
log.warning(LOG_PREFIX + ".app", prepareWarningMessage(messages), this.getLabels());
}
public void warning(final String loggerName, final List<String> messages) {
if (messages == null || messages.isEmpty()) {
return;
}
log.warning(loggerName, LOG_PREFIX + ".app", prepareWarningMessage(messages), this.getLabels());
}
public void warning(String message, Exception e) {
log.warning(LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void warning(final String loggerName, final String message, final Exception e) {
log.warning(loggerName, LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void error(String message) {
log.error(LOG_PREFIX + ".app", message, this.getLabels());
}
public void error(final String loggerName, final String message) {
log.error(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void error(String message, Exception e) {
log.error(LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void error(final String loggerName, final String message, final Exception e) {
log.error(loggerName, LOG_PREFIX + ".app", message, e, this.getLabels());
}
@Override
public void close() throws Exception {
}
private Map<String, String> getLabels() {
Map<String, String> out;
if (headers != null) {
out = LogUtils.createStandardLabelsFromMap(headers.getHeaders());
if (out.containsKey(AppEngineHeaders.TASK_RETRY_COUNT)) {
out.put(AppEngineHeaders.TASK_RETRY_COUNT, StringUtils.join(out.get(AppEngineHeaders.TASK_RETRY_COUNT), ','));
}
return out;
}
return Collections.emptyMap();
}
@Inject
public JaxRsDpsLog(ILogger log, DpsHeaders headers) {
this.log = log;
this.headers = headers;
}
public void audit(AuditPayload auditPayload) {
log.audit(LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
public void audit(final String loggerName, final AuditPayload auditPayload) {
log.audit(loggerName, LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
public void auditDebug(final AuditPayload auditPayload) {
log.auditDebugLog(LOG_PREFIX + ".audit", auditPayload, this.getLabels());
}
public void request(Request httpRequest) {
log.request(LOG_PREFIX + ".request", httpRequest, this.getLabels());
}
public void request(final String loggerName, final Request httpRequest) {
log.request(loggerName, LOG_PREFIX + ".request", httpRequest, this.getLabels());
}
public void info(String message) {
log.info(LOG_PREFIX + ".app", message, this.getLabels());
}
public void info(final String loggerName, final String message) {
log.info(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void debug(String message) {
log.debug(LOG_PREFIX + ".app", message, this.getLabels());
}
public void debug(final String loggerName, final String message) {
log.debug(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void warning(String message) {
log.warning(LOG_PREFIX + ".app", message, this.getLabels());
}
public void warning(final String loggerName, final String message) {
log.warning(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
private String prepareWarningMessage(List<String> messages) {
int sn = 0;
StringBuilder sb = new StringBuilder();
for (String s : messages) {
sb.append(String.format("%d: %s", sn++, s)).append(System.lineSeparator());
}
return sb.toString();
}
public void warning(List<String> messages) {
if (messages == null || messages.isEmpty()) {
return;
}
log.warning(LOG_PREFIX + ".app", prepareWarningMessage(messages), this.getLabels());
}
public void warning(final String loggerName, final List<String> messages) {
if (messages == null || messages.isEmpty()) {
return;
}
log.warning(loggerName, LOG_PREFIX + ".app", prepareWarningMessage(messages), this.getLabels());
}
public void warning(String message, Exception e) {
log.warning(LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void warning(final String loggerName, final String message, final Exception e) {
log.warning(loggerName, LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void error(String message) {
log.error(LOG_PREFIX + ".app", message, this.getLabels());
}
public void error(final String loggerName, final String message) {
log.error(loggerName, LOG_PREFIX + ".app", message, this.getLabels());
}
public void error(String message, Exception e) {
log.error(LOG_PREFIX + ".app", message, e, this.getLabels());
}
public void error(final String loggerName, final String message, final Exception e) {
log.error(loggerName, LOG_PREFIX + ".app", message, e, this.getLabels());
}
@Override
public void close() throws Exception {
}
private Map<String, String> getLabels() {
Map<String, String> out;
if (headers != null) {
out = LogUtils.createStandardLabelsFromMap(headers.getHeaders());
if (out.containsKey(AppEngineHeaders.TASK_RETRY_COUNT)) {
out.put(AppEngineHeaders.TASK_RETRY_COUNT, StringUtils.join(out.get(AppEngineHeaders.TASK_RETRY_COUNT), ','));
}
return out;
}
return Collections.emptyMap();
}
}
......@@ -104,9 +104,9 @@ public class JaxRsDpsLogTest {
}
@Test
public void testAuditWithLogLevel() {
public void testAuditWithDebugLogLevel() {
doNothing().when(logger).audit(eq(AUDIT_LOG_PREFIX), eq(auditPayload), eq(headers));
jaxRsDpsLog.audit(auditPayload, LogLevel.DEBUG);
jaxRsDpsLog.auditDebug(auditPayload);
verify(logger, times(1)).auditDebugLog(eq(AUDIT_LOG_PREFIX), eq(auditPayload), eq(headers));
verify(dpsHeaders, times(1)).getHeaders();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment