本文整理汇总了Java中org.apache.log4j.ConsoleAppender类的典型用法代码示例。如果您正苦于以下问题:Java ConsoleAppender类的具体用法?Java ConsoleAppender怎么用?Java ConsoleAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleAppender类属于org.apache.log4j包,在下文中一共展示了ConsoleAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpClass
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws Exception {
//Configure log4j
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
Logger.getRootLogger().addAppender(console);
System.out.println("SETUP: Starting SPLGroundControl...");
config.init(args);
daemon.init(new SPLGroundControl.SPLDaemonContext(args));
daemon.start();
}
示例2: setupLogging
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
private void setupLogging() {
LogManager.getLogManager().reset();
Logger.getRootLogger().getLoggerRepository().resetConfiguration();
final Logger rootLogger = Logger.getRootLogger();
final PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
final Level level = endPointHealthConfiguration.logLevel();
final ConsoleAppender consoleAppender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_ERR);
consoleAppender.setThreshold(level);
consoleAppender.activateOptions();
final FileAppender fileAppender = new FileAppender();
fileAppender.setFile(endPointHealthConfiguration.logFile().getAbsolutePath());
fileAppender.setLayout(layout);
fileAppender.setThreshold(level);
fileAppender.setAppend(true);
fileAppender.setErrorHandler(new FallbackAppenderErrorHandler(rootLogger, fileAppender, consoleAppender));
rootLogger.addAppender(fileAppender);
fileAppender.activateOptions();
}
示例3: setUp
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public void setUp() {
Logger root = Logger.getRootLogger();
root.setLevel(Level.DEBUG);
root.addAppender(new ConsoleAppender(
new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
// setup TLS properties
System.setProperty( "javax.net.ssl.keyStore", TlsTest.class.getResource("testkeys").getPath() );
System.setProperty( "javax.net.ssl.trustStore", TlsTest.class.getResource("testkeys").getPath() );
System.setProperty( "javax.net.ssl.keyStorePassword", "passphrase" );
System.setProperty( "javax.net.ssl.keyStoreType", "jks" );
this.shootist = new BadShootist();
this.shootme = new BadShootme();
shootist.setSocketDisconnectWorstCase(true);
shootme.setSocketDisconnectWorstCase(true);
this.shootme.init();
}
示例4: 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);
}
示例5: setUpConfigLogger
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
private static void setUpConfigLogger(File pathF, String configName) throws IOException {
Logger.getRootLogger().removeAllAppenders();
String nameSuffix = configName.replace(".txt", "");
PropertyConfigurator.configure("resource/log4jproperties.txt");
FileAppender logFileAppender = new FileAppender(
new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"),
new File(pathF, "log_" + nameSuffix + ".txt").toString(), false);
Logger.getRootLogger().addAppender(logFileAppender);
if (opt.logToConsole)
Logger.getRootLogger().addAppender(new ConsoleAppender(
new PatternLayout("%-4r [%t] %-5p %c %x - %m%n")));
}
示例6: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%d{MM-dd HH:mm:ss,SSS} [%t] %5p: %m%n")));
Logger.getRootLogger().setLevel(Level.DEBUG);
final RecoveryMessage recoveryMessage = new RecoveryMessage("GROUP1~1~ADD~data1");
final RecoveryMessage recoveryMessage2 = new RecoveryMessage("GROUP1~1~ADD~data1");
Service service = new Service(Arrays.asList("GROUP1", "GROUP2"), 10);
service.process(recoveryMessage);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(() -> {
IntStream.rangeClosed(0, 5000)
.mapToObj(count -> new RecoveryMessage("GROUP1~" + count + "~ADD~data2"))
.forEach(service::process);
Logger.getRootLogger().info("Recovery done");
});
service.process(recoveryMessage2);
service.start();
executorService.shutdown();
Utils.simulateWork(TimeUnit.SECONDS.toMillis(2));
}
示例7: init
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void init(CmpSqlResultsConfig cmpSqlResultsConfig) {
log.debug("Initializing logger / printer ...");
ConsoleAppender consoleAppender = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
if (cmpSqlResultsConfig.getLogger() != null && cmpSqlResultsConfig.getLogger().getLogLevel() !=
null && !cmpSqlResultsConfig.getLogger().getLogLevel().isEmpty()) {
Logger.getRootLogger().setLevel(Level.toLevel(cmpSqlResultsConfig.getLogger().getLogLevel()));
}
if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
consoleAppender.setLayout(new PatternLayout("%m%n"));
}
consoleAppender.addFilter(new Filter() {
@Override
public int decide(LoggingEvent loggingEvent) {
if(loggingEvent.getMessage() instanceof String == false) return ACCEPT;
boolean isTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.TC);
// before threads (and buffering messages for TC) we allowed "common" logs
// boolean isNotTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.NOT_TC);
if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
return isTCMsg ? ACCEPT : DENY;
// return isNotTCMsg ? DENY : ACCEPT;
} else {
return isTCMsg ? DENY : ACCEPT;
}
}
});
}
示例8: configureLogging
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
/**
* Configures the logger.
*/
private static void configureLogging() {
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%-5p] [%c] - %m%n");
ConsoleAppender console = new ConsoleAppender();
console.setLayout(layout);
console.setThreshold(Level.INFO);
console.activateOptions();
DailyRollingFileAppender file = new DailyRollingFileAppender();
file.setFile("log/app.log");
file.setDatePattern("'.'yyyy-MM-dd");
file.setLayout(layout);
file.activateOptions();
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
logger.addAppender(console);
logger.addAppender(file);
}
示例9: addAppender
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void addAppender() {
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
String logFile = getConfHome() + System.getProperty("file.separator") + "zoofx.log";
fa.setFile(logFile);
Enumeration<Appender> allAppenders = Logger.getRootLogger().getAllAppenders();
if(allAppenders.hasMoreElements()){
Appender appender = allAppenders.nextElement();
if(appender instanceof ConsoleAppender){
ConsoleAppender ca = (ConsoleAppender)appender;
fa.setLayout(ca.getLayout());
fa.setThreshold(ca.getThreshold());
}
fa.setAppend(true);
}
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
}
示例10: initializeLogger
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
/**
* Initializes console logger for tests. Sets the logger level to
* {@link Level#ERROR} by default. If the VM property <i>logOutputLevel</i>
* is specified, it is used to determine the logger level.
*/
public static void initializeLogger() {
Logger.getRootLogger().setLevel(Level.ERROR);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger()
.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %d{HH:mm:ss,SSS} %-30C{1} - %m%n")));
String outputLevelProperty = System.getProperty(VM_ARGUMENT_LOG_OUTPUT_LEVEL);
if (outputLevelProperty != null) {
if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
Logger.getRootLogger().addAppender(new ConsoleAppender());
}
Logger.getRootLogger().setLevel(Level.toLevel(outputLevelProperty));
} else {
Logger.getRootLogger().setLevel(Level.ERROR);
}
}
示例11: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main (String[] args) {
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
ClientConnectorLocal client = new ClientConnectorBeanWIKIHom();
log.info("Setup done. Building index...");
// client.addFirstDocuments("/home/bernardo/Desktop/enwiki-latest-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/ptwiki-20121027-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/eswiki-20121018-pages-articles.xml");
// log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
log.info("Query finished!");
}
示例12: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main (String[] args) throws Exception{
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
PrototypeClientConnector client = new PrototypeClientConnector();
log.info("Setup done. Building index...");
File f = new File("/Users/bernardo/Dropbox/WorkspacePHD/CryptoSearchCloud/docs");
client.addFirstDocuments(f.listFiles());
log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
// query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
query(client, "rTp");
log.info("Query finished!");
}
示例13: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main (String[] args) {
log.addAppender(new ConsoleAppender(new PatternLayout("%d{ABSOLUTE} %-5p [%c{1}] %m%n")));
log.setLevel(Level.INFO);
ClientConnectorLocal client = new ClientConnectorBeanWIKI();
log.info("Setup done. Building index...");
// client.addFirstDocuments("/home/bernardo/Desktop/enwiki-latest-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/ptwiki-20121027-pages-articles.xml");
// client.addFirstDocuments("/home/bernardo/Desktop/eswiki-20121018-pages-articles.xml");
// log.info("Index Finished!");
client.rebuildIndex();
log.info("Starting query...");
query(client, "IETF payload optimize retransmit threshold RFC protocol trusted network address");
// query(client, "IETF payload optimize retransmit threshold");
// query(client, "IETF payload");
log.info("Query finished!");
}
示例14: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main(final String[] args) throws IOException {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%r %d{ISO8601} [%t] %p %c %x - %m%n")));
final String host = Wizard.host;
final String realm = "olga";
logger.info("begin");
final List<Country> countries = CityInitParser.getCountries(host, realm);
logger.info("countries.size = {}", countries.size());
final List<Region> regions = CityInitParser.getRegions(host, realm);
logger.info("regions.size = {}", regions.size());
final List<City> cities = CityListParser.fillWealthIndex(host, realm, regions);
logger.info("cities.size = {}", cities.size());
final List<Product> materials = ProductInitParser.getManufactureProducts(host, realm);
logger.info("materials.size = {}", materials.size());
logger.info("парсим транспортные расходы, {}", materials.size() * cities.size());
TransportParser.setRowsOnPage(host, realm, Math.max(400, cities.size()), cities.get(0), materials.get(0));
final List<Transport> list = TransportParser.parseTransport(host, realm, cities, cities.get(0), materials.get(0));
logger.info(Utils.getPrettyGson(list));
logger.info("list.size = {}", list.size());
}
示例15: main
import org.apache.log4j.ConsoleAppender; //导入依赖的package包/类
public static void main(final String[] args) throws IOException {
BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%r %d{ISO8601} [%t] %p %c %x - %m%n")));
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/15751");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/422209");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/2425");
// final Document doc = Downloader.getDoc(Wizard.host + "olga/main/industry/unit_type/info/2417");
final String host = Wizard.host;
final String realm = "olga";
final String url = host + realm + "/main/industry/unit_type/info/";
final List<Manufacture> manufactures = new ArrayList<>();
// manufactures.add(new Manufacture("423140", "manufactureCategory", "caption"));
// manufactures.add(new Manufacture("2425", "manufactureCategory", "caption"));
manufactures.add(new Manufacture("2438", "manufactureCategory", "caption", new ArrayList<>()));
final Map<String, List<ProductRecipe>> result = getProductRecipes(host, realm, manufactures);
logger.info(Utils.getPrettyGson(result));
}