本文整理汇总了Java中org.apache.log4j.Appender.getLayout方法的典型用法代码示例。如果您正苦于以下问题:Java Appender.getLayout方法的具体用法?Java Appender.getLayout怎么用?Java Appender.getLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Appender
的用法示例。
在下文中一共展示了Appender.getLayout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enableRingBufferAppender
import org.apache.log4j.Appender; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static void enableRingBufferAppender(Logger logger, int bufferSize) {
Layout l = null;
if (LOG.isDebugEnabled())
LOG.debug(logger + " => " + logger.getAllAppenders());
for (Object o : CollectionUtil.iterable(logger.getAllAppenders())) {
Appender a = (Appender)o;
l = a.getLayout();
} // FOR
if (l != null) {
logger.removeAllAppenders();
logger.addAppender(new RingBufferAppender(bufferSize));
Logger.getRootLogger().info("Enabled RingBuffer logging for '" + logger.getName() + "'");
}
}
示例2: printOptions
import org.apache.log4j.Appender; //导入方法依赖的package包/类
protected
void printOptions(PrintWriter out, Category cat) {
Enumeration appenders = cat.getAllAppenders();
Level prio = cat.getLevel();
String appenderString = (prio == null ? "" : prio.toString());
while (appenders.hasMoreElements()) {
Appender app = (Appender) appenders.nextElement();
String name;
if ((name = (String) appenderNames.get(app)) == null) {
// first assign name to the appender
if ((name = app.getName()) == null || isGenAppName(name)) {
name = genAppName();
}
appenderNames.put(app, name);
printOptions(out, app, "log4j.appender."+name);
if (app.getLayout() != null) {
printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
}
}
appenderString += ", " + name;
}
String catKey = (cat == Logger.getRootLogger())
? "log4j.rootLogger"
: "log4j.logger." + cat.getName();
if (appenderString != "") {
out.println(catKey + "=" + appenderString);
}
if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
out.println("log4j.additivity." + cat.getName() + "=false");
}
}
示例3: FileAppender
import org.apache.log4j.Appender; //导入方法依赖的package包/类
public FileAppender() {
setLayout(new PatternLayout("[%d{ISO8601} %-5p] %m%n"));
// trying to get a layout from log4j configuration
Enumeration<?> en = Logger.getRootLogger().getAllAppenders();
if (en != null && en.hasMoreElements()) {
Appender app = (Appender) en.nextElement();
if (app != null && app.getLayout() != null) {
Logger.getRootLogger().debug("Retrieved layout from log4j configuration");
setLayout(app.getLayout());
}
}
}
示例4: printOptions
import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
* @since 1.2.15
*/
protected
void printOptions(PrintWriter out, Category cat) {
Enumeration appenders = cat.getAllAppenders();
Level prio = cat.getLevel();
String appenderString = (prio == null ? "" : prio.toString());
while (appenders.hasMoreElements()) {
Appender app = (Appender) appenders.nextElement();
String name;
if ((name = (String) appenderNames.get(app)) == null) {
// first assign name to the appender
if ((name = app.getName()) == null || isGenAppName(name)) {
name = genAppName();
}
appenderNames.put(app, name);
printOptions(out, app, "log4j.appender."+name);
if (app.getLayout() != null) {
printOptions(out, app.getLayout(), "log4j.appender."+name+".layout");
}
}
appenderString += ", " + name;
}
String catKey = (cat == Logger.getRootLogger())
? "log4j.rootLogger"
: "log4j.logger." + cat.getName();
if (appenderString != "") {
out.println(catKey + "=" + appenderString);
}
if (!cat.getAdditivity() && cat != Logger.getRootLogger()) {
out.println("log4j.additivity." + cat.getName() + "=false");
}
}
示例5: createOBRLogger
import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
* This create log4j logger for OBS work flow using root logger.
* It adds file appender with specified filename to the logger which creates separate
* log file for each resource access tool.
*
* @param clazz
* @param logFile String containing name of log file.
* @return log4j Logger object
*/
@SuppressWarnings("unchecked")
public static Logger createOBRLogger(Class clazz) {
Logger logger = Logger.getLogger(clazz);
Enumeration<Appender> appenders = Logger.getRootLogger()
.getAllAppenders();
// Add all appenders of root logger
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
// For file appender create new appender with different log file
if (appender instanceof RollingFileAppender) {
try {
// Creates new file appender
RollingFileAppender newFileAppender = new RollingFileAppender(
appender.getLayout(), FileResourceParameters.resourceLogFolder() + OBR_LOG_FILE
);
newFileAppender.activateOptions();
logger.addAppender(newFileAppender);
} catch (Exception e) {
e.printStackTrace();
}
} else {
logger.addAppender(appender);
}
}
logger.setAdditivity(false);
return logger;
}
示例6: createOBRLogger
import org.apache.log4j.Appender; //导入方法依赖的package包/类
/**
* This create log4j logger for OBS work flow using root logger.
* It adds file appender with specified filename to the logger which creates separate
* log file for each resource access tool.
*
* @param clazz
* @param logFile String containing name of log file.
* @return log4j Logger object
*/
@SuppressWarnings("unchecked")
public static Logger createOBRLogger(Class clazz) {
Logger logger = Logger.getLogger(clazz);
Enumeration<Appender> appenders = Logger.getRootLogger()
.getAllAppenders();
// Add all appenders of root logger
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
// For file appender create new appender with different log file
if (appender instanceof DailyRollingFileAppender) {
try {
// Creates new file appender
DailyRollingFileAppender newFileAppender = new DailyRollingFileAppender(
appender.getLayout(), FileParameters.obrLogFolder() + OBR_LOG_FILE,
((DailyRollingFileAppender) appender)
.getDatePattern());
newFileAppender.activateOptions();
logger.addAppender(newFileAppender);
} catch (Exception e) {
e.printStackTrace();
}
} else {
logger.addAppender(appender);
}
}
logger.setAdditivity(false);
return logger;
}
示例7: LogCapturer
import org.apache.log4j.Appender; //导入方法依赖的package包/类
private LogCapturer(Logger logger) {
this.logger = logger;
Appender defaultAppender = Logger.getRootLogger().getAppender("stdout");
if (defaultAppender == null) {
defaultAppender = Logger.getRootLogger().getAppender("console");
}
final Layout layout = (defaultAppender == null) ? new PatternLayout() :
defaultAppender.getLayout();
this.appender = new WriterAppender(layout, sw);
logger.addAppender(this.appender);
}