private static OutputStreamManager getDefaultManager(final Target target, final boolean follow, final boolean direct, final Layout<? extends Serializable> layout) { OutputStream os = NullOutputStream.getInstance(); String managerName = target.name() + '.' + follow + '.' + direct + "-" + COUNT.get(); return OutputStreamManager.getManager(managerName, new FactoryData(os, managerName, layout), MANAGER_FACTORY); }
private static OutputStreamManager getManager(final Target target, final boolean follow, final boolean direct, final Layout<? extends Serializable> layout) { OutputStream os = NullOutputStream.getInstance(); String managerName = "null." + target.name() + '.' + follow + '.' + direct; return OutputStreamManager.getManager(managerName, new FactoryData(os, managerName, layout), MANAGER_FACTORY); }
@Test public void logWriterLevelIsPassedIntoConstructor() { ManagerLogWriter logWriter = new ManagerLogWriter(CONFIG.intLevel(), new PrintStream(NullOutputStream.getInstance()), true); assertThat(logWriter.getLogWriterLevel()).isEqualTo(CONFIG.intLevel()); } }
/** * Test method for * {@link org.apache.logging.log4j.core.appender.RandomAccessFileManager#writeBytes(byte[], int, int)} * . */ @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = folder.newFile(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3; final byte[] data = new byte[size]; manager.write(data); // no buffer overflow exception // all data is written if exceeds buffer size assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length()); }}
/** * Test method for * {@link org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager#writeBytes(byte[], int, int)} */ @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final boolean append = false; final boolean flushNow = false; final long triggerSize = Long.MAX_VALUE; final long time = System.currentTimeMillis(); final TriggeringPolicy triggerPolicy = new SizeBasedTriggeringPolicy(triggerSize); final RolloverStrategy rolloverStrategy = null; final RollingRandomAccessFileManager manager = new RollingRandomAccessFileManager(null, raf, file.getName(), Strings.EMPTY, os, append, flushNow, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE, triggerSize, time, triggerPolicy, rolloverStrategy, null, null, null, null, null, true); final int size = RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3; final byte[] data = new byte[size]; manager.write(data, 0, data.length, flushNow); // no buffer overflow exception // buffer is full but not flushed yet assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length()); } }
/** * Test method for * {@link org.apache.logging.log4j.core.appender.rolling.RollingRandomAccessFileManager#writeBytes(byte[], int, int)} . */ @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final boolean append = false; final boolean flushNow = false; final long triggerSize = 0; final long time = System.currentTimeMillis(); final TriggeringPolicy triggerPolicy = new SizeBasedTriggeringPolicy(triggerSize); final RolloverStrategy rolloverStrategy = null; final RollingRandomAccessFileManager manager = new RollingRandomAccessFileManager(null, raf, file.getName(), Strings.EMPTY, os, append, flushNow, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE, triggerSize, time, triggerPolicy, rolloverStrategy, null, null, null, null, null, true); final int size = RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1; final byte[] data = new byte[size]; manager.write(data, 0, data.length, flushNow); // no exception assertEquals(RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length()); manager.flush(); assertEquals(size, raf.length()); // all data written to file now } }
@Test public void testConfigurableBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final boolean append = false; final boolean flushNow = false; final long triggerSize = 0; final long time = System.currentTimeMillis(); final TriggeringPolicy triggerPolicy = new SizeBasedTriggeringPolicy(triggerSize); final int bufferSize = 4 * 1024; assertNotEquals(bufferSize, RollingRandomAccessFileManager.DEFAULT_BUFFER_SIZE); final RolloverStrategy rolloverStrategy = null; final RollingRandomAccessFileManager manager = new RollingRandomAccessFileManager(null, raf, file.getName(), Strings.EMPTY, os, append, flushNow, bufferSize, triggerSize, time, triggerPolicy, rolloverStrategy, null, null, null, null, null, true); // check the resulting buffer size is what was requested assertEquals(bufferSize, manager.getBufferSize()); } }
@Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = folder.newFile(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final int bufferSize = 1; final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), os, bufferSize, null, null, true); final int size = bufferSize * 3 + 1; final byte[] data = new byte[size]; manager.write(data); // no exception // all data is written if exceeds buffer size assertEquals(bufferSize * 3 + 1, raf.length()); manager.flush(); assertEquals(size, raf.length()); // all data written to file now }}
@Test public void testConfigurableBufferSize() throws IOException { final File file = folder.newFile(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final int bufferSize = 4 * 1024; assertNotEquals(bufferSize, RandomAccessFileManager.DEFAULT_BUFFER_SIZE); final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), os, bufferSize, null, null, true); // check the resulting buffer size is what was requested assertEquals(bufferSize, manager.getBufferSize()); }}
/** * Test method for * {@link org.apache.logging.log4j.core.appender.RandomAccessFileManager#writeBytes(byte[], int, int)} * . */ @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = folder.newFile(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream os = NullOutputStream.getInstance(); final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1; final byte[] data = new byte[size]; manager.write(data); // no exception // all data is written if exceeds buffer size assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length()); manager.flush(); assertEquals(size, raf.length()); // all data written to file now }}
final OutputStream os = NullOutputStream.getInstance(); RandomAccessFile raf; try {
final OutputStream os = NullOutputStream.getInstance(); RandomAccessFile raf = null; try {
NullOutputStream.getInstance(), data.append, data.immediateFlush, data.bufferSize, size, time, data.policy, data.strategy, data.advertiseURI, data.layout, data.filePermissions, data.fileOwner, data.fileGroup, writeHeader); if (rrm.isAttributeViewEnabled()) {
@SuppressWarnings("resource") @Override public M createManager(final String name, final T data) { InetAddress inetAddress; OutputStream os; try { inetAddress = InetAddress.getByName(data.host); } catch (final UnknownHostException ex) { LOGGER.error("Could not find address of {}: {}", data.host, ex, ex); return null; } Socket socket = null; try { // LOG4J2-1042 socket = createSocket(data); os = socket.getOutputStream(); return createManager(name, os, socket, inetAddress, data); } catch (final IOException ex) { LOGGER.error("TcpSocketManager ({}) caught exception and will continue:", name, ex, ex); os = NullOutputStream.getInstance(); } if (data.reconnectDelayMillis == 0) { Closer.closeSilently(socket); return null; } return createManager(name, os, null, inetAddress, data); }