當前位置: 首頁>>代碼示例>>Java>>正文


Java RollingFileAppender.setMaxBackupIndex方法代碼示例

本文整理匯總了Java中org.apache.log4j.RollingFileAppender.setMaxBackupIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java RollingFileAppender.setMaxBackupIndex方法的具體用法?Java RollingFileAppender.setMaxBackupIndex怎麽用?Java RollingFileAppender.setMaxBackupIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.RollingFileAppender的用法示例。


在下文中一共展示了RollingFileAppender.setMaxBackupIndex方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initLogger

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
private static void initLogger() {
	Logger rootLogger = Logger.getRootLogger();
	PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");

	try {
		RollingFileAppender fileAppender = new RollingFileAppender(layout, System.getProperty("log.file", "./vnt.log"));
		fileAppender.setImmediateFlush(true);
		fileAppender.setThreshold(Level.DEBUG);
		fileAppender.setAppend(true);
		fileAppender.setMaxFileSize("5MB");
		fileAppender.setMaxBackupIndex(2);

		rootLogger.addAppender(fileAppender);
	} catch (IOException e) {
		log.error("Failed to add appender !!", e);
	}
}
 
開發者ID:crsmoro,項目名稱:vntscraper,代碼行數:18,代碼來源:VntMain.java

示例2: 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;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:13,代碼來源:Log4JMetricsFileWriter.java

示例3: CreateRollingFileAppender

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
/**
 * Create File appender, This appender is responsible to write stream of data when invoked, in our case, this appender is handeled my the Bufferappender
 *
 * @param cacheName Name of the file appender
 * @param fileName Filename to which is to write logs
 * @return returns the created appender
 */
private Appender CreateRollingFileAppender(String fileName)
{
    RollingFileAppender appender = new RollingFileAppender();
    appender.setName("RollingFileAppender" + _loggerName);
    appender.setFile(fileName);
    //doesnt matter since all files are created with a new name
    appender.setAppend(false);

    appender.setMaxBackupIndex(Integer.MAX_VALUE);
    appender.setMaxFileSize("5MB");

    String str = "%-27d{ISO8601}" /*+ "\t%-45.42appdomain" + "\t%-45.42l"*/ + "\t%-42t" + "\t%-9p" + "\t%m" + "%n";

    appender.setThreshold(Level.ALL);

    return appender;
}
 
開發者ID:Alachisoft,項目名稱:TayzGrid,代碼行數:25,代碼來源:CacheLogger.java

示例4: initLogger

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
private static void initLogger() {
	// This is the root logger provided by log4j
	Logger rootLogger = Logger.getRootLogger();

	// Define log pattern layout
	PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");

	try {
		// Define file appender with layout and output log file name
		RollingFileAppender fileAppender = new RollingFileAppender(layout, "./scplayer.log");
		fileAppender.setImmediateFlush(true);
		fileAppender.setThreshold(Level.DEBUG);
		fileAppender.setAppend(true);
		fileAppender.setMaxFileSize("5MB");
		fileAppender.setMaxBackupIndex(2);

		// Add the appender to root logger
		rootLogger.addAppender(fileAppender);
	} catch (IOException e) {
		System.out.println("Failed to add appender !!");
		System.exit(-1);
	}
}
 
開發者ID:crsmoro,項目名稱:scplayer,代碼行數:24,代碼來源:SCPlayerMain.java

示例5: internalInit

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
/**
 *  initializes the log system using the logfile argument
 */
private void internalInit( String logfile )
    throws Exception
{
    /*
     *  do it by our classname to avoid conflicting with anything else 
     *  that might be used...
     */

    logger = Category.getInstance(this.getClass().getName());
    logger.setAdditivity(false);

    /*
     * Priority is set for DEBUG becouse this implementation checks 
     * log level.
     */
    logger.setPriority(Priority.DEBUG);

    RollingFileAppender appender = new RollingFileAppender( new PatternLayout( "%d - %m%n"), logfile, true);
    
    appender.setMaxBackupIndex( 1 );
    
    appender.setMaximumFileSize( 100000 );
    
    logger.addAppender(appender);
}
 
開發者ID:BowlerHatLLC,項目名稱:feathers-sdk,代碼行數:29,代碼來源:SimpleLog4JLogSystem.java

示例6: createLogger

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
private void createLogger() {
	// Create logger
	synchronized (logCreatorLock) {
		String loggerName = System.currentTimeMillis() + "." + this.executionId + "." + this.jobId;
		logger = Logger.getLogger(loggerName);

		// Create file appender
		String logName = createLogFileName(node);
		logFile = new File(workingDir, logName);
		
		String absolutePath = logFile.getAbsolutePath();

		jobAppender = null;
		try {
			RollingFileAppender fileAppender = new RollingFileAppender(loggerLayout, absolutePath, true);
			fileAppender.setMaxBackupIndex(jobLogBackupIndex);
			fileAppender.setMaxFileSize(jobLogChunkSize);
			jobAppender = fileAppender;
			logger.addAppender(jobAppender);
			logger.setAdditivity(false);
		}
		catch (IOException e) {
			flowLogger.error("Could not open log file in " + workingDir + " for job " + this.jobId, e);
		}
	}
}
 
開發者ID:zhizhounq,項目名稱:azkaban-customization,代碼行數:27,代碼來源:JobRunner.java

