tree: 75901ffb364a140c05b15c3f5fe57e0544a01c46 [path history] [tgz]
  1. __files/
  2. bad/
  3. customplugin/
  4. LOG4J-2195/
  5. LOG4J2-1100/
  6. logger-config/
  7. META-INF/
  8. org/
  9. perf/
  10. rolloverPath/
  11. s p a c e s/
  12. scripts/
  13. witness/
  14. AsyncAppenderConfigTest-LOG4J2-2032.xml
  15. AsyncLoggerConfigAutoFlushTest.xml
  16. AsyncLoggerConfigErrorOnFormat.xml
  17. AsyncLoggerConfigTest.xml
  18. AsyncLoggerConfigTest2.xml
  19. AsyncLoggerConfigTest4.xml
  20. AsyncLoggerConfigThreadContextTest.xml
  21. AsyncLoggerConsoleTest.xml
  22. AsyncLoggerCustomSelectorLocationTest.xml
  23. AsyncLoggerLocationTest.xml
  24. AsyncLoggersWithAsyncAppenderTest.xml
  25. AsyncLoggersWithAsyncLoggerConfigTest.xml
  26. AsyncLoggerTest.xml
  27. AsyncLoggerThreadContextTest.xml
  28. AsyncLoggerTimestampMessageTest.xml
  29. BlockingQueueFactory-ArrayBlockingQueue.xml
  30. BlockingQueueFactory-DisruptorBlockingQueue.xml
  31. BlockingQueueFactory-JCToolsBlockingQueue.xml
  32. BlockingQueueFactory-LinkedTransferQueue.xml
  33. configPropertyTest.xml
  34. ContextMapLookupTest.xml
  35. EventParameterMemoryLeakTest.xml
  36. FlumeFuncTest.xml
  37. gcFreeLogging.xml
  38. gcFreeMixedSyncAsyncLogging.xml
  39. GelfLayoutTest2.xml
  40. GelfLayoutTest3.xml
  41. HttpAppenderTest.xml
  42. JeroMqAppenderTest.xml
  43. JmsAppenderTest.xml
  44. JsonCompleteFileAppenderTest.xml
  45. legacy-plugins.xml
  46. log4j+config+with+plus+characters.xml
  47. log4j-advertiser.xml
  48. log4j-appender-selector-groovy.xml
  49. log4j-appender-selector-javascript.xml
  50. log4j-asynch-no-location.xml
  51. log4j-asynch-queue-full.xml
  52. log4j-asynch-shutdownTimeout.xml
  53. log4j-asynch.xml
  54. log4j-burst.xml
  55. log4j-collectionLogging.xml
  56. log4j-comp-appender.json
  57. log4j-comp-appender.xml
  58. log4j-comp-filter.json
  59. log4j-comp-filter.xml
  60. log4j-comp-logger-attr-override.json
  61. log4j-comp-logger-ref.json
  62. log4j-comp-logger-ref.xml
  63. log4j-comp-logger-root.xml
  64. log4j-comp-logger.json
  65. log4j-comp-logger.xml
  66. log4j-comp-properties.json
  67. log4j-comp-properties.xml
  68. log4j-comp-reconfig.properties
  69. log4j-comp-reconfig.xml
  70. log4j-comp-root-loggers.xml
  71. log4j-config.json
  72. log4j-console.xml
  73. log4j-cronRolloverApp.xml
  74. log4j-customLevel.xml
  75. log4j-customLevels.xml
  76. log4j-customLevelsOverride.xml
  77. log4j-customLevelsWithFilters.xml
  78. log4j-date.xml
  79. log4j-deadlock.xml
  80. log4j-empty.xml
  81. log4j-failover.xml
  82. log4j-filetest.xml
  83. log4j-jira965.xml
  84. log4j-Level.xml
  85. log4j-list-nolookups.xml
  86. log4j-list.xml
  87. log4j-loggerprops.xml
  88. log4j-lookup-main.xml
  89. log4j-lookup.xml
  90. log4j-marker-lookup.yaml
  91. log4j-message-ansi.xml
  92. log4j-message-styled.xml
  93. log4j-nested-logging-throwable-message.xml
  94. log4j-patternSelector.xml
  95. log4j-posix.xml
  96. log4j-props.xml
  97. log4j-props1.xml
  98. log4j-reference-level.json
  99. log4j-reference-level.xml
  100. log4j-replace.xml
  101. log4j-rewrite.xml
  102. log4j-rolling-7z-lazy.xml
  103. log4j-rolling-7z.xml
  104. log4j-rolling-bzip2-lazy.xml
  105. log4j-rolling-bzip2.xml
  106. log4j-rolling-cron-and-size.xml
  107. log4j-rolling-cron-every2-direct.xml
  108. log4j-rolling-cron-every2.xml
  109. log4j-rolling-cron-once-a-day.xml
  110. log4j-rolling-cron.xml
  111. log4j-rolling-cron2.xml
  112. log4j-rolling-deflate-lazy.xml
  113. log4j-rolling-deflate.xml
  114. log4j-rolling-direct-1906.xml
  115. log4j-rolling-direct-reconfigure.xml
  116. log4j-rolling-direct-startup-size.xml
  117. log4j-rolling-direct-tmp-compress-folder.xml
  118. log4j-rolling-direct.xml
  119. log4j-rolling-gz-lazy.xml
  120. log4j-rolling-gz-posix.xml
  121. log4j-rolling-gz-tmp-compress.xml
  122. log4j-rolling-gz.xml
  123. log4j-rolling-numbered-gz.xml
  124. log4j-rolling-pack200-lazy.xml
  125. log4j-rolling-pack200.xml
  126. log4j-rolling-random-direct.xml
  127. log4j-rolling-reconfigure.xml
  128. log4j-rolling-size-with-time.xml
  129. log4j-rolling-size.xml
  130. log4j-rolling-with-custom-delete-accum-count1.xml
  131. log4j-rolling-with-custom-delete-accum-count2.xml
  132. log4j-rolling-with-custom-delete-accum-size.xml
  133. log4j-rolling-with-custom-delete-maxdepth.xml
  134. log4j-rolling-with-custom-delete-nested.xml
  135. log4j-rolling-with-custom-delete-script-fri13th.xml
  136. log4j-rolling-with-custom-delete-script.xml
  137. log4j-rolling-with-custom-delete-unconditional1.xml
  138. log4j-rolling-with-custom-delete-unconditional2.xml
  139. log4j-rolling-with-custom-delete-unconditional3.xml
  140. log4j-rolling-with-custom-delete.xml
  141. log4j-rolling-with-padding.xml
  142. log4j-rolling-xz-lazy.xml
  143. log4j-rolling-xz.xml
  144. log4j-rolling-zip-lazy.xml
  145. log4j-rolling-zip.xml
  146. log4j-rolling.properties
  147. log4j-rolling2.xml
  148. log4j-rolling3-direct.xml
  149. log4j-rolling3.xml
  150. log4j-rolling4.xml
  151. log4j-rootthrowablefilter.xml
  152. log4j-routing-by-jndi.xml
  153. log4j-routing-default-route-script-groovy.xml
  154. log4j-routing-default-route-script-javascript.xml
  155. log4j-routing-purge.xml
  156. log4j-routing-routes-script-groovy.xml
  157. log4j-routing-routes-script-javascript.xml
  158. log4j-routing-script-staticvars-groovy.xml
  159. log4j-routing-script-staticvars-javascript.xml
  160. log4j-routing.json
  161. log4j-routing.properties
  162. log4j-routing.xml
  163. log4j-routing2.json
  164. log4j-routing3.xml
  165. log4j-script-filters.xml
  166. log4j-scriptFile-filters.properties
  167. log4j-scriptFile-filters.xml
  168. log4j-scriptRef-filters.xml
  169. log4j-socket-options.xml
  170. log4j-socket.xml
  171. log4j-socket2.xml
  172. log4j-ssl-socket-options.xml
  173. log4j-strict1.xml
  174. log4j-style.xml
  175. log4j-sync-to-list.xml
  176. log4j-test-shutdownTimeout.xml
  177. log4j-test1.json
  178. log4j-test1.properties
  179. log4j-test1.xml
  180. log4j-test1.yaml
  181. log4j-test2.properties
  182. log4j-test2.xml
  183. log4j-test3.xml
  184. log4j-test4.xml
  185. log4j-test5.xml
  186. log4j-threaded.xml
  187. log4j-throwable.xml
  188. log4j-throwablefilter.xml
  189. log4j-xinclude-appenders.xml
  190. log4j-xinclude-loggers.xml
  191. log4j-xinclude.xml
  192. log4j.dtd
  193. log4j12-perf.xml
  194. log4j2-1002.xml
  195. log4j2-1482.xml
  196. log4j2-1573.xml
  197. log4j2-180.xml
  198. log4j2-2134.yml
  199. log4j2-272.xml
  200. log4j2-319.xml
  201. LOG4J2-739.xml
  202. log4j2-744.xml
  203. LOG4J2-807.xml
  204. log4j2-962.xml
  205. log4j2-calling-class.xml
  206. log4j2-config.xml
  207. log4j2-console-default-suppressed-throwable.xml
  208. log4j2-console-disableAnsi.xml
  209. log4j2-console-highlight-default.xml
  210. log4j2-console-highlight-logback.xml
  211. log4j2-console-highlight.xml
  212. log4j2-console-msg-ansi.xml
  213. log4j2-console-noConsoleNoAnsi.xml
  214. log4j2-console-progress.xml
  215. log4j2-console-style-ansi.xml
  216. log4j2-console-style-name-ansi.xml
  217. log4j2-console-style-no-ansi.xml
  218. log4j2-console-xex-ansi-custom.xml
  219. log4j2-console-xex-ansi-kirk.xml
  220. log4j2-console-xex-ansi.xml
  221. log4j2-console.xml
  222. log4j2-dynamicfilter.xml
  223. log4j2-gelf-layout.xml
  224. log4j2-json-layout.xml
  225. log4j2-mapfilter.xml
  226. log4j2-perf-filter.xml
  227. log4j2-perf.xml
  228. log4j2-properties-root-only.properties
  229. log4j2-properties-trailing-space-on-level.properties
  230. log4j2-properties.properties
  231. log4j2-queueFull.xml
  232. log4j2-queueFullAsyncAppender.xml
  233. log4j2-queueFullAsyncLoggerConfig.xml
  234. log4j2-random-1833.xml
  235. log4j2-rolling-1833.xml
  236. log4j2-sdfilter.xml
  237. log4j2-xml-layout.xml
  238. logback-flume.xml
  239. logback-perf-filter.xml
  240. logback-perf.xml
  241. logback-subst.xml
  242. logback-test.xml
  243. MemoryMappedFileAppenderLocationTest.xml
  244. MemoryMappedFileAppenderRemapTest.xml
  245. MemoryMappedFileAppenderTest.xml
  246. missingRootLogger.xml
  247. multipleIncompatibleAppendersTest.xml
  248. multipleRootLoggersTest.xml
  249. NanoTimeToFileTest.xml
  250. perf-CountingNoOpAppender.xml
  251. perf-log4j12-async.xml
  252. perf-log4j12.xml
  253. perf-logback-async.xml
  254. perf-logback.xml
  255. perf1syncFastFile.xml
  256. perf1syncFile.xml
  257. perf2syncRollFastFile.xml
  258. perf2syncRollFile.xml
  259. perf3PlainNoLoc.xml
  260. perf4PlainLocation.xml
  261. perf5AsyncApndNoLoc.xml
  262. perf6AsyncApndLoc.xml
  263. perf7MixedNoLoc.xml
  264. perf8MixedLoc.xml
  265. perf9MMapNoLoc.xml
  266. RandomAccessFileAppenderLocationTest.xml
  267. RandomAccessFileAppenderTest.xml
  268. README.md
  269. reconfiguration-deadlock.xml
  270. rolling-file-appender-reconfigure.original.xml
  271. rolling-file-appender-reconfigure.xml
  272. RollingRandomAccessFileAppenderHeaderFooterTest.xml
  273. RollingRandomAccessFileAppenderLocationPropsTest.properties
  274. RollingRandomAccessFileAppenderLocationTest.xml
  275. RollingRandomAccessFileAppenderTest.xml
  276. rollover-test.xml
  277. SequenceNumberPatternConverterTest.yml
  278. SequenceNumberPatternConverterZeroPaddedTest.yml
  279. serializedEvent.dat
  280. ShutdownCallbackRegistryTest.xml
  281. SmtpAppenderAsyncTest.xml
  282. xml-events.xml
  283. XmlCompactFileAppenderTest.xml
  284. XmlCompactFileAppenderValidationTest.xml
  285. XmlCompactFileAsyncAppenderValidationTest.xml
  286. XmlCompleteFileAppenderTest.xml
  287. XmlConfigurationSecurity.xml
  288. XmlFileAppenderTest.xml
  289. XmlRandomAccessFileAppenderTest.xml
