本文整理汇总了Java中org.apache.log4j.RollingFileAppender.setLayout方法的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender.setLayout方法的具体用法?Java RollingFileAppender.setLayout怎么用?Java RollingFileAppender.setLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.RollingFileAppender
的用法示例。
在下文中一共展示了RollingFileAppender.setLayout方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLogger
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
private RollingFileAppender initLogger(String loggerName, String filePrefix) {
String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName(loggerName);
fileAppender.setFile(fileName);
fileAppender.setLayout(new PatternLayout("%m%n"));
fileAppender.setAppend(true);
fileAppender.setMaxFileSize(maxFileSize);
fileAppender.setMaxBackupIndex(maxFileCount);
fileAppender.activateOptions();
return fileAppender;
}
示例2: setup
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
public static void setup(Level level, String logLocation) {
if (logLocation != null) {
RollingFileAppender fa = new RollingFileAppender();
fa.setName("FileLogger");
fa.setFile(logLocation);
fa.setMaxFileSize("5MB");
fa.setMaxBackupIndex(1);
fa.setLayout(new PatternLayout("%d | %-5p| %c{1} | %m%n"));
fa.setThreshold(level);
fa.setAppend(true);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
LOGGER.info("File Handler set");
} else {
System.out.println("Log location is not set, not logging to file");
}
}
示例3: initializeLogger
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
private void initializeLogger()
{
DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM");
Date date = new Date();
String curDate = dateFormat.format(date);
MethodAnalysis meth = new MethodAnalysis();
String filename = meth.getFilePath()+"logs/SCM_logFile_"+curDate+".log";//+"_"+log_number+".log";
try
{
PatternLayout layout = new PatternLayout();
layout.setConversionPattern("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
appender = new RollingFileAppender();
appender.setAppend(true);
appender.setMaxFileSize("10MB");
appender.setMaxBackupIndex(2);
appender.setFile(filename);
appender.setLayout(layout);
appender.activateOptions();
LOGGER.addAppender(appender);
}
catch(Exception e)
{
System.out.println("Exception in loading the logger in the Home");
}
}
示例4: getRollingFileAppender
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
/**
* Returns a rolling file appender.
*
* @param file the file to output to, including path and filename.
*/
private RollingFileAppender getRollingFileAppender( String file )
{
RollingFileAppender appender = new RollingFileAppender();
appender.setThreshold( Level.INFO );
appender.setFile( file );
appender.setMaxFileSize( MAX_FILE_SIZE );
appender.setLayout( PATTERN_LAYOUT );
appender.activateOptions();
return appender;
}
示例5: installFileAppender
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
private void installFileAppender(String logFilename) {
RollingFileAppender file = new RollingFileAppender();
file.setName("FileAppender");
file.setThreshold(logLevel);
file.setFile(new File(logFilename).getAbsolutePath());
file.setMaxFileSize(MAX_FILE_SIZE);
file.setMaxBackupIndex(MAX_BACKUPS);
file.setLayout(new PatternLayout(PATTERN));
file.setAppend(true);
file.activateOptions();
Logger.getRootLogger().addAppender(file);
}
示例6: starting
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
@Override
protected void starting(Description description) {
if (isSpecsEnabled()) {
String simplePackageName = getSimplePackageName(description);
String specsLocation = SPECS_BASE_DIRECTORY + File.separator + simplePackageName;
thisTestsAppender = new RollingFileAppender();
thisTestsAppender.setMaxFileSize("100MB");
thisTestsAppender.setMaxBackupIndex(0);
thisTestsAppender.setFile(specsLocation + File.separator + description.getTestClass().getSimpleName()
+ File.separator + description.getMethodName().split("http")[0] + ".html");
PatternLayout patternLayout = new PatternLayout();
patternLayout.setConversionPattern("%m%n");
thisTestsAppender.setLayout(patternLayout);
thisTestsAppender.setThreshold(Level.TRACE);
thisTestsAppender.activateOptions();
rootLogger = Logger.getRootLogger();
rootLogger.addAppender(thisTestsAppender);
log.info("<html><head><title>" + formatMethodName(description) + "</title>" +
"<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\"></script>" +
"<style>" +
".text{color: green; font-style: italic; font-size: 95%; font-family: tahoma} " +
".link{text-decoration: none; font-weight: normal; font-size: 80%; font-style: italic; color: #33d;} " +
"h1{width:60%} li.error{padding-top: 0px} li.error span{background: #e00; color: #fff; padding: 0 20px; margin: 0; display: block;} " +
"ol ol li.step{ color: #444; font-size: 95%; font-weight: normal} ol ol " +
"li{ list-style-type: lower-latin; line-height:2; width: 60%;border-bottom: 1px dotted #999; padding-top: 15px; color: darkblue} " +
".action{margin-top: 20px;cursor:pointer; font-weight: bold; color: green; } body{ font-family: tahoma; padding: 20px; } ul{line-height: 1.5; padding: 10px 60px; }" +
"</style>" +
"</head><body>");
log.info("<h1 style=\"font-family: tahoma\">" + formatMethodName(description) + "</h1><hr/><ol><li class='dummy'><ol>");
}
}
示例7: init
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// Force the locale in order to not depend on the execution environment
Locale.setDefault(new Locale(Constants.DEFAULT_LOCALE_ID));
// Injects the webapp root
String webappRoot = filterConfig.getServletContext().getRealPath("/");
EnvironmentUtil.setWebappRoot(webappRoot);
// Initialize the app directory
File baseDataDirectory = null;
try {
baseDataDirectory = DirectoryUtil.getBaseDataDirectory();
} catch (Exception e) {
log.error("Error initializing base data directory", e);
}
if (log.isInfoEnabled()) {
log.info(MessageFormat.format("Using base data directory: {0}", baseDataDirectory.toString()));
}
// Initialize file logger
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName("FILE");
fileAppender.setFile(DirectoryUtil.getLogDirectory() + File.separator + "books.log");
fileAppender.setLayout(new PatternLayout("%d{DATE} %p %l %m %n"));
fileAppender.setThreshold(Level.INFO);
fileAppender.setAppend(true);
fileAppender.setMaxFileSize("5MB");
fileAppender.setMaxBackupIndex(5);
fileAppender.activateOptions();
org.apache.log4j.Logger.getRootLogger().addAppender(fileAppender);
// Initialize the application context
TransactionUtil.handle(new Runnable() {
@Override
public void run() {
AppContext.getInstance();
}
});
}
示例8: initLogging
import org.apache.log4j.RollingFileAppender; //导入方法依赖的package包/类
public static void initLogging(String configDir, TypedProperties properties) {
/* Optionally remove existing handlers attached to j.u.l root logger */
SLF4JBridgeHandler.removeHandlersForRootLogger();
/*
* Add SLF4JBridgeHandler to j.u.l's root logger, should be done once
* during the initialization phase of your application
*/
SLF4JBridgeHandler.install();
consoleEnabled = Boolean.parseBoolean(properties.getProperty(
EnvConstants.LOG_TO_CONSOLE_ENABLED, "true"));
if (!consoleEnabled) {
org.apache.log4j.Logger.getRootLogger().removeAppender("CONSOLE");
}
fileEnabled = Boolean.parseBoolean(properties.getProperty(
EnvConstants.LOG_TO_FILE_ENABLED, "true"));
if (fileEnabled) {
logFilePath = properties.getProperty(EnvConstants.LOG_FILE,(String)null);
if (isBlank(logFilePath)) {
logDir = new File(configDir, "logs");
logDir.mkdirs();
logFilePath = logDir.getAbsolutePath() + "/metl.log";
} else {
logDir = new File(logFilePath).getParentFile();
}
int logFileRetentionInDays = properties.getInt(EnvConstants.LOG_FILE_RETENTION_IN_DAYS,10);
String logFileMaxSize = properties.get(EnvConstants.LOG_FILE_MAX_SIZE, "40MB");
String logFilePatternLayout = properties.get(EnvConstants.LOG_FILE_PATTERN_LAYOUT,"%d %-5p [%c{1}] [%t] %m%n");
try {
RollingFileAppender logFileAppender = new RollingFileAppender();
logFileAppender.setFile(logFilePath);
logFileAppender.setMaxBackupIndex(logFileRetentionInDays);
logFileAppender.setMaxFileSize(logFileMaxSize);
logFileAppender.setAppend(true);
logFileAppender.setLayout(new PatternLayout(logFilePatternLayout));
org.apache.log4j.Logger.getRootLogger().addAppender(logFileAppender);
logFileAppender.activateOptions();
} catch (Exception ex) {
System.err.println("Failed to configure the following log file: " + logFilePath);
ex.printStackTrace();
}
}
}