Search in sources :

Example 1 with FileAppender

use of org.apache.logging.log4j.core.appender.FileAppender in project hive by apache.

the class PartialScanTask method main.

public static void main(String[] args) {
    String inputPathStr = null;
    String outputDir = null;
    String jobConfFileName = null;
    try {
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-input")) {
                inputPathStr = args[++i];
            } else if (args[i].equals("-jobconffile")) {
                jobConfFileName = args[++i];
            } else if (args[i].equals("-outputDir")) {
                outputDir = args[++i];
            }
        }
    } catch (IndexOutOfBoundsException e) {
        System.err.println("Missing argument to option");
        printUsage();
    }
    if (inputPathStr == null || outputDir == null || outputDir.trim().equals("")) {
        printUsage();
    }
    List<Path> inputPaths = new ArrayList<Path>();
    String[] paths = inputPathStr.split(INPUT_SEPERATOR);
    if (paths == null || paths.length == 0) {
        printUsage();
    }
    FileSystem fs = null;
    JobConf conf = new JobConf(PartialScanTask.class);
    for (String path : paths) {
        try {
            Path pathObj = new Path(path);
            if (fs == null) {
                fs = FileSystem.get(pathObj.toUri(), conf);
            }
            FileStatus fstatus = fs.getFileStatus(pathObj);
            if (fstatus.isDir()) {
                FileStatus[] fileStatus = fs.listStatus(pathObj);
                for (FileStatus st : fileStatus) {
                    inputPaths.add(st.getPath());
                }
            } else {
                inputPaths.add(fstatus.getPath());
            }
        } catch (IOException e) {
            e.printStackTrace(System.err);
        }
    }
    if (jobConfFileName != null) {
        conf.addResource(new Path(jobConfFileName));
    }
    org.slf4j.Logger LOG = LoggerFactory.getLogger(PartialScanTask.class.getName());
    boolean isSilent = HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVESESSIONSILENT);
    LogHelper console = new LogHelper(LOG, isSilent);
    // that it's easy to find reason for local mode execution failures
    for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
        if (appender instanceof FileAppender) {
            console.printInfo("Execution log at: " + ((FileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            console.printInfo("Execution log at: " + ((RollingFileAppender) appender).getFileName());
        }
    }
    QueryState queryState = new QueryState(new HiveConf(conf, PartialScanTask.class));
    PartialScanWork mergeWork = new PartialScanWork(inputPaths);
    DriverContext driverCxt = new DriverContext();
    PartialScanTask taskExec = new PartialScanTask();
    taskExec.initialize(queryState, null, driverCxt, new CompilationOpContext());
    taskExec.setWork(mergeWork);
    int ret = taskExec.execute(driverCxt);
    if (ret != 0) {
        System.exit(2);
    }
}
Also used : DriverContext(org.apache.hadoop.hive.ql.DriverContext) FileStatus(org.apache.hadoop.fs.FileStatus) LogHelper(org.apache.hadoop.hive.ql.session.SessionState.LogHelper) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) ArrayList(java.util.ArrayList) FileSystem(org.apache.hadoop.fs.FileSystem) HiveConf(org.apache.hadoop.hive.conf.HiveConf) JobConf(org.apache.hadoop.mapred.JobConf) Path(org.apache.hadoop.fs.Path) Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) IOException(java.io.IOException) QueryState(org.apache.hadoop.hive.ql.QueryState) CompilationOpContext(org.apache.hadoop.hive.ql.CompilationOpContext)

Example 2 with FileAppender

use of org.apache.logging.log4j.core.appender.FileAppender in project logging-log4j2 by apache.

the class CustomConfigurationTest method testConfig.

@Test
public void testConfig() {
    // don't bother using "error" since that's the default; try another level
    final LoggerContext ctx = this.init.getLoggerContext();
    ctx.reconfigure();
    final Configuration config = ctx.getConfiguration();
    assertThat(config, instanceOf(XmlConfiguration.class));
    for (final StatusListener listener : StatusLogger.getLogger().getListeners()) {
        if (listener instanceof StatusConsoleListener) {
            assertSame(listener.getStatusLevel(), Level.INFO);
            break;
        }
    }
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).withConfiguration(config).build();
    // @formatter:off
    final FileAppender appender = FileAppender.newBuilder().withFileName(LOG_FILE).withAppend(false).withName("File").withIgnoreExceptions(false).withBufferSize(4000).withBufferedIo(false).withLayout(layout).build();
    // @formatter:on
    appender.start();
    config.addAppender(appender);
    final AppenderRef ref = AppenderRef.createAppenderRef("File", null, null);
    final AppenderRef[] refs = new AppenderRef[] { ref };
    final LoggerConfig loggerConfig = LoggerConfig.createLogger(false, Level.INFO, "org.apache.logging.log4j", "true", refs, null, config, null);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger("org.apache.logging.log4j", loggerConfig);
    ctx.updateLoggers();
    final Logger logger = ctx.getLogger(CustomConfigurationTest.class.getName());
    logger.info("This is a test");
    final File file = new File(LOG_FILE);
    assertThat(file, exists());
    assertThat(file, hasLength(greaterThan(0L)));
}
Also used : FileAppender(org.apache.logging.log4j.core.appender.FileAppender) XmlConfiguration(org.apache.logging.log4j.core.config.xml.XmlConfiguration) XmlConfiguration(org.apache.logging.log4j.core.config.xml.XmlConfiguration) Logger(org.apache.logging.log4j.Logger) StatusLogger(org.apache.logging.log4j.status.StatusLogger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) StatusConsoleListener(org.apache.logging.log4j.status.StatusConsoleListener) StatusListener(org.apache.logging.log4j.status.StatusListener) File(java.io.File) Test(org.junit.Test)