log4j-core/src/test/resources/README.md

This directory is mainly for storing configuration files used in various unit tests. As such, there are a few things provided for your convenience in writing and maintaining unit tests.

Running Unit Tests

First, make sure you've recently run mvn clean install in log4j-api to get an up to date dependency. Then you can run mvn test to run unit tests, or run mvn verify to run both unit tests and integration/performance tests.

Test Plugins

Included are various Log4j plugins that are only useful for writing tests. These test plugins are automatically made available to test classes. For instance, to use the ListAppender:

<Configuration>
  <Appenders>
    <List name="List"/>
  </Appenders>
  <Loggers>
    <Logger name="org.apache.logging.log4j" level="debug">
      <AppenderRef ref="List"/>
    </Logger>
  </Loggers>
</Configuration>

Note that if you don't specify a layout for a ListAppender, your log messages will be stored in a list of LogEvents. With a layout, your log messages will be stored in a list of strings. For more details, check out the class org.apache.logging.log4j.test.appender.ListAppender.

Specifying Configuration Files in JUnit Tests

Added in JUnit 4.9, the concept of test fixtures (i.e., the @Before, @After, etc. methods) has been expanded into the concept of test rules. A test rule is a reusable test fixture such as the TemporaryFolder JUnit rule for creating temporary directories and files on a test-by-test (or suite) basis. To use a test rule, you need to use the @Rule or @ClassRule annotation to get a method-level or class-level test fixture respectively. For instance, suppose your test class uses the file named MyTestConfig.xml in this directory. Then you can use the following rule in your test class:

