Skip to content

Commit

Permalink
Start on logging (dtinit#483)
Browse files Browse the repository at this point in the history
  • Loading branch information
olsona committed Jul 20, 2018
1 parent 6d2af83 commit 7417288
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout=org.datatransferproject.transfer.logging.EncryptingLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
8 changes: 3 additions & 5 deletions distributions/demo-server/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
log4j.rootLogger=DEBUG, A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
# Print the date in ISO 8601 format
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.rootLogger=DEBUG, consoleAppender, fileAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.datatransferproject.transfer.logging.EncryptingLayout
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ private static RecurrenceRule getRecurrenceRule(List<String> ruleStrings) {
"Recurrence entry " + st + " is not recognizable as an RRULE, RDATE, or EXDATE");
}
}
RecurrenceRule rule = ruleBuilder.build();
logger.debug("RRule: " + rule.getRRule());
logger.debug("RDate: " + rule.getRDate());
logger.debug("ExDate: " + rule.getExDate());
return rule;
return ruleBuilder.build();
}

private static CalendarModel convertToCalendarModel(CalendarListEntry calendarData) {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ okHttpVersion=3.9.1
azureKeyVaultVersion=1.0.0
javaDockerContainer=openjdk:8-jdk
jerseyVersion=2.26
log4jVersion=2.11.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
/** Provides information required to bootstrap extensions. */
public interface ExtensionContext {

/** Returns the system logger extension service can use to record events. */
Logger getLogger();

/**
* Returns the runtime type manager.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@
package org.datatransferproject.api;

import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
import org.datatransferproject.api.launcher.Constants.Environment;
import org.datatransferproject.api.launcher.ExtensionContext;
import org.datatransferproject.api.launcher.Flag;
import org.datatransferproject.api.launcher.Logger;
import org.datatransferproject.api.launcher.TypeManager;
import org.datatransferproject.config.extension.SettingsExtension;

import java.util.HashMap;
import java.util.Map;

/**
* Provides a context for initializing extensions.
*
* <p>
*/
public class ApiExtensionContext implements ExtensionContext {

private final Map<Class<?>, Object> registered = new HashMap<>();
private final TypeManager typeManager;
private final SettingsExtension settingsExtension;
Expand All @@ -57,12 +56,6 @@ public ApiExtensionContext(TypeManager typeManager, SettingsExtension settingsEx
Preconditions.checkNotNull(baseApiUrl, "Required setting 'baseApiUrl' is missing");
}

@Override
public Logger getLogger() {
// TODO implement
return null;
}

@Override
public TypeManager getTypeManager() {
return typeManager;
Expand Down
3 changes: 2 additions & 1 deletion portability-transfer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ dependencies {
// Logging
compile("org.slf4j:slf4j-api:${slf4jVersion}")
compile("org.slf4j:slf4j-log4j12:${slf4jVersion}")

compile("org.apache.logging.log4j:log4j-api:${log4jVersion}")
compile("org.apache.logging.log4j:log4j-core:${log4jVersion}")

testCompile("com.google.truth:truth:${truthVersion}")
testCompile("junit:junit:${junitVersion}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.base.Preconditions;
import java.security.KeyPair;
import java.util.UUID;
import org.datatransferproject.transfer.logging.EncryptingLayout;

/**
* A class that contains metadata for a transfer worker's job.
Expand Down Expand Up @@ -54,6 +55,7 @@ static void init(
dataType = initDataType;
exportService = initExportService;
importService = initImportService;
EncryptingLayout.setJobId(jobId);
}

// TODO: remove this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
import org.slf4j.LoggerFactory;

/**
* Process a job in two steps: <br>
* (1) Decrypt the stored credentials, which have been encrypted with this transfer worker's public
* key<br>
* (2)Run the copy job
* Process a job in two steps: <br> (1) Decrypt the stored credentials, which have been encrypted
* with this transfer worker's public key<br> (2)Run the copy job
*/
final class JobProcessor {

private static final Logger logger = LoggerFactory.getLogger(JobProcessor.class);

private final JobStore store;
Expand All @@ -58,7 +57,9 @@ final class JobProcessor {
this.symmetricKeyGenerator = symmetricKeyGenerator;
}

/** Process our job, whose metadata is available via {@link JobMetadata}. */
/**
* Process our job, whose metadata is available via {@link JobMetadata}.
*/
void processJob() {
UUID jobId = JobMetadata.getJobId();
logger.debug("Begin processing jobId: {}", jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
import java.util.Map;
import org.datatransferproject.api.launcher.Constants.Environment;
import org.datatransferproject.api.launcher.ExtensionContext;
import org.datatransferproject.api.launcher.Logger;
import org.datatransferproject.api.launcher.TypeManager;
import org.datatransferproject.api.launcher.Flag;
import org.datatransferproject.api.launcher.TypeManager;
import org.datatransferproject.config.extension.SettingsExtension;
import org.datatransferproject.launcher.impl.TypeManagerImpl;
import org.datatransferproject.types.transfer.auth.TokenAuthData;
import org.datatransferproject.types.transfer.auth.TokenSecretAuthData;
import org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData;

/** {@link ExtensionContext} used by the transfer worker. */
/**
* {@link ExtensionContext} used by the transfer worker.
*/
public class WorkerExtensionContext implements ExtensionContext {

private final TypeManager typeManager;
private final Map<Class<?>, Object> registered = new HashMap<>();
private final SettingsExtension settingsExtension;
Expand All @@ -54,11 +56,6 @@ public class WorkerExtensionContext implements ExtensionContext {
Preconditions.checkNotNull(environment, "Required setting 'environment' is missing");
}

@Override
public Logger getLogger() {
return null;
}

@Override
public TypeManager getTypeManager() {
return typeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
import static com.google.common.collect.MoreCollectors.onlyElement;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.collect.ImmutableList;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NoSuchElementException;
import org.datatransferproject.api.launcher.ExtensionContext;
Expand All @@ -36,7 +34,6 @@
import org.datatransferproject.spi.transfer.extension.TransferExtension;
import org.datatransferproject.spi.transfer.provider.Exporter;
import org.datatransferproject.spi.transfer.provider.Importer;
import org.datatransferproject.types.transfer.retry.RetryStrategy;
import org.datatransferproject.types.transfer.retry.RetryStrategyLibrary;

final class WorkerModule extends FlagBindingModule {
Expand Down Expand Up @@ -128,4 +125,6 @@ ImmutableList<TransferExtension> getTransferExtensions() {
RetryStrategyLibrary getRetryStrategyLibrary() throws IOException {
return context.getSetting("retryLibrary", null);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.datatransferproject.transfer.logging;

import com.google.common.base.Preconditions;
import java.util.UUID;
import org.apache.log4j.Layout;
import org.apache.log4j.helpers.ISO8601DateFormat;
import org.apache.log4j.spi.LoggingEvent;

public class EncryptingLayout extends Layout {

static UUID jobId;

public static void setJobId(UUID inputJobId) {
Preconditions.checkState(jobId == null, "jobId has already been set");
jobId = inputJobId;
}

@Override
public String format(LoggingEvent event) {
// TODO: read formatting from a config file
return String.format("[%s] [%s]: %s - %s%s",
new ISO8601DateFormat().format(event.timeStamp),
jobId != null ? Long.toHexString(jobId.getMostSignificantBits()) : "undefined",
event.getLevel().toString(),
event.getRenderedMessage(), LINE_SEP);
}

@Override
public boolean ignoresThrowable() {
return true;
}

@Override
public void activateOptions() {
}
}

0 comments on commit 7417288

Please sign in to comment.