use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class DistributedProgramRunner method logProgramStart.
/**
* Set up Logging Context so the Log is tagged correctly for the Program.
* Reset the context once done.
*/
private void logProgramStart(Program program, ProgramOptions options) {
LoggingContext loggingContext = LoggingContextHelper.getLoggingContext(program.getNamespaceId(), program.getApplicationId(), program.getName(), program.getType(), ProgramRunners.getRunId(options).getId(), options.getArguments().asMap());
Cancellable saveContextCancellable = LoggingContextAccessor.setLoggingContext(loggingContext);
String userArguments = Joiner.on(", ").withKeyValueSeparator("=").join(options.getUserArguments());
LOG.info("Starting {} Program '{}' with Arguments [{}], with debugging {}", program.getType(), program.getName(), userArguments, options.isDebug());
saveContextCancellable.cancel();
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class LogAppenderLogProcessor method process.
@Override
public void process(Iterator<byte[]> loggingEventBytes) {
LoggingEventSerializer serializer = LOGGING_EVENT_SERIALIZER.get();
loggingEventBytes.forEachRemaining(bytes -> {
try {
ILoggingEvent iLoggingEvent = serializer.fromBytes(ByteBuffer.wrap(bytes));
LoggingContext loggingContext = LoggingContextHelper.getLoggingContext(iLoggingEvent.getMDCPropertyMap());
if (loggingContext == null) {
// This shouldn't happen
LOG.debug("Ignore logging event due to missing logging context: {}", iLoggingEvent);
return;
}
logAppender.append(new LogMessage(iLoggingEvent, loggingContext));
} catch (IOException e) {
LOG.warn("Ignore logging event due to decode failure: {}", e.getMessage());
LOG.debug("Ignore logging event stack trace", e);
}
});
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class PreviewRunnerTwillRunnable method doInitialize.
private void doInitialize(TwillContext context) throws Exception {
CConfiguration cConf = CConfiguration.create(new File(getArgument("cConf")).toURI().toURL());
Configuration hConf = new Configuration();
hConf.clear();
hConf.addResource(new File(getArgument("hConf")).toURI().toURL());
PreviewRequestPollerInfo pollerInfo;
if (context instanceof ExtendedTwillContext) {
pollerInfo = new PreviewRequestPollerInfo(context.getInstanceId(), ((ExtendedTwillContext) context).getUID());
} else {
pollerInfo = new PreviewRequestPollerInfo(context.getInstanceId(), null);
}
LOG.debug("Initializing preview runner with poller info {} in total {} runners", pollerInfo, context.getInstanceCount());
Injector injector = createInjector(cConf, hConf, pollerInfo);
// Initialize logging context
logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
logAppenderInitializer.initialize();
LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, PreviewRunnerTwillApplication.NAME);
LoggingContextAccessor.setLoggingContext(loggingContext);
// Optionally get the storage provider. It is for destroy() method to close it on shutdown.
Binding<StorageProvider> storageBinding = injector.getExistingBinding(Key.get(StorageProvider.class));
if (storageBinding != null) {
storageProvider = storageBinding.getProvider().get();
}
previewRunnerManager = injector.getInstance(PreviewRunnerManager.class);
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class SystemWorkerTwillRunnable method doInitialize.
private void doInitialize(TwillContext context) throws Exception {
CConfiguration cConf = CConfiguration.create(new File(getArgument("cConf")).toURI().toURL());
// Overwrite the app fabric temp directory with the task worker temp directory
cConf.set(Constants.CFG_LOCAL_DATA_DIR, cConf.get(Constants.TaskWorker.LOCAL_DATA_DIR));
Configuration hConf = new Configuration();
hConf.clear();
hConf.addResource(new File(getArgument("hConf")).toURI().toURL());
Injector injector = createInjector(cConf, hConf);
// Initialize logging context
logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
logAppenderInitializer.initialize();
metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
metricsCollectionService.startAndWait();
LoggingContext loggingContext = new ServiceLoggingContext(NamespaceId.SYSTEM.getNamespace(), Constants.Logging.COMPONENT_NAME, SystemWorkerTwillApplication.NAME);
LoggingContextAccessor.setLoggingContext(loggingContext);
taskWorker = injector.getInstance(TaskWorkerService.class);
}
use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class MapReduceClassLoader method getTaskContextProvider.
/**
* Returns the {@link MapReduceTaskContextProvider} associated with this ClassLoader.
*/
public MapReduceTaskContextProvider getTaskContextProvider() {
// Logging context needs to be set in main thread.
LoggingContext loggingContext = createMapReduceLoggingContext();
LoggingContextAccessor.setLoggingContext(loggingContext);
synchronized (this) {
taskContextProvider = Optional.fromNullable(taskContextProvider).or(taskContextProviderSupplier);
}
taskContextProvider.startAndWait();
return taskContextProvider;
}
Aggregations