A log router sends each message through a chain of loggers. Every logger decides whether the message is at or above its own level, records a line when it is, and passes the message along either way.
The provided LogRouter exposes this API:
LogRouter() creates a router with an empty chain.boolean addLogger(String kind) appends "debug", "info", "warn" or "error" to the end of the chain and returns true. An unrecognised name changes nothing and returns false, and so does an attempt to add a seventh logger.String chainOrder() returns the labels from head to tail joined by " -> ", for example "ERROR -> WARN -> INFO -> DEBUG", or "EMPTY" when no logger has been added.String[] log(int level, String message) sends the message from the head of the chain and returns one line for every logger that recorded it, in the order the lines were recorded. A level outside 1 to 4 reaches no logger and returns an empty array.int loggerCount() returns how many loggers are in the chain.int handledCount() returns how many lines have been recorded across all log calls.The four levels are DEBUG at 1, INFO at 2, WARN at 3 and ERROR at 4. A logger records "[LABEL] message" using its own label whenever the level is at or above its own, and passes the message to the next logger whether or not it recorded anything. Several loggers can record the same message.
The same kind may be added more than once, and the chain runs in the order the loggers were added rather than by level.
Complete only the six Chain of Responsibility types left in the starter code:
Logger defines label, setNext, getNext and log.BaseLogger stores the next logger and provides the shared forwarding operation.DebugLogger, InfoLogger, WarnLogger and ErrorLogger supply their labels and thresholds, record matching lines, and always forward the request.The supplied router creates and appends loggers, validates levels and capacity, traverses the chain for reporting, and counts recorded lines. LogRouter is the only type the tests call; do not change it.
Input:
Output:
Explanation: The message sits at level 2. The error and warn loggers do not record it but still pass it on, the info and debug loggers do record it, and the handled count moves to 2.
Input:
Output:
Explanation: A level 4 message clears every threshold, so all four loggers record it in chain order. The level 1 message that follows reaches the debug logger only, which brings the running total to 5.
0 <= level <= 51 <= message.length <= 606 loggers are added to one chain.100 calls in total are made across all methods.Full marks when each logger is its own class behind one contract, holding only its own threshold and its link to the next logger, and the router sends the message to the head without comparing levels. Lose points heavily when `log` walks a list and does the level comparison itself, or when the router names a logger class anywhere other than where it builds one.
Full marks when every logger hands the message to the next one whether or not it recorded a line, so a single message can produce several lines and a logger that skips does not end the run. Lose points when a logger returns after recording, or when it stops on a message it did not record.
Full marks when the transcript follows the order the loggers were added rather than their levels, repeated kinds are allowed, a level outside `1` to `4` returns an empty array and counts nothing, and an empty chain reports `EMPTY`. Lose points for printing to stdout.
Passing every test is not enough on its own. A submission is accepted only when the design also clears the bar.
| Call | Returns |
|---|---|
| new LogRouter() | null |
| addLogger("error") | true |
| addLogger("warn") | true |
| addLogger("info") | true |
| addLogger("debug") | true |
| chainOrder() | "ERROR -> WARN -> INFO -> DEBUG" |
| log(2, "User logged in") | ["[INFO] User logged in","[DEBUG] User logged in"] |
| handledCount() | 2 |
The message sits at level 2. The error and warn loggers do not record it but still pass it on, the info and debug loggers do record it, and the handled count moves to 2.
Run checks these cases. Submit also runs a larger hidden set.

