JakeWharton / JakeWharton/timber

Optional call stack depth parameter

Open
#180 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
10.9k
Forks
994
Avg merge
17h 16m
Merged PRs (30d)
17

Description

The logging interface looks like following:

```
log(int priority, String tag, String message, Throwable t)
```

Why not add an additional call stack adjustment value?

**Use cases**

Maybe someone wants to write reuseable logging functions, that should log their calling functions parameters. Seems like a common use case for me.

**Example - simple transformer for logging observables execution time**

```
public static Observable.Transformer applyMeasurement(Class clazz, String tag, boolean enabled)
{
return observable -> measure(observable, clazz, tag, enabled);
}

private static Observable measure(Observable observable, Class clazz, String tag, boolean enabled)
{
if (!mEnabled || !enabled)
return observable;

LongHolder start = new LongHolder(0);
return observable
.doOnSubscribe(() -> start.set(System.currentTimeMillis()))
.doOnTerminate(() -> Timber.d("[%s | %s] Duration: %dms", clazz, tag, System.currentTimeMillis() - start.get()));
}
```

Here the log would print the line and class of my logger utility class, which is not perfect...

Wouldn't it make sense to extend the log interface for such use cases?

Contributor guide

No contributing guide indexed for this repository

Research direction

No file or test is named. Start by locating the logging interface and its delegation to Android's Log, then review the existing discussion before proposing the API shape. Done would require an agreed call-stack adjustment design and corresponding behavior coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
developer-experience, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.