Search in sources :

Example 1 with LoggingContext

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();
}
Also used : LoggingContext(io.cdap.cdap.common.logging.LoggingContext) Cancellable(org.apache.twill.common.Cancellable)

Example 2 with LoggingContext

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);
        }
    });
}
Also used : LoggingContext(io.cdap.cdap.common.logging.LoggingContext) LogMessage(io.cdap.cdap.logging.appender.LogMessage) LoggingEventSerializer(io.cdap.cdap.logging.serialize.LoggingEventSerializer) IOException(java.io.IOException) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 3 with LoggingContext

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);
}
Also used : ExtendedTwillContext(io.cdap.cdap.master.spi.twill.ExtendedTwillContext) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Configuration(org.apache.hadoop.conf.Configuration) SConfiguration(io.cdap.cdap.common.conf.SConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) Injector(com.google.inject.Injector) PreviewRunnerManager(io.cdap.cdap.app.preview.PreviewRunnerManager) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) StorageProvider(io.cdap.cdap.spi.data.StorageProvider) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File) PreviewRequestPollerInfo(io.cdap.cdap.internal.app.runtime.k8s.PreviewRequestPollerInfo)

Example 4 with LoggingContext

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);
}
Also used : LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) Configuration(org.apache.hadoop.conf.Configuration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) Injector(com.google.inject.Injector) ServiceLoggingContext(io.cdap.cdap.common.logging.ServiceLoggingContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) File(java.io.File) TaskWorkerService(io.cdap.cdap.internal.app.worker.TaskWorkerService)

Example 5 with LoggingContext

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;
}
Also used : MapReduceLoggingContext(io.cdap.cdap.logging.context.MapReduceLoggingContext) WorkflowProgramLoggingContext(io.cdap.cdap.logging.context.WorkflowProgramLoggingContext) LoggingContext(io.cdap.cdap.common.logging.LoggingContext)

Aggregations

LoggingContext (io.cdap.cdap.common.logging.LoggingContext)36 Test (org.junit.Test)10 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)9 GET (javax.ws.rs.GET)9 Path (javax.ws.rs.Path)9 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)7 ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)6 LoggingTester (io.cdap.cdap.logging.appender.LoggingTester)6 Injector (com.google.inject.Injector)5 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)5 File (java.io.File)5 Configuration (org.apache.hadoop.conf.Configuration)5 Cancellable (org.apache.twill.common.Cancellable)5 FileLogReader (io.cdap.cdap.logging.read.FileLogReader)4 LogEvent (io.cdap.cdap.logging.read.LogEvent)4 Logger (org.slf4j.Logger)4 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)3 ApplicationLoggingContext (io.cdap.cdap.logging.context.ApplicationLoggingContext)3 MapReduceLoggingContext (io.cdap.cdap.logging.context.MapReduceLoggingContext)3 LoggingEventSerializer (io.cdap.cdap.logging.serialize.LoggingEventSerializer)3