Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
fix: change how logging policy is instantiated
Browse files Browse the repository at this point in the history
  • Loading branch information
melanahammel committed Feb 13, 2020
1 parent 2f8a3bb commit e7605d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
import com.nike.internal.util.StringUtils;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/** Rolling policy that will copy audit logs to S3 if enabled when the logs roll. */
@Slf4j
@Component
public class AuditLogsS3TimeBasedRollingPolicy<E> extends TimeBasedRollingPolicy<E> {

Expand All @@ -36,9 +38,13 @@ public class AuditLogsS3TimeBasedRollingPolicy<E> extends TimeBasedRollingPolicy
@Autowired
public AuditLogsS3TimeBasedRollingPolicy(
@Value("${cerberus.audit.athena.bucket}") String bucket,
@Value("${cerberus.audit.athena.bucketRegion}") String bucketRegion) {
@Value("${cerberus.audit.athena.bucketRegion}") String bucketRegion,
S3LogUploaderService s3LogUploaderService) {
this.bucket = bucket;
this.bucketRegion = bucketRegion;

setS3LogUploaderService(s3LogUploaderService);
log.info("AuditLogsS3TimeBasedRollingPolicy initialized");
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class FiveMinuteRollingFileAppender<E> extends RollingFileAppender<E> {
@Override
public void rollover() {
long currentTime = System.currentTimeMillis();
long maxIntervalSinceLastLoggingInMillis = TimeUnit.MINUTES.toMillis(1);
long maxIntervalSinceLastLoggingInMillis = TimeUnit.MINUTES.toMillis(5);

if ((currentTime - start) >= maxIntervalSinceLastLoggingInMillis) {
super.rollover();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ public S3LogUploaderService(

amazonS3 = s3ClientFactory.getClient(bucketRegion);
log.info("S3 Uploader Service initialized");

// Inject this into the logback rolling policy which was created before guice land exists
getRollingPolicy()
.ifPresent(
policy -> {
log.info("S3 Rolling Policy detected injecting S3 Log Uploader Service");
policy.setS3LogUploaderService(this);
});
}

/** Convenience method for sleeping */
Expand Down Expand Up @@ -201,7 +193,7 @@ public void executeServerShutdownHook() {
*/
private Optional<AuditLogsS3TimeBasedRollingPolicy<ILoggingEvent>> getRollingPolicy() {

log.info("S3 Uploader Service getting rolling policy");
log.info("S3 Uploader Service getting rolling policy for shutdown hooks");

if (athenaLoggingEventListenerEnabled) {
ch.qos.logback.classic.Logger auditLogger =
Expand All @@ -210,7 +202,7 @@ private Optional<AuditLogsS3TimeBasedRollingPolicy<ILoggingEvent>> getRollingPol
FiveMinuteRollingFileAppender<ILoggingEvent> appender =
(FiveMinuteRollingFileAppender<ILoggingEvent>)
auditLogger.getAppender(ATHENA_LOG_APPENDER);
// TODO figure out if appender is always null and when it should not be null

if (appender != null) {
return Optional.ofNullable(
(AuditLogsS3TimeBasedRollingPolicy<ILoggingEvent>) appender.getRollingPolicy());
Expand Down

0 comments on commit e7605d1

Please sign in to comment.