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


Java RollingFileAppender類代碼示例

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


RollingFileAppender類屬於org.apache.log4j包,在下文中一共展示了RollingFileAppender類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:13,代碼來源:Log4JMetricsFileWriter.java

示例2: 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

示例3: configureAuditLogs

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
private void configureAuditLogs() throws IOException {
  // Shutdown the LogManager to release all logger open file handles.
  // Unfortunately, Apache commons logging library does not provide
  // means to release underlying loggers. For additional info look up
  // commons library FAQ.
  LogManager.shutdown();

  File file = new File(auditLogFile);
  if (file.exists()) {
    assertTrue(file.delete());
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  // disable logging while the cluster startup preps files
  logger.setLevel(Level.OFF);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAuditLogs.java

示例4: configureLoggers

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
/**
 * Configures rolling file loggers.
 * 
 * @param filename the filename to output logging to.
 * @param loggers the logger names.
 */
private void configureLoggers( String filename, List<String> loggers )
{
    String file = getLogFile( filename );
    
    RollingFileAppender appender = getRollingFileAppender( file );

    for ( String loggerName : loggers )
    {
        Logger logger = Logger.getRootLogger().getLoggerRepository().getLogger( loggerName );
        
        logger.addAppender( appender );
        
        log.info( "Added logger: " + loggerName + " using file: " + file );     
    }  
}
 
開發者ID:dhis2,項目名稱:dhis2-core,代碼行數:22,代碼來源:Log4JLogConfigInitializer.java

示例5: tieSystemOutAndErrToLog

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void tieSystemOutAndErrToLog()
{

  org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
  Appender appender = rootLogger.getAppender(DT_LOG_APPENDER);
  if (appender instanceof RollingFileAppender) {
    RollingFileAppender rfa = (RollingFileAppender)appender;
    if (rfa.getFile() == null || rfa.getFile().isEmpty()) {
      rfa.setFile(System.getProperty(DT_LOGDIR));
      rfa.activateOptions();
    }
  } else if (appender != null) {
    logger.warn("found appender {} instead of RollingFileAppender", appender);
  }

  LoggerUtil.addAppenders();
  System.setOut(createLoggingProxy(System.out));
  System.setErr(createLoggingProxy(System.err));
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:21,代碼來源:StdOutErrLog.java

示例6: setupAuditLogs

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
/** Sets up log4j logger for auditlogs */
private void setupAuditLogs() throws IOException {
  // Shutdown the LogManager to release all logger open file handles.
  // Unfortunately, Apache commons logging library does not provide
  // means to release underlying loggers. For additional info look up
  // commons library FAQ.
  LogManager.shutdown();

  File file = new File(auditLogFile);
  if (file.exists()) {
    assertTrue(file.delete());
  }
  Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
  logger.setLevel(Level.INFO);
  PatternLayout layout = new PatternLayout("%m%n");
  RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
  logger.addAppender(appender);
}
 
開發者ID:ict-carch,項目名稱:hadoop-plus,代碼行數:19,代碼來源:TestAuditLogs.java

示例7: testRolloverLogfile

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
@Test
public void testRolloverLogfile() throws Exception {
    Log4jUtils.rolloverLogfile();

    // add appender to cover more
    Logger.getLogger("somelogger");
    Logger.getRootLogger().addAppender(new ConsoleAppender());
    final RollingFileAppender rollingFileAppender = new RollingFileAppender();
    File file = File.createTempFile("log4j", ".log");
    rollingFileAppender.setFile(file.getAbsolutePath());
    Logger.getRootLogger().addAppender(rollingFileAppender);

    Log4jUtils.rolloverLogfile();

    file.deleteOnExit();
    new File(file.getAbsoluteFile() + ".1").deleteOnExit();
}
 
開發者ID:centic9,項目名稱:commons-dost,代碼行數:18,代碼來源:Log4jUtilsTest.java

示例8: 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

示例9: createRATSpecificLogger

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
/**
 * This create log4j logger for resource access tool using root logger.
 * It adds file appender with specified filename to the logger which creates separate
 * log file for each resource access tool.
 *
 * @param clazz   Class object for Resource Access Tool
 * @param logFile String containing name of log file.
 * @return log4j Logger object
 */
@SuppressWarnings("unchecked")
public static Logger createRATSpecificLogger(Class clazz, String logFile) {
    Enumeration<Appender> appenders = Logger.getRootLogger()
            .getAllAppenders();
    // Add all appenders of root logger
    while (appenders.hasMoreElements()) {
        Appender appender = appenders.nextElement();

        //	For file appender create new appender with different log file
        if (appender instanceof RollingFileAppender) {
            try {
                // Creates new file appender
                ((RollingFileAppender) appender).setFile(FileResourceParameters.resourceLogFolder() + logFile);
                ((RollingFileAppender) appender).activateOptions();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    return Logger.getLogger(clazz);
}
 
開發者ID:ncbo,項目名稱:resource_access_tools,代碼行數:32,代碼來源:LoggerUtils.java

示例10: 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

示例11: 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

示例12: 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

示例13: createFileLogger

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
public void createFileLogger(String file) throws IOException {
    //----
    ConsoleAppender console = new ConsoleAppender();
    String PATTERN = "%m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.INFO);
    console.activateOptions();
    Logger.getRootLogger().getLoggerRepository().resetConfiguration();
    Logger.getRootLogger().removeAllAppenders();
    Logger.getRootLogger().addAppender(console);
    //----		
    org.apache.log4j.RollingFileAppender rfa = 
            new RollingFileAppender(new org.apache.log4j.PatternLayout(),file);
    Logger.getRootLogger().addAppender(rfa);
    

    
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:19,代碼來源:BaseEvolutionaryTest.java

示例14: createCustomFileLogger

import org.apache.log4j.RollingFileAppender; //導入依賴的package包/類
public Logger createCustomFileLogger(String file) throws IOException {
    //----
    ConsoleAppender console = new ConsoleAppender();
    String PATTERN = "%m%n-%c: ";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.INFO);
    console.activateOptions();
    Logger log = Logger.getLogger(Thread.currentThread().getName());
    
     log.getLoggerRepository().resetConfiguration();
     log.removeAllAppenders();
     log.addAppender(console);
    //----		
    org.apache.log4j.RollingFileAppender rfa = 
            new RollingFileAppender(new org.apache.log4j.PatternLayout(PATTERN),file);
     log.addAppender(rfa);
     rfa.setImmediateFlush(true);
    
    return log;
    
}
 
開發者ID:SpoonLabs,項目名稱:astor,代碼行數:22,代碼來源:BaseEvolutionaryTest.java

示例15: 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


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