本文整理匯總了Java中org.apache.log4j.FileAppender.setName方法的典型用法代碼示例。如果您正苦於以下問題:Java FileAppender.setName方法的具體用法?Java FileAppender.setName怎麽用?Java FileAppender.setName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.FileAppender
的用法示例。
在下文中一共展示了FileAppender.setName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addAppender
import org.apache.log4j.FileAppender; //導入方法依賴的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);
}
示例2: setUp
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
try {
Files.delete(Paths.get(FILEPATH));
} catch (Exception e) {
// TODO: handle exception
}
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile(FILEPATH);
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa);
}
示例3: setupLog4jForAction
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Setup the Log4J logger for this action thread.
* @return String path to log file
* @throws IOException If there's something wrong with the FileAppender.
*/
private void setupLog4jForAction() throws IOException {
String loggerName = "Action_" + this.id;
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("Action_" + this.id);
String logRoot = System.getProperty("LOG_ROOT");
if(logRoot == null) {
logRoot = ".";
}
String logFilePath = logRoot + "/charles-rest/ActionsLogs/" + this.id + ".log";
File logFile = new File(logFilePath);
logFile.getParentFile().mkdirs();
logFile.createNewFile();//you have to create the file yourself since FileAppender acts funny under linux if the file doesn't already exist.
FileAppender fa = new FileAppender(new PatternLayout("%d %p - %m%n"), logFilePath);
fa.setName(this.id + "_appender");
fa.setThreshold(Level.DEBUG);
log4jLogger.addAppender(fa);
log4jLogger.setLevel(Level.DEBUG);
this.logger = LoggerFactory.getLogger(loggerName);
}
示例4: getLogger
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public Logger getLogger(Logger logger, JEVisObject dataSource) {
String loggerFileName = dataSource.getName().replace(" ", "_") + "_ID(" + dataSource.getID() + ").log";
String loggerName = dataSource.getID().toString();
MDC.put(KEY, "" + loggerName);
FileAppender appender = new FileAppender();
appender.setLayout(new PatternLayout("[%d{dd MMM yyyy HH:mm:ss}][%c{2}]: %-10m%n"));
appender.setFile(loggerFileName);
appender.setAppend(true);
appender.setImmediateFlush(true);
appender.activateOptions();
appender.setName(loggerName);
ThreadFilter threadFilter = new ThreadFilter(loggerName);
appender.addFilter(threadFilter);
logger.setAdditivity(false); //<--do not use default root logger
logger.addAppender(appender);
return logger;
}
示例5: init
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void init() {
ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.TRACE);
console.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile("log.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.TRACE);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa);
}
示例6: initializeAnalysisLog
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Initialize the log4j logging infrastructure for the analysis run.
*/
private void initializeAnalysisLog() {
// build the path of the log file
// inside a log directory of the analysis workflow
DateFormat logDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
String logFile = WorkspaceUtil.getAbsoluteFromProjectRelativePath(
"logs/vpm-analysis-" + (logDateFormat.format(new Date())) + ".csv",
config.getSplevoProjectEditor().getSplevoProject());
FileAppender fa = new FileAppender();
fa.setName(CloseAnalysisTraceLogAppenderJob.LOG_APPENDER_NAME);
fa.setFile(logFile);
fa.setLayout(new PatternLayout("%m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(false);
fa.activateOptions();
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).removeAllAppenders();
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).addAppender(fa);
// insert header row
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).info("Analyzer,VP1, VP2, SourceInfo, TargetInfo, Remark");
}
示例7: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void setupLogging() {
// add in our custom per-file logging appender. anything that happens for this particular
// file should go in this log file
FileAppender appender = new FileAppender();
File file = fileService.getById(getServiceContext(), getFileId());
appender.setName("batch-" + getFileId());
appender.setLayout(new PatternLayout("%d %-5p %c %x - %m%n"));
appender.setFile(file.getPath() + java.io.File.separator + file.getFilename() + ".log");
appender.setAppend(true);
appender.activateOptions();
Logger logger = Logger.getRootLogger();
logger.addAppender(appender);
}
示例8: addFileAppender
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void addFileAppender(Logger rootLogger) {
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile("rubus.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa);
}
示例9: setup
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Setup the Log4J logger. We do it programatically since the properties
* file way is not thread-safe!<br>
* Also, note that we have to create the file ourselves since FileAppender
* acts funny under linux if the file doesn't already exist.
* @param dir The directory where the file should be located.
* @throws IOException If there's something wrong with the File.
*/
private void setup(final String dir) throws IOException {
final String loggerName = "Action_" + this.id;
final org.apache.log4j.Logger build = org.apache.log4j.Logger
.getLogger(loggerName);
final String logFilePath;
if(dir == null) {
logFilePath = "/" + this.id + ".log";
} else {
if(dir.endsWith("/")) {
logFilePath = dir + this.id + ".log";
} else {
logFilePath = dir + "/" + this.id + ".log";
}
}
final File logFile = new File(logFilePath);
logFile.getParentFile().mkdirs();
logFile.createNewFile();
final FileAppender appender = new FileAppender(
new PatternLayout("%d %p - %m%n"), logFilePath
);
appender.setName(this.id + "_appender");
appender.setThreshold(Level.DEBUG);
build.addAppender(appender);
build.setLevel(Level.DEBUG);
this.logger = LoggerFactory.getLogger(loggerName);
}
示例10: SetFileLogger
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public static void SetFileLogger(Level level, String filename) {
FileAppender fa = new FileAppender();
fa.setName("FileLogger_Debug");
fa.setFile(filename);
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(level);
fa.setAppend(false);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
}
示例11: CISCoreStandaloneApp
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public CISCoreStandaloneApp() throws CISConfigException {
ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "%d [%p|%c|%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);
FileAppender fa = new FileAppender();
fa.setName("CISCoreLogger");
fa.setFile("./log/CISCore.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender((Appender)fa);
//repeat with all other desired appenders
log = Logger.getLogger(this.getClass());
Boolean ignoreError = Boolean.parseBoolean(PropertiesReader.getInstance().getPropertie("startup.ignore.error"));
log.info("Ignore Errors on CoreStartup: " + ignoreError);
try {
CISCoreImpl cisCore = CISCoreImpl.getInstance();
} catch (Exception e) {
if (!ignoreError) {
throw e;
}
}
ConnectorCallbackHandlerImpl callbackHandler = ConnectorCallbackHandlerImpl.getInstance();
callbackHandler.registerCallback(new RestConnectorCallback(PropertiesReader.getInstance().getPropertie("core.connector.rest.callback")));
log.info("Init. CISCoreStandaloneApp");
}
示例12: addLog4jFileAppender
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
Path addLog4jFileAppender(final Path path) throws IOException {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
String pattern = "%d{HH:mm:ss.SSS} %-5p %t %C{1}.%M:%L - %m%n";
final String threadName = Thread.currentThread().getName();
class ThreadFilter extends Filter {
@Override
public int decide(LoggingEvent event) {
if (event.getThreadName().startsWith(threadName)) {
return Filter.ACCEPT;
}
return Filter.DENY;
}
}
FileAppender fa = new FileAppender(new PatternLayout(pattern), path.toFile().getAbsolutePath());
fa.addFilter(new ThreadFilter());
fa.setThreshold(sysConfig.getCaseLogLevel());
fa.setImmediateFlush(true);
fa.setAppend(true);
fa.setName(path.toFile().getAbsolutePath());
fa.activateOptions();
rootLogger.addAppender(fa);
return path;
}
示例13: configureLogger
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public static void configureLogger(File logFile) {
Bundle bundle = Platform.getBundle("tools.vitruv.integration");
URL fileURL = bundle.getEntry("log4j.xml");
DOMConfigurator.configure(fileURL);
FileAppender appender = new FileAppender();
appender.setName("LogFile");
appender.setFile(logFile.getAbsolutePath());
appender.setThreshold(Level.INFO);
appender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
appender.setAppend(true);
appender.activateOptions();
Logger.getRootLogger().addAppender(appender);
}
示例14: initLog4j
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void initLog4j() {
FileAppender fa = new FileAppender();
fa.setName(LOG4J_FILE_APPENDER_NAME);
fa.setFile(getLogPath());
fa.setLayout(new PatternLayout("%d{dd.MM.yyyy HH:mm:ss,SS} %-5p %C{1} - %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
}
示例15: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public void setupLogging() throws IOException {
String patternLayout = "";
if (ConfigurationProperties.getPropertyBool("disablelog")) {
patternLayout = "%m%n";
} else {
patternLayout = ConfigurationProperties.getProperty("logpatternlayout");
}
Logger.getRootLogger().getLoggerRepository().resetConfiguration();
ConsoleAppender console = new ConsoleAppender();
console.setLayout(new PatternLayout(patternLayout));
console.activateOptions();
Logger.getRootLogger().addAppender(console);
String loglevelSelected = ConfigurationProperties.properties.getProperty("loglevel");
if (loglevelSelected != null)
LogManager.getRootLogger().setLevel(Level.toLevel(loglevelSelected));
if (ConfigurationProperties.hasProperty("logfilepath")) {
FileAppender fa = new FileAppender();
String filePath = ConfigurationProperties.getProperty("logfilepath");
File fileLog = new File(filePath);
if (!fileLog.exists()) {
fileLog.getParentFile().mkdirs();
fileLog.createNewFile();
}
fa.setName("FileLogger");
fa.setFile(fileLog.getAbsolutePath());
fa.setLayout(new PatternLayout(patternLayout));
fa.setThreshold(LogManager.getRootLogger().getLevel());
fa.setAppend(true);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
this.log.info("Log file at: " + filePath);
}
}