本文整理匯總了Java中org.apache.log4j.FileAppender.setThreshold方法的典型用法代碼示例。如果您正苦於以下問題:Java FileAppender.setThreshold方法的具體用法?Java FileAppender.setThreshold怎麽用?Java FileAppender.setThreshold使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.FileAppender
的用法示例。
在下文中一共展示了FileAppender.setThreshold方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的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();
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
示例5: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Setup log4j logging
*
* @param logFile log file
* @param debug true if debug messages should be logged (use -Ddebug=true to enable debug message)
*/
public static void setupLogging(File logFile, boolean debug) {
Logger root = Logger.getRootLogger();
ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
console.setThreshold(Level.INFO);
root.addAppender(console);
if (logFile != null) {
try {
FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
file.setThreshold(Level.DEBUG);
root.addAppender(file);
} catch (IOException e) {
sLogger.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
}
}
if (!debug)
root.setLevel(Level.INFO);
}
示例6: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Setup log4j logging
*
* @param logFile
* log file
* @param debug
* true if debug messages should be logged (use -Ddebug=true to
* enable debug message)
*/
public static void setupLogging(File logFile, boolean debug) {
Logger root = Logger.getRootLogger();
ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
console.setThreshold(Level.INFO);
root.addAppender(console);
if (logFile != null) {
try {
FileAppender file = new FileAppender(new PatternLayout(
"%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
file.setThreshold(Level.DEBUG);
root.addAppender(file);
} catch (IOException e) {
sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
}
}
if (!debug)
root.setLevel(Level.INFO);
}
示例7: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Setup log4j logging
*
* @param logFile log file
*/
public static void setupLogging(File logFile) {
Logger root = Logger.getRootLogger();
ConsoleAppender console = new ConsoleAppender(new PatternLayout("[%t] %m%n"));
console.setThreshold(Level.INFO);
root.addAppender(console);
if (logFile != null) {
try {
FileAppender file = new FileAppender(new PatternLayout("%d{dd-MMM-yy HH:mm:ss.SSS} [%t] %-5p %c{2}> %m%n"), logFile.getPath(), false);
file.setThreshold(Level.DEBUG);
root.addAppender(file);
} catch (IOException e) {
sLog.fatal("Unable to configure logging, reason: " + e.getMessage(), e);
}
}
}
示例8: prepareExperimentLog
import org.apache.log4j.FileAppender; //導入方法依賴的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 );
}
示例9: prepareExperimentLog
import org.apache.log4j.FileAppender; //導入方法依賴的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);
}
示例10: 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);
}
示例11: 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");
}
示例12: setupLoggingToFile
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void setupLoggingToFile(Logger stcLogger, String logfile,
boolean trace) {
Layout layout = new PatternLayout("%-5p %m%n");
boolean append = false;
try {
FileAppender appender = new FileAppender(layout, logfile, append);
Level threshold;
if (trace) {
threshold = Level.TRACE;
} else {
threshold = Level.DEBUG;
}
appender.setThreshold(threshold);
stcLogger.addAppender(appender);
stcLogger.setLevel(threshold);
} catch (IOException e) {
System.out.println(e.getMessage());
System.exit(ExitCode.ERROR_IO.code());
}
}
示例13: enableLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
void enableLogging(TaskoRun run) {
PatternLayout pattern = new PatternLayout(DEFAULT_LOGGING_LAYOUT);
try {
getLogger().removeAllAppenders();
FileAppender outLogAppender = new FileAppender(pattern,
run.buildStdOutputLogPath());
outLogAppender.setThreshold(Level.INFO);
getLogger().addAppender(outLogAppender);
FileAppender errLogAppender = new FileAppender(pattern,
run.buildStdErrorLogPath());
errLogAppender.setThreshold(Level.ERROR);
getLogger().addAppender(errLogAppender);
}
catch (IOException e) {
getLogger().warn("Logging to file disabled");
e.printStackTrace();
}
}
示例14: setLogLevel
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void setLogLevel(String level) {
Level newLevel = Level.ERROR;
level = level.substring(level.lastIndexOf(' ') + 1);
switch (level) {
case "Debug":
newLevel = Level.DEBUG;
break;
case "Info":
newLevel = Level.INFO;
break;
case "Warn":
newLevel = Level.WARN;
break;
case "Error":
newLevel = Level.ERROR;
break;
}
Logger.getRootLogger().setLevel(newLevel);
logger.setLevel(newLevel);
ConsoleAppender ca = (ConsoleAppender)Logger.getRootLogger().getAppender("stdout");
if (ca != null) {
ca.setThreshold(newLevel);
}
FileAppender fa = (FileAppender)Logger.getRootLogger().getAppender("FILE");
if (fa != null) {
fa.setThreshold(newLevel);
}
}
示例15: 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);
}