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);
}
}
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)));
}
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);
}
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();
});
}
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);
});
}
Aggregations