The application should parse the content of this log file and filter it based on timestamp. The log file should meet standard definition and format of the log message according to IETF-syslog format (RFC 5424).
For practical implementation was used Apache Flume SyslogParser
public Event parseMessage(String msg, Charset charset, Set<String> keepFields)
Parses a Flume Event out of a syslog message string.
Parameters:
msg - Syslog message, not including the newline character
Returns:
Parsed Flume Event
Throws:
IllegalArgumentException - if unable to successfully parse messageFor the .log file reading was created class ParserFileReader.
public static List<String> parserFileReaderMethod (String filepath, List<String> messages) throws Exception{
File file = new File(filepath);
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
messages.add(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return messages;
}For saving sorted messages to the .html file, was created method write2HTML in class HTMLfileCreator.
For sorting messages is used method sortParsedRfc5424Messages.
Local path for the .log file is src/main/resources/syslog_example.log.
Path for the html file is src/main/resources/syslog_example_parsed.html.
For the initial compiling via Maven, was used next command :
$ mvn clean compile assembly:singleTo run created Jar is used command:
$ java -jar target/TestTask1-1.0-jar-with-dependencies.jarAfter the running of the program is opened default web browser with the created html page, with sorted messages.
Created tests are using Junit ver. 5.4, and created for testing methods of SyslogParser.