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


Java RollingRandomAccessFileAppender类代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender的典型用法代码示例。如果您正苦于以下问题:Java RollingRandomAccessFileAppender类的具体用法?Java RollingRandomAccessFileAppender怎么用?Java RollingRandomAccessFileAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RollingRandomAccessFileAppender类属于org.apache.logging.log4j.core.appender包,在下文中一共展示了RollingRandomAccessFileAppender类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerLogFileTailThreads

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
private void registerLogFileTailThreads() throws IOException {
    final Collection<String> outputFileNames = new HashSet<>();
    final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values();
    loggerAppenders.forEach(appender -> {
        if (appender instanceof FileAppender) {
            outputFileNames.add(((FileAppender) appender).getFileName());
        } else if (appender instanceof RandomAccessFileAppender) {
            outputFileNames.add(((RandomAccessFileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            outputFileNames.add(((RollingFileAppender) appender).getFileName());
        } else if (appender instanceof MemoryMappedFileAppender) {
            outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName());
        } else if (appender instanceof RollingRandomAccessFileAppender) {
            outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName());
        }
    });

    outputFileNames.forEach(s -> {
        final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true);
        final Thread thread = new Thread(t);
        thread.setPriority(Thread.MIN_PRIORITY);
        thread.setName(s);
        thread.start();
    });
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:26,代码来源:LoggingOutputSocketMessagingController.java

示例2: extractFileName

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
/**
 * File appender types do not share a "write-to-file" superclass.
 */
private String extractFileName(Appender a) {
    if (a instanceof FileAppender) {
        return ((FileAppender) a).getFileName();

    } else if (a instanceof RollingFileAppender) {
        return ((RollingFileAppender) a).getFileName();

    } else if (a instanceof RollingRandomAccessFileAppender) {
        return ((RollingRandomAccessFileAppender) a).getFileName();

    } else if (a instanceof RandomAccessFileAppender) {
        return ((RandomAccessFileAppender) a).getFileName();

    } else if (a instanceof MemoryMappedFileAppender) {
        return ((MemoryMappedFileAppender) a).getFileName();

    } else {
        return null;
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:24,代码来源:LogFileRetriever.java

示例3: initTargetAppender

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
@Override
public void initTargetAppender() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    // get log file path from existing file appender
    RollingRandomAccessFileAppender mainFile =
            (RollingRandomAccessFileAppender) ctx.getConfiguration().getAppender("mainFile");

    String pathPrefix = mainFile == null
            ? System.getProperty("user.dir") + StringUtils.replace("/target/log", "/", File.separator)
            + File.separator
            : StringUtils.replace(mainFile.getFileName(), "core.log", StringUtils.EMPTY);

    targetAppender = FileAppender.newBuilder()
            .withName(getTargetAppenderName())
            .withAppend(true)
            .withFileName(pathPrefix + getTargetAppenderName() + ".log")
            .withLayout(
                    PatternLayout.newBuilder()
                            .withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n")
                            .build()).
            build();
}
 
开发者ID:apache,项目名称:syncope,代码行数:23,代码来源:TestFileAuditAppender.java

示例4: initTargetAppender

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
@Override
public void initTargetAppender() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);

    // get log file path from existing file appender
    RollingRandomAccessFileAppender mainFile =
            (RollingRandomAccessFileAppender) ctx.getConfiguration().getAppender("mainFile");
    String pathPrefix = StringUtils.replace(mainFile.getFileName(), "core.log", StringUtils.EMPTY);

    targetAppender = FileAppender.newBuilder().
            withName(getTargetAppenderName()).
            withAppend(true).
            withFileName(pathPrefix + getTargetAppenderName() + ".log").
            withLayout(
                    PatternLayout.newBuilder()
                            .withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n")
                            .build())
            .build();
}
 
开发者ID:apache,项目名称:syncope,代码行数:20,代码来源:TestFileRewriteAuditAppender.java

示例5: createRollingRandomAccessFileAppender

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
/**
 * Creates a new {@link RollingFileAppender}
 * @param fileName The log file
 * @param loggingConfig The logging config
 * @param layout The layout
 * @param strategy the rollover strategy
 * @param rolledFileFormat The log file roll pattern
 * @param trigger The roll trigger
 * @return the new appender
 */
protected Appender createRollingRandomAccessFileAppender(final String fileName, Configuration loggingConfig, PatternLayout layout,
		final DefaultRolloverStrategy strategy, final String rolledFileFormat, final TriggeringPolicy trigger) {
       
       RollingRandomAccessFileManager fileManager = RollingRandomAccessFileManager.getRollingRandomAccessFileManager(
       		fileName, 
       		rolledFileFormat, 
       		true, 
       		true,
       		8192,
       		trigger, 
       		strategy, 
       		null, 
       		layout      		
       		);
       trigger.initialize(fileManager);
	
	return RollingRandomAccessFileAppender.createAppender(
			fileName, 						// file name
			rolledFileFormat, 				// rolled file name pattern
			"true", 						// append
			getClass().getSimpleName(), 	// appender name
			"true", 						// immediate flush
			"8192", 						// buffer size				
			trigger, 						// triggering policy
			strategy,						// rollover strategy
			layout, 						// layout
			null, 							// filter
			"true",							// ignore exceptions 
			null, 							// advertise
			null, 							// advertise uri
			loggingConfig);					// config
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:43,代码来源:LoggingWriter.java

示例6: testRollingRandomAccessFileAppender

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
/**
 * Tests LOG4J2-1740 Add CronTriggeringPolicy programmatically leads to NPE
 */
@Test
public void testRollingRandomAccessFileAppender() {
    // @formatter:off
    RollingRandomAccessFileAppender.newBuilder()
        .withName("test2")
        .withFileName("target/testcmd2.log")
        .withFilePattern("target/testcmd2.log.%d{yyyy-MM-dd}")
        .withPolicy(createPolicy())
        .withStrategy(createStrategy())
        .setConfiguration(configuration)
        .build();
    // @formatter:on
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:17,代码来源:CronTriggeringPolicyTest.java

示例7: getConfiguration

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
/**
 * Gets configuration as JSON.
 * Depends on the log4j core API.
 *
 * @param request  the request
 * @param response the response
 * @return the configuration
 * @throws Exception the exception
 */
@GetMapping(value = "/getConfiguration")
@ResponseBody
public Map<String, Object> getConfiguration(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    ensureEndpointAccessIsAuthorized(request, response);

    Assert.notNull(this.loggerContext);

    final Collection<Map<String, Object>> configuredLoggers = new HashSet<>();
    getLoggerConfigurations().forEach(config -> {
        final Map<String, Object> loggerMap = new HashMap<>();
        loggerMap.put("name", StringUtils.defaultIfBlank(config.getName(), LOGGER_NAME_ROOT));
        loggerMap.put("state", config.getState());
        if (config.getProperties() != null) {
            loggerMap.put("properties", config.getProperties());
        }
        loggerMap.put("additive", config.isAdditive());
        loggerMap.put("level", config.getLevel().name());
        final Collection<String> appenders = new HashSet<>();
        config.getAppenders().keySet().stream().map(key -> config.getAppenders().get(key)).forEach(appender -> {
            final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.JSON_STYLE);
            builder.append("name", appender.getName());
            builder.append("state", appender.getState());
            builder.append("layoutFormat", appender.getLayout().getContentFormat());
            builder.append("layoutContentType", appender.getLayout().getContentType());
            if (appender instanceof FileAppender) {
                builder.append(FILE_PARAM, ((FileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingFileAppender) {
                builder.append(FILE_PARAM, ((RollingFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingFileAppender) appender).getFilePattern());
            }
            if (appender instanceof MemoryMappedFileAppender) {
                builder.append(FILE_PARAM, ((MemoryMappedFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, "(none)");
            }
            if (appender instanceof RollingRandomAccessFileAppender) {
                builder.append(FILE_PARAM, ((RollingRandomAccessFileAppender) appender).getFileName());
                builder.append(FILE_PATTERN_PARAM, ((RollingRandomAccessFileAppender) appender).getFilePattern());
            }
            appenders.add(builder.build());
        });
        loggerMap.put("appenders", appenders);
        configuredLoggers.add(loggerMap);
    });
    final Map<String, Object> responseMap = new HashMap<>();
    responseMap.put("loggers", configuredLoggers);
    return responseMap;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:63,代码来源:LoggingConfigController.java

示例8: initialize

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
public static void initialize()
{
	// REDIRECT JAVA UTIL LOGGER TO LOG4J2 (MUST BE BEFORE ALL LOG4J2 CALLS)
	System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");

	// STARTING CONFIGURATION
	final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	org.apache.logging.log4j.core.config.Configuration configuration = loggerContext.getConfiguration();
	LoggerConfig rootLogger = configuration.getLoggerConfig("");
	rootLogger.setLevel(Level.ALL);

	// PATTERNS
	PatternLayout consolePattern = PatternLayout.createLayout("%d{yyyy-MM-dd HH:mm:ss} [%level] [%logger{1}]: %msg%n", configuration, null, null, true, false, null, null);
	PatternLayout logfilePattern = PatternLayout.createLayout("%d{yyyy-MM-dd HH:mm:ss} [%level] [%logger]: %msg%n", configuration, null, null, true, false, null, null);

	// LOG FILE STRINGS
	String logName = "NoMoreOversleeps";
	String logFilePrefix = PlatformData.installationDirectory.getAbsolutePath().replace("\\", "/") + "/logs/" + WordUtils.capitalizeFully(logName, new char[] { '_', '-', ' ' }).replaceAll("_", "").replaceAll("_", "").replaceAll("-", "").replaceAll(" ", "");

	// CLIENT LOG FILE APPENDER (ROLLING)
	RollingRandomAccessFileAppender clientInfoLogFile = RollingRandomAccessFileAppender.createAppender(logFilePrefix + "-0.log", logFilePrefix + "-%i.log", null, "InfoFile", null, null, OnStartupTriggeringPolicy.createPolicy(), DefaultRolloverStrategy.createStrategy("2", "1", "min", null, configuration), logfilePattern, null, null, null, null, configuration);
	clientInfoLogFile.start();
	configuration.addAppender(clientInfoLogFile);
	rootLogger.addAppender(clientInfoLogFile, Level.INFO, null);

	/*
	// FINER DETAIL LOG FILE (REPLACED ON EACH RUN)
	RandomAccessFileAppender detailLogFile = RandomAccessFileAppender.createAppender(logFilePrefix + "-latest-fine.log", "false", "DetailFile", null, null, null, logfilePattern, null, null, null, configuration);
	detailLogFile.start();
	configuration.addAppender(detailLogFile);
	rootLogger.addAppender(detailLogFile, Level.ALL, null);
	*/

	// CONSOLE APPENDER
	ConsoleAppender console = ConsoleAppender.createAppender(consolePattern, null, "SYSTEM_OUT", "Console", null, null); // must be named "Console" to work correctly
	console.start();
	configuration.addAppender(console);
	rootLogger.addAppender(console, Level.INFO, null);

	// UPDATE LOGGERS
	loggerContext.updateLoggers();

	// REDIRECT STDOUT AND STDERR TO LOG4J2
	System.setOut(new PrintStream(new StdOutErrOutputStream(LogManager.getLogger("java.lang.System.out"), Level.INFO)));
	System.setErr(new PrintStream(new StdOutErrOutputStream(LogManager.getLogger("java.lang.System.err"), Level.ERROR)));

	// set main engine log
	log = LogManager.getLogger();

	// print opening header
	log.info("===============================================================================================================");
	log.info(" NoMoreOversleeps v" + Main.VERSION);
	log.info(" (c) Robert James Dennington, " + Math.max(Calendar.getInstance().get(Calendar.YEAR), minCopyrightYear));
	log.info("===============================================================================================================");
	log.debug("The system log manager is " + System.getProperty("java.util.logging.manager"));
	log.info("Install path: " + PlatformData.installationDirectory.getAbsolutePath());
	log.info("Computer name: " + PlatformData.computerName);
	log.info("Platform: " + PlatformData.platformName);
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:60,代码来源:Logging.java

示例9: initialize

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
public static void initialize(Application application)
{
	// STORE APPLICATION FOR LATER USE
	Logging.application = application;

	// REDIRECT JAVA UTIL LOGGER TO LOG4J2 (MUST BE BEFORE ALL LOG4J2 CALLS)
	System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");

	// STARTING CONFIGURATION
	final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
	org.apache.logging.log4j.core.config.Configuration configuration = loggerContext.getConfiguration();
	LoggerConfig rootLogger = configuration.getLoggerConfig("");
	rootLogger.setLevel(Level.ALL);

	// PATTERNS
	PatternLayout consolePattern = PatternLayout.createLayout("%d{yyyy-MM-dd HH:mm:ss} [%level] [%logger{1}]: %msg%n", null, configuration, null, null, true, false, null, null);
	PatternLayout logfilePattern = PatternLayout.createLayout("%d{yyyy-MM-dd HH:mm:ss} [%level] [%logger]: %msg%n", null, configuration, null, null, true, false, null, null);

	// LOG FILE STRINGS
	String logFilePrefix = PlatformData.installationDirectory.getAbsolutePath().replace("\\", "/") + "/logs/" + WordUtils.capitalizeFully(application.getName(), new char[] { '_', '-', ' ' }).replaceAll("_", "").replaceAll("_", "").replaceAll("-", "").replaceAll(" ", "");

	// CLIENT LOG FILE APPENDER (ROLLING)
	RollingRandomAccessFileAppender clientInfoLogFile = RollingRandomAccessFileAppender.createAppender(logFilePrefix + "-0.log", logFilePrefix + "-%i.log", null, "InfoFile", null, null, OnStartupTriggeringPolicy.createPolicy(), DefaultRolloverStrategy.createStrategy("2", "1", "min", null, null, false, configuration), logfilePattern, null, null, null, null, configuration);
	clientInfoLogFile.start();
	configuration.addAppender(clientInfoLogFile);
	rootLogger.addAppender(clientInfoLogFile, Level.INFO, null);

	// FINER DETAIL LOG FILE (REPLACED ON EACH RUN)
	RandomAccessFileAppender detailLogFile = RandomAccessFileAppender.createAppender(logFilePrefix + "-latest-fine.log", "false", "DetailFile", null, null, null, logfilePattern, null, null, null, configuration);
	detailLogFile.start();
	configuration.addAppender(detailLogFile);
	rootLogger.addAppender(detailLogFile, Level.ALL, null);

	// CONSOLE APPENDER
	ConsoleAppender console = ConsoleAppender.createAppender(consolePattern, null, Target.SYSTEM_OUT, "Console", false, true); // must be named "Console" to work correctly
	console.start();
	configuration.addAppender(console);
	rootLogger.addAppender(console, Level.INFO, null);

	// UPDATE LOGGERS
	loggerContext.updateLoggers();

	// REDIRECT STDOUT AND STDERR TO LOG4J2
	System.setOut(new PrintStream(new StdOutErrOutputStream(LogManager.getLogger("java.lang.System.out"), Level.INFO)));
	System.setErr(new PrintStream(new StdOutErrOutputStream(LogManager.getLogger("java.lang.System.err"), Level.ERROR)));

	// set main engine log
	log = LogManager.getLogger();

	// print opening header
	log.info("===============================================================================================================");
	log.info(" " + application.getName() + " v" + application.getVersion());
	log.info(" (c) Robert James Dennington, " + Math.max(Calendar.getInstance().get(Calendar.YEAR), minCopyrightYear));
	log.info("===============================================================================================================");
	log.debug("The system log manager is " + System.getProperty("java.util.logging.manager"));
	log.info("Install path: " + PlatformData.installationDirectory.getAbsolutePath());
	log.info("Computer name: " + PlatformData.computerName);
	log.info("Platform: " + PlatformData.platformName);
}
 
开发者ID:PolyphasicDevTeam,项目名称:NapBot,代码行数:60,代码来源:Logging.java

示例10: ForwardHandler

import org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender; //导入依赖的package包/类
public ForwardHandler(@Nullable RollingRandomAccessFileAppender log4jAppender) {
    this.log4jAppender = log4jAppender;
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLibv2,代码行数:4,代码来源:ForwardHandler.java


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