示例7: 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");
    }
}
 
開發者ID:DataDog,項目名稱:jmxfetch,代碼行數:18,代碼來源:CustomLogger.java

示例8: initAppenders

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
private static void initAppenders() throws IOException {
    systemLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "system.log");
    accessLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "access.log");
    auditLogAppender = new RollingFileAppender(getLayout(), logFilePath
            + File.separatorChar + "audit.log");
    reverseProxyLogAppender = new RollingFileAppender(getLayout(),
            logFilePath + File.separatorChar + "reverseproxy.log");

    // setting the max backup index and file size
    systemLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    systemLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    systemLogAppender.setName(systemLogAppenderName);

    accessLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    accessLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    accessLogAppender.setName(accessLogAppenderName);

    auditLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    auditLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    auditLogAppender.setName(auditLogAppenderName);

    reverseProxyLogAppender.setMaxBackupIndex(MAX_BACKUP_INDEX);
    reverseProxyLogAppender.setMaxFileSize(MAX_FILE_SIZE);
    reverseProxyLogAppender.setName(reverseProxyLogAppenderName);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:28,代碼來源:LoggerFactory.java

示例9: 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");
    }
}
 
開發者ID:ccaicedo,項目名稱:SCMBAT,代碼行數:30,代碼來源:Home.java

示例10: createLogger

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
private void createLogger() {
  // Create logger
  synchronized (logCreatorLock) {
    String loggerName =
        System.currentTimeMillis() + "." + this.executionId + "."
            + this.jobId;
    logger = Logger.getLogger(loggerName);

    // Create file appender
    String logName = createLogFileName(node);
    logFile = new File(workingDir, logName);

    String absolutePath = logFile.getAbsolutePath();

    jobAppender = null;
    try {
      RollingFileAppender fileAppender =
          new RollingFileAppender(loggerLayout, absolutePath, true);
      fileAppender.setMaxBackupIndex(jobLogBackupIndex);
      fileAppender.setMaxFileSize(jobLogChunkSize);
      jobAppender = fileAppender;
      logger.addAppender(jobAppender);
      logger.setAdditivity(false);
    } catch (IOException e) {
      flowLogger.error("Could not open log file in " + workingDir
          + " for job " + this.jobId, e);
    }
  }
}
 
開發者ID:JasonBian,項目名稱:azkaban,代碼行數:30,代碼來源:JobRunner.java

示例11: Log4jFileLoggerFactory

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
public Log4jFileLoggerFactory(File logFile, String categoriesWithDebugLevel) throws IOException {
  myCategoriesWithDebugLevel = categoriesWithDebugLevel.isEmpty() ? Collections.<String>emptyList() : Arrays.asList(categoriesWithDebugLevel.split(","));
  PatternLayout pattern = new PatternLayout("%d [%7r] %6p - %30.30c - %m\n");
  myAppender = new RollingFileAppender(pattern, logFile.getAbsolutePath());
  myAppender.setMaxFileSize("20MB");
  myAppender.setMaxBackupIndex(10);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:8,代碼來源:Log4jFileLoggerFactory.java

示例12: configureLog4J

import org.apache.log4j.RollingFileAppender; //導入方法依賴的package包/類
/**
 * Configures the Log4J properties
 * 
 * @param logFilePath
 *            The log file path
 */
private void configureLog4J(String logFilePath) {

	// This is the root logger provided by log4j
	Logger rootLogger = Logger.getRootLogger();
	rootLogger.setLevel(Level.DEBUG);

	// Define log pattern layout
	PatternLayout layout = new PatternLayout("[%-5p] %d %c - %m%n");

	// Add console appender to root logger
	if (rootLogger.getAppender(LOG_CONSOLE_APPENDER_NAME) == null) {
		ConsoleAppender consoleAppender = new ConsoleAppender(layout);
		consoleAppender.setName(LOG_CONSOLE_APPENDER_NAME);
		rootLogger.addAppender(consoleAppender);
	}

	// Add file appender with layout and output log file name
	try {
		if (rootLogger.getAppender(LOG_FILE_APPENDER_NAME) == null) {
			RollingFileAppender fileAppender = new RollingFileAppender(
					layout, logFilePath);
			fileAppender.setAppend(false);
			fileAppender.setImmediateFlush(true);
			fileAppender.setName(LOG_FILE_APPENDER_NAME);
			fileAppender.setMaxFileSize("5MB");
			fileAppender.setMaxBackupIndex(10);
			rootLogger.addAppender(fileAppender);
		}
	} catch (IOException e) {
		System.out.println("Failed to add appender !!");
	}
}
 
開發者ID:aguelle,項目名稱:MIDI-Automator,代碼行數:39,代碼來源:Resources.java

示例13: 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);
}
 
開發者ID:sterodium,項目名稱:selenium-grid-extensions,代碼行數:14,代碼來源:LoggingConfigurator.java

示例14: 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>");
    }
}
 
開發者ID:automated-testing,項目名稱:nitrogen,代碼行數:36,代碼來源:SpecificationLoggerWatcher.java

示例15: 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();
        }
    });
}
 
開發者ID:sismics,項目名稱:books,代碼行數:41,代碼來源:RequestContextFilter.java


注:本文中的org.apache.log4j.RollingFileAppender.setMaxBackupIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。