org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender Java Examples
The following examples show how to use
org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestFileAuditAppender.java From syncope with Apache License 2.0 | 6 votes |
@Override protected 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(). setName(getTargetAppenderName()). withAppend(true). withFileName(pathPrefix + getTargetAppenderName() + ".log"). setLayout(PatternLayout.newBuilder(). withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n"). build()). build(); }
Example #2
Source File: TestFileRewriteAuditAppender.java From syncope with Apache License 2.0 | 5 votes |
@Override protected 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(). setName(getTargetAppenderName()). withAppend(true). withFileName(pathPrefix + getTargetAppenderName() + ".log"). setLayout(PatternLayout.newBuilder(). withPattern("%d{HH:mm:ss.SSS} %-5level %logger - %msg%n"). build()). build(); }
Example #3
Source File: CronTriggeringPolicyTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
/** * Tests LOG4J2-1740 Add CronTriggeringPolicy programmatically leads to NPE */ @Test public void testRollingRandomAccessFileAppender() { // @formatter:off RollingRandomAccessFileAppender.newBuilder() .setName("test2") .setFileName("target/testcmd2.log") .setFilePattern("target/testcmd2.log.%d{yyyy-MM-dd}") .setPolicy(createPolicy()) .setStrategy(createStrategy()) .setConfiguration(configuration) .build(); // @formatter:on }
Example #4
Source File: LogFormatter.java From VoxelGamesLibv2 with MIT License | 4 votes |
public LogFormatter(@Nullable RollingRandomAccessFileAppender log4jAppender, ErrorHandler errorHandler) { this.log4jAppender = log4jAppender; this.errorHandler = errorHandler; }
Example #5
Source File: Log4j2HookProxy.java From uavstack with Apache License 2.0 | 4 votes |
private LogProfileInfo getAppenderInfo(Appender appender, String appid) { if(appender == null) { return null; } String fileName; if (appender instanceof FileAppender) { fileName = ((FileAppender) appender).getFileName(); } else if (appender instanceof RollingFileAppender) { fileName = ((RollingFileAppender) appender).getFileName(); } else if (appender instanceof RollingRandomAccessFileAppender) { fileName = ((RollingRandomAccessFileAppender) appender).getFileName(); } else if (appender instanceof RandomAccessFileAppender) { fileName = ((RandomAccessFileAppender) appender).getFileName(); } else if (appender instanceof MemoryMappedFileAppender) { fileName = ((MemoryMappedFileAppender) appender).getFileName(); } else { return null; } Map<String, String> attributes = new HashMap<String, String>(); attributes.put(LogProfileInfo.ENGINE, "log4j2"); Layout<?> layout = appender.getLayout(); if (null != layout) { if (layout instanceof PatternLayout) { attributes.put(LogProfileInfo.PATTERN, ((PatternLayout) layout).getConversionPattern()); } else { attributes.put(LogProfileInfo.PATTERN, layout.getClass().getSimpleName()); } } LogProfileInfo logProfileInfo = new LogProfileInfo(); logProfileInfo.setAppId(appid); logProfileInfo.setFilePath(fileName); logProfileInfo.setAttributes(attributes); logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j); return logProfileInfo; }