use of org.apache.logging.log4j.core.Appender in project camel by apache.
the class LogBodyWithNewLineTest method setUp.
public void setUp() throws Exception {
super.setUp();
writer = new StringWriter();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Appender appender = WriterAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).build()).setTarget(writer).setName("Writer").build();
appender.start();
config.addAppender(appender);
config.getRootLogger().removeAppender("Writer");
config.getRootLogger().addAppender(appender, Level.INFO, null);
ctx.updateLoggers();
}
use of org.apache.logging.log4j.core.Appender 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 in project torodb by torodb.
the class Log4jUtils method appendToLogFile.
public static void appendToLogFile(String logFile) {
LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
Configuration configuration = coreContext.getConfiguration();
final Layout<? extends Serializable> layout = PatternLayout.newBuilder().withConfiguration(configuration).withPattern("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n").build();
final Appender appender = FileAppender.createAppender(logFile, "false", "false", "File", "true", "false", null, null, layout, null, "false", null, configuration);
appender.start();
for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
configuration.addLoggerAppender(coreContext.getLogger(loggerConfig.getName()), appender);
}
}
use of org.apache.logging.log4j.core.Appender 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 in project HikariCP by brettwooldridge.
the class TestElf method setSlf4jTargetStream.
static void setSlf4jTargetStream(Class<?> clazz, PrintStream stream) {
try {
Log4jLogger log4Jlogger = (Log4jLogger) LoggerFactory.getLogger(clazz);
Field field = clazz.getClassLoader().loadClass("org.apache.logging.slf4j.Log4jLogger").getDeclaredField("logger");
field.setAccessible(true);
Logger logger = (Logger) field.get(log4Jlogger);
if (logger.getAppenders().containsKey("string")) {
Appender appender = logger.getAppenders().get("string");
logger.removeAppender(appender);
}
logger.addAppender(new StringAppender("string", stream));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations