Override AND Reuse the Parent Logic

Medium ⏱ 12 min 55% acceptance ★★★★☆ 4.4
Logger.log(msg) returns f'[LOG] {msg}'. Subclass TimestampLogger overrides log to return the parent's output prefixed with a supplied ts string: f'{ts} ' + super-result. The pattern to practice: overriding a method while still calling the original through super().

Examples

Example 1
Input
TimestampLogger().log('boot', '2026-07-28')
Output
'2026-07-28 [LOG] boot'
Explanation

The child wraps rather than replaces the parent behavior.

Constraints

  • Must call super().log(msg).
  • Signature: log(self, msg, ts).

Topics

OOPoverride + super

Companies

AdobeSalesforceSAP

Hints

Hint 1

Call the parent first, then prepend.

Hint 2

No duplication of the [LOG] formatting.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.