当前位置: 首页>>代码示例>>Java>>正文


Java FileAppender.setThreshold方法代码示例

本文整理汇总了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();
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:26,代码来源:EndPointHealthServiceImpl.java

示例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);
}
 
开发者ID:ajiniesta,项目名称:zoofx,代码行数:21,代码来源:ZFXConf.java

示例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);
}
 
开发者ID:bkusche,项目名称:bktail2,代码行数:20,代码来源:LogfileHandlerTest.java

示例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);
    
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:28,代码来源:Action.java

示例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);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:24,代码来源:Test.java

示例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);
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:28,代码来源:Test.java

示例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);
        }
    }
}
 
开发者ID:UniTime,项目名称:cpsolver,代码行数:21,代码来源:Test.java

示例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 );
	
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:23,代码来源:BilinearExperiment.java

示例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);

}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:24,代码来源:LambdaSearchAustrian.java

示例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);

}
 
开发者ID:miho,项目名称:PiOnWheels,代码行数:23,代码来源:Main.java

示例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");

}
 
开发者ID:kopl,项目名称:SPLevo,代码行数:27,代码来源:VPMAnalysisWorkflowDelegate.java

示例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());
  }
}
 
开发者ID:swift-lang,项目名称:swift-t,代码行数:21,代码来源:Logging.java

示例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();
    }
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:19,代码来源:RhnJavaJob.java

示例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);
    }
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:29,代码来源:MainWindow.java

示例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);
	
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:14,代码来源:Rubus.java


注:本文中的org.apache.log4j.FileAppender.setThreshold方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。