Example 3 with FileAppender

use of org.apache.logging.log4j.core.appender.FileAppender in project logging-log4j2 by apache.

the class CustomLevelsWithFiltersTest method testConfiguration.

@Test
public void testConfiguration() {
    final Configuration configuration = context.getConfiguration();
    assertNotNull(configuration);
    final FileAppender appender = configuration.getAppender("info");
    assertNotNull(appender);
    final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
    assertNotNull(compFilter);
    final Filter[] filters = compFilter.getFiltersArray();
    assertNotNull(filters);
    boolean foundLevel = false;
    for (final Filter filter : filters) {
        final ThresholdFilter tFilter = (ThresholdFilter) filter;
        if (infom1Level.equals(tFilter.getLevel())) {
            foundLevel = true;
            break;
        }
    }
    Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
Also used : FileAppender(org.apache.logging.log4j.core.appender.FileAppender) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) CompositeFilter(org.apache.logging.log4j.core.filter.CompositeFilter) Configuration(org.apache.logging.log4j.core.config.Configuration) CompositeFilter(org.apache.logging.log4j.core.filter.CompositeFilter) ThresholdFilter(org.apache.logging.log4j.core.filter.ThresholdFilter) Test(org.junit.Test)

Example 4 with FileAppender

use of org.apache.logging.log4j.core.appender.FileAppender in project cas by apereo.

the class LoggingOutputSocketMessagingController method registerLogFileTailThreads.

private void registerLogFileTailThreads() throws IOException {
    final Collection<String> outputFileNames = new HashSet<>();
    final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values();
    loggerAppenders.forEach(appender -> {
        if (appender instanceof FileAppender) {
            outputFileNames.add(((FileAppender) appender).getFileName());
        } else if (appender instanceof RandomAccessFileAppender) {
            outputFileNames.add(((RandomAccessFileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            outputFileNames.add(((RollingFileAppender) appender).getFileName());
        } else if (appender instanceof MemoryMappedFileAppender) {
            outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName());
        } else if (appender instanceof RollingRandomAccessFileAppender) {
            outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName());
        }
    });
    outputFileNames.forEach(s -> {
        final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true);
        final Thread thread = new Thread(t);
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.setName(s);
        thread.start();
    });
}
Also used : RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Appender(org.apache.logging.log4j.core.Appender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) Tailer(org.apache.commons.io.input.Tailer) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) File(java.io.File) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet)

Example 5 with FileAppender

use of org.apache.logging.log4j.core.appender.FileAppender in project cas by apereo.

the class LoggingOutputTailingService method registerLogFileTailersForExecution.

private void registerLogFileTailersForExecution(final LoggerContext loggerContext) {
    final Collection<String> outputFileNames = new HashSet<>();
    final Collection<Appender> loggerAppenders = loggerContext.getConfiguration().getAppenders().values();
    loggerAppenders.forEach(appender -> {
        if (appender instanceof FileAppender) {
            outputFileNames.add(FileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RandomAccessFileAppender) {
            outputFileNames.add(RandomAccessFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            outputFileNames.add(RollingFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof MemoryMappedFileAppender) {
            outputFileNames.add(MemoryMappedFileAppender.class.cast(appender).getFileName());
        } else if (appender instanceof RollingRandomAccessFileAppender) {
            outputFileNames.add(RollingRandomAccessFileAppender.class.cast(appender).getFileName());
        }
    });
    outputFileNames.forEach(f -> {
        final Tailer t = new Tailer(new File(f), this, 100L, false, true);
        this.tailers.add(t);
        this.taskExecutor.execute(t);
    });
}
Also used : RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) Appender(org.apache.logging.log4j.core.Appender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) MemoryMappedFileAppender(org.apache.logging.log4j.core.appender.MemoryMappedFileAppender) Tailer(org.apache.commons.io.input.Tailer) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) File(java.io.File) RollingRandomAccessFileAppender(org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender) HashSet(java.util.HashSet)

Aggregations

FileAppender (org.apache.logging.log4j.core.appender.FileAppender)23 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)12 Appender (org.apache.logging.log4j.core.Appender)11 LoggerContext (org.apache.logging.log4j.core.LoggerContext)8 Configuration (org.apache.logging.log4j.core.config.Configuration)8 RollingRandomAccessFileAppender (org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender)6 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)6 File (java.io.File)5 MemoryMappedFileAppender (org.apache.logging.log4j.core.appender.MemoryMappedFileAppender)5 RandomAccessFileAppender (org.apache.logging.log4j.core.appender.RandomAccessFileAppender)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 Logger (org.slf4j.Logger)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)2 Set (java.util.Set)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Tailer (org.apache.commons.io.input.Tailer)2