@Rule
public InitialLoggerContext init = new InitialLoggerContext("MyTestConfig.xml");

@Test
public void testSomeAwesomeFeature() {
    final LoggerContext ctx = init.getContext();
    final Logger logger = init.getLogger("org.apache.logging.log4j.my.awesome.test.logger");
    final Configuration cfg = init.getConfiguration();
    final ListAppender app = init.getListAppender("List");
    logger.warn("Test message");
    final List<LogEvent> events = app.getEvents();
    // etc.
}

Using this rule will automatically create a new LoggerContext using the specified configuration file for you to retrieve via the getContext() method shown above. After the method finishes (or if you use @ClassRule and make the field static), the LoggerContext is automatically stopped. No longer do you need to set any system properties, reset the StatusLogger configuration, and all that other fun boilerplate code.

Cleaning Up Test Log Files

The CleanFiles rule is also available to automatically delete a list of files after every test.

@Rule
public CleanFiles files = new CleanFiles("target/file1.log", "target/file2.log", "more files");

You can specify either a list of strings or a list of Files.

If you have any questions about writing unit tests, feel free to send an email to the dev mailing list, or check out the JUnit documentation over at junit.org.

Specifying Test Categories

If your test is something more than just a unit test, it's usually a good idea to add a JUnit category to it. This can be done at the class or method level:

@Category(PerformanceTests.class)
@Test
public void testRandomAccessFileLogging() {
    // ...
}

Various pre-defined categories are defined in org.apache.logging.log4j.categories in log4j-core test. If you only want to run your test as part of the maven-failsafe-plugin integration tests phase, then simply name your test FooIT instead of FooTest for automatic configuration.