Skip to content

aliahmad8701/Log4j-Assignment_homework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log4j Assignment

The assignment demonstrates the use of the following two features of [Apache Log4j 2](https://logging.apache.org/log4j/2.x/):

Markers provide a means for tagging log messages that enables the filtering of messages of various types. For example, different markers can be used for logging user interface events and database operations. Thread Context enables automatic insertion of values from key-value pairs into log messages.

Create an Apache Maven project with the following two dependencies:

Create a Main class whose main method logs the lines of a nursery rhyme in a loop, where the number of iterations must be provided as a command-line argument. The lines of the poem must be logged at various levels. You must use at least two different markers for logging. All but one of the log messages generated in the loop must be marked with a marker. For example, you can use different markers for assertions (e.g., The mouse ran up the clock.) and gibberish (e.g., Hickory, dickory, dock.). You must add some delay between the iterations with the Thread.sleep(long millis) method.

Create a log4j2.xml configuration file that configures a ConsoleAppender and an appropriate number of FileAppenders as follows.

All log messages must be shown on the console. Log messages marked with different markers must be written to different files. For this purpose, you must use MarkerFilters. Log messages not marked with any marker must be written to a separate file using a NoMarkerFilter.

Log messages written to the console and log files must contain the current iteration number. The iteration number must be automatically inserted with the ThreadContext class and the %X conversion pattern of Pattern Layout. It is not allowed to refer to the iteration number in the logging methods.

A separate FileAppender must be configured such that messages logged during the curfew hours (i.e., between 20:00 and 05:00) must be written to a separate file. This requires a properly configured TimeFilter.

Implementation Notes:

  • Iterations are limited to the command line Input.
  • Iteration delay is 3 seconds.
  • 4 Logs files from the first run are added.
    • Rhyme, Gibberish, Marker-notfound and Curfew-time.

Releases

No releases published

Packages

No packages published

Languages