Log Every Call

Easy ⏱ 8 min 77% acceptance ★★★★★ 4.7
Write the decorator logged(func) that appends the string func.__name__ to a module-level CALLS list every time the wrapped function runs, then returns the original result unchanged. Apply it with @logged and preserve the metadata with functools.wraps.

Examples

Example 1
Input
@logged applied to greet; greet(); CALLS
Output
['greet']
Explanation

The wrapper recorded the call and delegated.

Constraints

  • Use functools.wraps.
  • Support any args via *args/**kwargs.

Topics

Decoratorsbasic decorator

Companies

TCSInfosysAtlassian

Hints

Hint 1

The wrapper signature is (*args, **kwargs).

Hint 2

Return func(*args, **kwargs).

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