本文整理汇总了Java中org.apache.log4j.ConsoleAppender.setWriter方法的典型用法代码示例。如果您正苦于以下问题:Java ConsoleAppender.setWriter方法的具体用法?Java ConsoleAppender.setWriter怎么用?Java ConsoleAppender.setWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.ConsoleAppender
的用法示例。
在下文中一共展示了ConsoleAppender.setWriter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public static void main(String[] args) throws TaskExecutionException {
ConsoleAppender ca = new ConsoleAppender();
ca.setWriter(new OutputStreamWriter(System.out));
ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
ca.setThreshold(Level.TRACE);
logger.getRootLogger().addAppender(ca);
final MarkLogicMonitor monitor = new MarkLogicMonitor();
final Map<String, String> taskArgs = new HashMap<String, String>();
taskArgs.put("config-file", "src/main/resources/conf/config.yml");
taskArgs.put("metrics-file", "src/main/resources/conf/metrics.xml");
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
monitor.execute(taskArgs, null);
} catch (Exception e) {
logger.error("Error while running the task", e);
}
}
}, 2, 30, TimeUnit.SECONDS);
}
示例2: main
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public static void main(String[] args) throws TaskExecutionException {
ConsoleAppender ca = new ConsoleAppender();
ca.setWriter(new OutputStreamWriter(System.out));
ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
ca.setThreshold(Level.DEBUG);
logger.getRootLogger().addAppender(ca);
final Map<String, String> taskArgs = new HashMap<String, String>();
taskArgs.put(CONFIG_ARG, "/Users/Muddam/AppDynamics/Code/extensions/kafka-monitoring-extension/src/main/resources/config/config.yml");
final KafkaMonitor monitor = new KafkaMonitor();
//monitor.execute(taskArgs, null);
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
monitor.execute(taskArgs, null);
} catch (Exception e) {
logger.error("Error while running the Task ", e);
}
}
}, 2, 60, TimeUnit.SECONDS);
}
示例3: Configuration
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public Configuration() {
SecureRandom random = new SecureRandom();
this.log4jLogger = Logger.getLogger("Logger"+ random.nextInt());
//this.log4jLogger.removeAllAppenders();
ConsoleAppender appender = new ConsoleAppender();
appender.setWriter(new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8)));
appender.setLayout(new PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN));
this.log4jLogger.addAppender(appender);
this.log4jLogger.setLevel(Level.OFF);
}
示例4: getConsoleAppender
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
/**
* Create a console appender that will catch the SoapUI messages.
*
* @return with the appender.
*/
public ConsoleAppender getConsoleAppender() {
ConsoleAppender appender = new ConsoleAppender();
appender.setWriter(stringWriter);
appender.setLayout(patternLayout);
return appender;
}