Log Search Facade

Report a typo

The search method of LogSearchFacade is intended to:

  • collect logs from the standard input;
  • filter the collected logs based on a passed expression that they should contain;
  • format the filtered logs.

You have 3 classes that help to achieve the goal: LogCollector, LogFilter and LogFormatter. Use them to complete the search method.

Sample Input 1:

6
INFO: Entity [id = 3] is created
ERROR: Failed to update [id = 3], no permissions
INFO: Security configuration is updated
INFO: Entity [id = 3] is updated
INFO: Entity [id = 3] is removed
ERROR: Entity [id = 3] doesn't exist

Sample Output 1:

Failed to update [id = 3], no permissions
Entity [id = 3] doesn't exist
Write a program in Java 17
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// Do not change the method
class FacadeMain {
public static void main(String[] args) {
LogSearchFacade logSearcher = new LogSearchFacade(
new LogCollector(), new LogFilter(), new LogFormatter());
List<String> foundLogs = logSearcher.search("ERROR");

for (String log : foundLogs) {
System.out.println(log);
}
}
}

class LogSearchFacade {
private final LogCollector collector;
private final LogFilter filter;
private final LogFormatter formatter;

public LogSearchFacade(LogCollector collector, LogFilter filter, LogFormatter formatter) {
this.collector = collector;
this.filter = filter;
this.formatter = formatter;
}

public List<String> search(String expr) {
// construct the code of the facade method
}
}

// Do not change code below
class LogCollector {
/**
___

Create a free account to access the full topic