本文整理汇总了Java中org.apache.log4j.ConsoleAppender.setLayout方法的典型用法代码示例。如果您正苦于以下问题:Java ConsoleAppender.setLayout方法的具体用法?Java ConsoleAppender.setLayout怎么用?Java ConsoleAppender.setLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.ConsoleAppender
的用法示例。
在下文中一共展示了ConsoleAppender.setLayout方法的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: 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);
}
示例3: 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;
}
}
});
}
示例4: 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);
}
示例5: 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);
}
示例6: prepareExperimentLog
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
protected void prepareExperimentLog(BilinearLearnerParameters params) throws IOException {
ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "[%p->%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
// add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
File expRoot = prepareExperimentRoot();
IOUtils.write(params, new DataOutputStream(new FileOutputStream(new File(expRoot,PARAMS_DATA_NAME))));
IOUtils.writeASCII(new File(expRoot,PARAMS_NAME), params);
File logFile = new File(expRoot,"log");
if(logFile.exists())logFile.delete();
FileAppender file = new FileAppender(new PatternLayout(PATTERN), logFile.getAbsolutePath());
file.setThreshold(Level.DEBUG);
file.activateOptions();
Logger.getRootLogger().addAppender(file );
}
示例7: prepareExperimentLog
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
protected void prepareExperimentLog() throws IOException {
final ConsoleAppender console = new ConsoleAppender(); // create
// appender
// configure the appender
final String PATTERN = "[%p->%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.INFO);
console.activateOptions();
// add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
final File expRoot = prepareExperimentRoot();
final File logFile = new File(expRoot, "log");
if (logFile.exists())
logFile.delete();
final String TIMED_PATTERN = "[%d{HH:mm:ss} %p->%C{1}] %m%n";
final FileAppender file = new FileAppender(new PatternLayout(TIMED_PATTERN), logFile.getAbsolutePath());
file.setThreshold(Level.DEBUG);
file.activateOptions();
Logger.getRootLogger().addAppender(file);
logger.info("Experiment root: " + expRoot);
}
示例8: errorOnlyConsole
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public static void errorOnlyConsole() {
LogManager.resetConfiguration();
final PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%-5p %c %x: %m%n");
final ConsoleAppender dst = new ConsoleAppender();
dst.setLayout(layout);
dst.setTarget("System.err");
dst.setThreshold(Level.ERROR);
dst.activateOptions();
final Logger root = LogManager.getRootLogger();
root.removeAllAppenders();
root.addAppender(dst);
}
示例9: getLogger
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
/**
* Singleton pattern for logger
* Adds a <code>ConsoleAppender</code> on initialization
* @return <code>Logger</code>
*/
public static Logger getLogger() {
if(logger == null) {
logger = Logger.getRootLogger();
ConsoleAppender appender = new ConsoleAppender();
appender.setLayout(new PatternLayout("[%-5p] %d{HH:mm:ss.SSS} [%t] - %m %n"));
appender.setThreshold(Level.ALL);
appender.activateOptions();
logger.addAppender(appender);
}
return logger;
}
示例10: setUp
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public void setUp() {
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" );
ConsoleAppender console = new ConsoleAppender();
console.setName("Console app");
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
Logger.getRootLogger().addAppender(console);
this.websocketServer = new WebsocketServer();
this.websocketBrowser = new WebsocketBrowser();
}
示例11: reconfigLog
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
/**
* read log4j properties from user defined location or default location
* @throws FileNotFoundException
*/
public void reconfigLog() throws FileNotFoundException {
File location = _configuration.getLogConfig();
Level llevel = _configuration.loglevel;
Logger.getRootLogger().removeAllAppenders();
progressAndResultLog.setAdditivity(false);
// user provided log location?
if (location != null) {
if (!location.exists())
{
System.err.printf("User provided log location does not exist: %s", location);
System.exit(1);
}
PropertyConfigurator.configure(new FileInputStream(location));
log.info("user has provided log level location: " + location);
}
// user has given a global log level
else if (llevel != null) {
ConsoleAppender c = new ConsoleAppender();
c.setLayout(new PatternLayout("%-4r [%t] %-5p %l - %m%n"));
c.setThreshold(llevel);
c.activateOptions();
Logger.getRootLogger().addAppender(c);
log.info("user set log level to " + llevel.toString());
}
// do we have a log file at the default location
else if (new File(LOG4JPROPERIES_DEFAULT_LOCATION).exists())
{
defaultLogPropertyFileConfig();
log.info("use default log properties location " + LOG4JPROPERIES_DEFAULT_LOCATION);
}
// just set everything to error log level
else {
defaultLogConfig();
}
outputLog(llevel == null ? Level.INFO : llevel);
}
示例12: outputLog
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public void outputLog(Level l) {
if (!progressAndResultLog.getAllAppenders().hasMoreElements()) {
progressAndResultLog.removeAllAppenders();
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(l);
console.activateOptions();
progressAndResultLog.addAppender(console);
}
}
示例13: defaultLogConfig
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
public void defaultLogConfig() {
// standard appender is console
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%d [%p] %l %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.ERROR);
console.activateOptions();
Logger.getRootLogger().addAppender(console);
}
示例14: loggerSetup
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
/**
* Just some logging set up here.
*/
private void loggerSetup() {
logger = TesttoolConfig.getLogger();
logger.setLevel(Level.INFO);
console = Logger.getLogger("de.wwu.testtool.test.console");
console.setLevel(Level.INFO);
ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%-5p [%t:%r] %M(): %m%n"));
consoleAppender.setName("Console Appender");
//consoleAppender.setLayout(new PatternLayout("[%r] %20.20M(): %m%n") );
consoleAppender.setLayout(new PatternLayout("%m%n") );
console.addAppender(consoleAppender);
}
示例15: loggerSetup
import org.apache.log4j.ConsoleAppender; //导入方法依赖的package包/类
private void loggerSetup() {
logger = TesttoolConfig.getLogger();
logger.setLevel(Level.DEBUG);
logger.debug("Debug");
logger.info("Info");
console = Logger.getLogger("de.wwu.testtool.test.console");
console.setLevel(Level.INFO);
ConsoleAppender consoleAppender = new ConsoleAppender(new PatternLayout("%-5p [%t:%r] %M(): %m%n"));
consoleAppender.setName("Console Appender");
consoleAppender.setLayout(new PatternLayout("[%r] %20.20M(): %m%n") );
console.addAppender(consoleAppender);
}