CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 6 of 6 · 2 min read

Exercises

Easy

Easy 1: Write the requirements (20 minutes)

Write seven numbered requirements for a logging library and three questions you would ask.

Done when: seven rules and three questions exist, and two features are marked out of scope.

Hint

Think of what the caller sees, and what the operator configures.

Easy 2: Run the hierarchy (20 minutes)

Type the code and reproduce the first four rows of the run table.

Done when: you print the full line, INFO:connected, the level change effect and the supplier count of 1.

Hint

The root logger needs a level, since the walk ends there.

Easy 3: Find the level (20 minutes)

Loggers: root (info), "a" (no level), "a.b" (warn), "a.b.c" (no level), "a.d" (no level). Give the effective level of each.

Done when: five answers (info, info, warn, warn, info) are written with the rule.

Hint

Walk up until a level is found.

Medium

Medium 1: Console and file appenders (45 minutes)

Write a ConsoleAppender and a FileAppender with a formatter. Send one record to both.

Done when: the same line appears on screen and in a file, and a failing file does not stop the console.

Hint

Wrap the file write in the same try and catch as other appenders.

Medium 2: JSON formatter (45 minutes)

Write a JsonFormatter that escapes quotes in the message and includes the error.

Done when: a message with quotes produces valid JSON, checked by a simple parser or by eye on three cases.

Hint

Escape backslash and quote at least.

Medium 3: Context fields (45 minutes)

Add a per-thread map of fields such as a request id that is copied into each record. Show two threads with different ids.

Done when: lines from two threads carry their own ids, and one thread's id never appears on the other's lines.

Hint

A ThreadLocal<Map<String,String>> holds the fields.

Hard

Hard 1: Smart dropping (90 minutes)

In the async appender, drop only debug and trace records when the queue is more than 80 per cent full, and block briefly for errors. Test both.

Done when: a flood of debug records never causes a lost error, and counts of dropped records per level are reported.

Hint

q.remainingCapacity() tells how full the queue is.

Hard 2: Rolling file (90 minutes)

Roll the file when it passes a size limit, keeping the last three files. Use an injected file-system interface for tests.

Done when: a test writes past the limit twice and finds three files with the right content.

Hint

Rename files from the oldest to the newest.

Hard 3: Throughput test (90 minutes)

Compare 8 threads logging 100,000 lines each through a synchronous file appender and through the async appender. Report time and drops.

Done when: a table shows both times and the drop count, and a sentence states the trade-off.

Hint

Use a start latch so the threads begin together.