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


Java WriterAppender類代碼示例

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


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

示例1: testPrintPaths

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
@Test
public void testPrintPaths() {
  RestOperationMeta staticRes = UnitTestRestUtils.createRestOperationMeta("POST", "/static");
  RestOperationMeta dynamicRes = UnitTestRestUtils.createRestOperationMeta("POST", "/dynamic/{id}");

  MicroservicePaths paths = new MicroservicePaths();
  paths.addResource(staticRes);
  paths.addResource(dynamicRes);

  WriterAppender appender = new WriterAppender();
  Writer writer = new StringWriter();
  appender.setWriter(writer);
  appender.setLayout(new SimpleLayout());
  Logger.getRootLogger().addAppender(appender);

  paths.printPaths();

  String[] lines = writer.toString().split("\n");
  Assert.assertEquals("INFO - Swagger mapped \"{[/static], method=[POST], produces=[application/json]}\" onto null",
      lines[0].trim());
  Assert.assertEquals(
      "INFO - Swagger mapped \"{[/dynamic/{id}], method=[POST], produces=[application/json]}\" onto null",
      lines[1].trim());

  Logger.getRootLogger().removeAppender(appender);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:27,代碼來源:TestMicroservicePaths.java

示例2: testPrint

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

	DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
	graph.addVertex( YURI );
	graph.addVertex( YUGO );
	graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );

	Collection<URI> roots = Arrays.asList( YURI );
	GraphToTreeConverter.Search search = GraphToTreeConverter.Search.DFS;
	Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );

	Logger log = Logger.getLogger( GraphToTreeConverter.class );
	StringWriter stringy = new StringWriter();
	WriterAppender app = new WriterAppender( new SimpleLayout(), stringy );
	log.setLevel( Level.DEBUG );
	log.addAppender( app );
	GraphToTreeConverter.printForest( result );
	String output = stringy.toString().replaceAll( "\\s", "" );
	assertEquals( "DEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/YuriDEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/Yugo", output );
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:22,代碼來源:GraphToTreeConverterTest.java

示例3: testMissingSprite

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if the sprite file is
 * invalid.
 */
@Test
public void testMissingSprite() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String inValidSpriteFile = "Sprite asdfsdfSheet";
	SpriteLoader spriteLoader = new SpriteLoader();

	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(inValidSpriteFile, 32, 32);
		spriteLoader.getSprite(1, 0);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You are trying to use a"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例4: testNegativeDimensions

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if an incorrect position
 * (on the sprite sheet) is entered.
 */
@Test
public void testNegativeDimensions() {

	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();
	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
		spriteLoader.getSprite(-1, -1);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You are requesting a grid position"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例5: testPositiveDimensions

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if an incorrect position
 * (on the sprite sheet) is entered.
 */
@Test
public void testPositiveDimensions() {

	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();
	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
		spriteLoader.getSprite(6, 6);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You are requesting a grid position"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例6: testInvalidSpriteSheetDimensions

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if an invalid specified
 * sprite dimension is entered.
 */
@Test
public void testInvalidSpriteSheetDimensions() {

	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();
	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 13, 13);
		spriteLoader.getSprite(1, 0);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("WARN - Your file is not a multiple of"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例7: testValidSpriteDimensions

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that no logger message is executed if valid specified sprite
 * dimensions are entered.
 */
@Test
public void testValidSpriteDimensions() {
	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();
	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
		spriteLoader.getSprite(1, 0);

		String logMessage = outputStream.toString();
		assertEquals("", logMessage);// should be empty
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:27,代碼來源:SpriteLoaderTests.java

示例8: testNullSpriteSheet

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if a null sprite sheet
 * file name is entered (i.e. does not exist due to trolling, typos)
 */
@Test
public void testNullSpriteSheet() {
	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Null file name
	String nullSpriteFile = null;
	SpriteLoader spriteLoader = new SpriteLoader();

	try {
		// The function to test
		spriteLoader.loadSpriteSheet(nullSpriteFile, 32, 32);
		assertNull(nullSpriteFile);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - Could not load file"));

	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:30,代碼來源:SpriteLoaderTests.java

示例9: testInvalidSpriteSheet

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if an invalid sprite
 * sheet file name is entered (i.e. does not exist due to trolling, typos)
 */
@Test
public void testInvalidSpriteSheet() {
	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Invalid file name
	String invalidSpriteFile = "invalid name";
	SpriteLoader spriteLoader = new SpriteLoader();

	try {
		// The function to test
		spriteLoader.loadSpriteSheet(invalidSpriteFile, 32, 32);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - Could not load file"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:28,代碼來源:SpriteLoaderTests.java

示例10: testValidSpriteSheet

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that no logger message is executed if a valid sprite sheet is
 * entered
 */
@Test
public void testValidSpriteSheet() {
	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();

	try {
		// The function to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
		assertNotNull(validSpriteFile);
		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertEquals("", logMessage);// should be empty
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:28,代碼來源:SpriteLoaderTests.java

示例11: validFrameInitialisation

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that no logger message is executed for a valid frame setup.
 */
@Test
public void validFrameInitialisation() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	Image mockSprite = mock(Image.class);

	try {
		// The functions to test
		frame = new Frame(mockSprite, 10);
		assertNotNull(frame.getFrame());
		assertTrue(frame.getDuration() == 10);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertEquals("", logMessage);
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:27,代碼來源:FrameTests.java

示例12: validGetters

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that getters are not null if there is a valid Frame initilisation.
 */
@Test
public void validGetters() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	Image mockSprite = mock(Image.class);

	try {
		// The functions to test
		frame = new Frame(mockSprite, 10);
		assertNotNull(frame.getFrame());
		assertNotNull(frame.getDuration());

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertEquals("", logMessage);
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:27,代碼來源:FrameTests.java

示例13: inValidFrame

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the appropriate error message is displayed if the frame image
 * is null.
 */
@Test
public void inValidFrame() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	try {
		// The functions to test
		frame = new Frame(null, 10);
		assertNull(frame.getFrame());

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You cannot have null frames"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:25,代碼來源:FrameTests.java

示例14: inValidDuration

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the appropriate logger message is executed if the duration is
 * less than or equal to 0.
 */
@Test
public void inValidDuration() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	Image mockSprite = mock(Image.class);

	try {
		// The functions to test
		frame = new Frame(mockSprite, 0);
		assertTrue(frame.getDuration() == 0);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You cannot have a duration equal to or less than 0"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:27,代碼來源:FrameTests.java

示例15: invalidSettersDuration

import org.apache.log4j.WriterAppender; //導入依賴的package包/類
/**
 * Tests that the appropriate logger message is executed if the duration is
 * set to be less than or equal to 0.
 */
@Test
public void invalidSettersDuration() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	Image mockSprite = mock(Image.class);
	frame = new Frame(mockSprite, 10);

	try {
		// The functions to test
		assertTrue(frame.getDuration() == 10);
		frame.setDuration(-1);
		assertTrue(frame.getDuration() == 10);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You cannot have a duration"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:FrameTests.java


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