Question: 1 . Create a class to represent a log message. The log message should include the following attributes: The severity of the message from least

1. Create a class to represent a log message. The log message should include the following attributes:
The severity of the message from least to most severe: DEBUG, INFO, WARNING, ERROR, or CRITICAL.
The name of the module that has created the log.
The timestamp at which the log was created in the format YYYY/MM/dd HH:mm:ss.SSS(see java.text.SimpleDateFormat).
The message to be logged.
A toString() method that returns a string in the format:
[severity][timestamp][name] message
2.
Create a Logger class with the following attributes:
A constructor that accepts a filename as a parameter.
A queue of log messages.
A method that, given a log message, will add the message to the queue.
Any messages added to the queue should be logged In a separate thread (do not block while logging):
Write the message out to standard output.
Write the message out to the file. The file should not be kept open longer than necessary to write the messages in the queue. In other words, it should be opened and closed as needed. FileOutputStream provides a constructor that will append to a file. If an IOException occurs, print the stack trace and exit.
You must guarantee that log messages are logged in the order in which they are added to the queue.
3. Create a class to act as a producer. A producer should have at least the following attributes:
A producer is a thread.
The producer should be constructed with a Logger and a BufferedReader.
While executing, the producer should sleep for a random number of milliseconds between 0 and 5000.
When the producer awakens from sleep, it should generate a log message and use the Logger to log it. Use a random severity. The message should be the next line from the provided file.
No two producers should log the same line from the file. As much as possible, the lines should be logged in order. If you reach the end of the file, the producer should stop. If an IOException occurs, print the stack trace and exit.
4. Create a class named Simulation. Add a main method.
The main method should expect three command-line arguments. If the wrong number of arguments is specified, print a usage message and exit with an error code.
The first argument should be the log filename. Use it to create the Logger.
The second argument will be the name of the input file used by the producers to create log messages. The alice_in_wonderland.txt file has been provided to you for use in testing.
The third argument should be the number of producers to create. Create and start the correct number of producers.
Use the stop button in IntelliJ or CTRL-C to end the program.
An example output file has been created for you in data/example_output.txt (note that some of the messages are blank lines).
An example run configuration has also been provided to you.
Have java in the most simplest form

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!