Logger with Message Throttling
A logger that suppresses duplicate messages inside a rolling window — the design question behind every 'why is my log 40GB' incident.
Requirements
- A message may print again only
windowseconds after the last time it actually printed — suppressed attempts do not reset the clock. - Different messages throttle independently.
- Timestamps arrive in non-decreasing order (a real log stream).
API to implement
Implement the class Logger. The I/O driver is already written in the starter code — it parses the command script below and calls your methods. You only implement the class.
| Command | Returns | Behavior |
|---|---|---|
| should_log <timestamp> <message> | boolean | Return true if message may be printed at timestamp — i.e. it was never printed, or was last printed at time p with timestamp ≥ p + window. Only a printed (true) call updates the message's record. Timestamps are non-decreasing. |
Input format
The first line contains Q, the number of operations. The second line contains the constructor argument: window — the throttle window in seconds. Each of the next Q lines is one command as listed above. String arguments contain no spaces.
Output format
For each command with a non-void return, print its result on its own line, in order. The driver does this for you — your methods just return values.
This is a design problem: the hidden tests exercise edge cases and interaction sequences, not performance tricks. Model the state cleanly and the tests will pass.
Sample cases
7
10
should_log 1 foo
should_log 2 bar
should_log 3 foo
should_log 8 bar
should_log 10 foo
should_log 11 foo
should_log 12 bartrue
true
false
false
false
true
true5
5
should_log 0 x
should_log 4 x
should_log 5 x
should_log 9 x
should_log 10 xtrue
false
true
false
true