Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Timber for logging #471

Merged
merged 2 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ dependencies {
implementation("ch.acra:acra-dialog:$acraVersion")
implementation("ch.acra:acra-limiter:$acraVersion")

// Logging
implementation("com.jakewharton.timber:timber:4.7.1")

// Testing
testImplementation("junit:junit:4.12")
testImplementation("org.mockito:mockito-core:3.2.4")
Expand Down
35 changes: 13 additions & 22 deletions app/src/main/java/org/jellyfin/androidtv/TvApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@
import org.jellyfin.apiclient.model.dto.BaseItemType;
import org.jellyfin.apiclient.model.dto.UserDto;
import org.jellyfin.apiclient.model.entities.DisplayPreferences;
import org.jellyfin.apiclient.model.logging.ILogger;

import java.util.Calendar;
import java.util.HashMap;

import timber.log.Timber;

@AcraCore(buildConfigClass = BuildConfig.class)
@AcraHttpSender(
uri = "https://collector.tracepot.com/a2eda9d9",
Expand All @@ -74,9 +75,6 @@ public class TvApp extends Application {
public static final int LIVE_TV_SCHEDULE_OPTION_ID = 4000;
public static final int LIVE_TV_SERIES_OPTION_ID = 5000;

private static final String TAG = "Jellyfin-AndroidTV";

private ILogger logger;
private PlaybackManager playbackManager;
private static TvApp app;
private UserDto currentUser;
Expand Down Expand Up @@ -126,7 +124,6 @@ protected void attachBaseContext(Context base) {
@Override
public void onCreate() {
super.onCreate();
logger = new AndroidLogger(TAG);
app = (TvApp) getApplicationContext();
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
playbackManager = new PlaybackManager(new AndroidDevice(this), new AndroidLogger("PlaybackManager"));
Expand All @@ -135,25 +132,19 @@ public void onCreate() {
registerActivityLifecycleCallbacks(new AuthenticatedUserCallbacks());
registerActivityLifecycleCallbacks(new AppThemeCallbacks());

logger.Info("Application object created");
// Initialize the logging library
Timber.plant(new Timber.DebugTree());
Timber.i("Application object created");
}

public static TvApp getApplication() {
return app;
}

public ILogger getLogger() {
return logger;
}

public void setLogger(ILogger value) {
logger = value;
}

public UserDto getCurrentUser() {
if (currentUser == null)
logger.Error("Called getCurrentUser() but value was null.");

if (currentUser == null) {
Timber.e("Called getCurrentUser() but value was null.");
}
return currentUser;
}

Expand Down Expand Up @@ -397,7 +388,7 @@ public void updateDisplayPrefs(DisplayPreferences preferences) {
public void updateDisplayPrefs(String app, DisplayPreferences preferences) {
displayPrefsCache.put(preferences.getId(), preferences);
getApiClient().UpdateDisplayPreferencesAsync(preferences, getCurrentUser().getId(), app, new EmptyResponse());
logger.Debug("Display prefs updated for %s isFavorite: %s", preferences.getId(), preferences.getCustomPrefs().get("FavoriteOnly"));
Timber.d("Display prefs updated for %s isFavorite: %s", preferences.getId(), preferences.getCustomPrefs().get("FavoriteOnly"));
}

public void getDisplayPrefsAsync(String key, Response<DisplayPreferences> response) {
Expand All @@ -406,7 +397,7 @@ public void getDisplayPrefsAsync(String key, Response<DisplayPreferences> respon

public void getDisplayPrefsAsync(final String key, String app, final Response<DisplayPreferences> outerResponse) {
if (displayPrefsCache.containsKey(key)) {
logger.Debug("Display prefs loaded from cache %s", key);
Timber.d("Display prefs loaded from cache %s", key);
outerResponse.onResponse(displayPrefsCache.get(key));
} else {
getApiClient().GetDisplayPreferencesAsync(key, getCurrentUser().getId(), app, new Response<DisplayPreferences>(){
Expand All @@ -415,14 +406,14 @@ public void onResponse(DisplayPreferences response) {
if (response.getSortBy() == null) response.setSortBy("SortName");
if (response.getCustomPrefs() == null) response.setCustomPrefs(new HashMap<String, String>());
displayPrefsCache.put(key, response);
logger.Debug("Display prefs loaded and saved in cache %s", key);
Timber.d("Display prefs loaded and saved in cache %s", key);
outerResponse.onResponse(response);
}

@Override
public void onError(Exception exception) {
//Continue with defaults
logger.ErrorException("Unable to load display prefs ", exception);
Timber.e(exception, "Unable to load display prefs ");
DisplayPreferences prefs = new DisplayPreferences();
prefs.setId(key);
prefs.setSortBy("SortName");
Expand All @@ -444,7 +435,7 @@ public void determineAutoBitrate() {
@Override
public void onResponse(Long response) {
autoBitrate = response.intValue();
logger.Info("Auto bitrate set to: %d", autoBitrate);
Timber.i("Auto bitrate set to: %d", autoBitrate);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.jellyfin.apiclient.model.querying.ItemFields;
import org.jellyfin.apiclient.model.results.TimerInfoDtoResult;

import timber.log.Timber;

public class BrowseRecordingsFragment extends EnhancedBrowseFragment {
@Override
public void onResume() {
Expand Down Expand Up @@ -133,7 +135,7 @@ public void onResponse(TimerInfoDtoResult response) {
programInfo.setId(timer.getId());
programInfo.setChannelName(timer.getChannelName());
programInfo.setName(Utils.getSafeValue(timer.getName(), "Unknown"));
TvApp.getApplication().getLogger().Warn("No program info for timer %s. Creating one...", programInfo.getName());
Timber.w("No program info for timer %s. Creating one...", programInfo.getName());
programInfo.setBaseItemType(BaseItemType.Program);
programInfo.setTimerId(timer.getId());
programInfo.setSeriesTimerId(timer.getSeriesTimerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import androidx.leanback.widget.HeaderItem;
import androidx.leanback.widget.ListRow;

import timber.log.Timber;

public class BrowseViewFragment extends EnhancedBrowseFragment {
private boolean isLiveTvLibrary;

Expand Down Expand Up @@ -299,7 +301,7 @@ public void onResponse(TimerInfoDtoResult response) {
programInfo.setId(timer.getId());
programInfo.setChannelName(timer.getChannelName());
programInfo.setName(Utils.getSafeValue(timer.getName(), "Unknown"));
TvApp.getApplication().getLogger().Warn("No program info for timer %s. Creating one...", programInfo.getName());
Timber.w("No program info for timer %s. Creating one...", programInfo.getName());
programInfo.setBaseItemType(BaseItemType.Program);
programInfo.setTimerId(timer.getId());
programInfo.setSeriesTimerId(timer.getSeriesTimerId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import android.os.Bundle;

import org.jellyfin.androidtv.TvApp;
import org.jellyfin.androidtv.constants.Extras;

import timber.log.Timber;

public class CustomViewFragment extends BrowseFolderFragment {
protected String includeType;

@Override
public void onActivityCreated(Bundle savedInstanceState) {
includeType = getActivity().getIntent().getStringExtra(Extras.IncludeType);
TvApp.getApplication().getLogger().Debug("Item type: %s", includeType);
Timber.d("Item type: %s", includeType);
showViews = false;

super.onActivityCreated(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import androidx.leanback.widget.Row;
import androidx.leanback.widget.RowPresenter;

import timber.log.Timber;

public class StdBrowseFragment extends BrowseSupportFragment implements IRowLoader {
private static final int BACKGROUND_UPDATE_DELAY = 100;

Expand Down Expand Up @@ -322,7 +324,7 @@ public void onMessageReceived(CustomMessage message) {

private void refreshCurrentItem() {
if (mCurrentItem != null && mCurrentItem.getBaseItemType() != BaseItemType.UserView && mCurrentItem.getBaseItemType() != BaseItemType.CollectionFolder) {
TvApp.getApplication().getLogger().Debug("Refresh item \"%s\"", mCurrentItem.getFullName());
Timber.d("Refresh item \"%s\"", mCurrentItem.getFullName());
mCurrentItem.refresh(new EmptyResponse() {
@Override
public void onResponse() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import androidx.leanback.widget.Row;
import androidx.leanback.widget.RowPresenter;

import timber.log.Timber;

public class StdGridFragment extends HorizontalGridFragment implements IGridLoader {
private static final String TAG = "StdGridFragment";

Expand Down Expand Up @@ -267,7 +269,7 @@ public void onResponse(Integer response) {
mCardHeight = autoHeight;
setNumberOfRows();
createGrid();
TvApp.getApplication().getLogger().Debug("Auto card height is %d", mCardHeight);
Timber.d("Auto card height is %d", mCardHeight);
buildAdapter(rowDef);
}
mGridAdapter.setSortBy(getSortOption(mDisplayPrefs.getSortBy()));
Expand Down Expand Up @@ -296,7 +298,7 @@ protected int getCardHeight(String heightSetting) {
}

protected int getAutoCardHeight(Integer size) {
TvApp.getApplication().getLogger().Debug("Result size for auto card height is %d", size);
Timber.d("Result size for auto card height is %d", size);
if (size > 35)
return getCardHeight(PosterSize.SMALL);
else if (size > 10)
Expand Down Expand Up @@ -594,7 +596,7 @@ private void refreshCurrentItem() {
}
if (mCurrentItem != null && mCurrentItem.getBaseItemType() != BaseItemType.Photo && mCurrentItem.getBaseItemType() != BaseItemType.PhotoAlbum
&& mCurrentItem.getBaseItemType() != BaseItemType.MusicArtist && mCurrentItem.getBaseItemType() != BaseItemType.MusicAlbum) {
TvApp.getApplication().getLogger().Debug("Refresh item \"%s\"", mCurrentItem.getFullName());
Timber.d("Refresh item \"%s\"", mCurrentItem.getFullName());
mCurrentItem.refresh(new EmptyResponse() {
@Override
public void onResponse() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.jellyfin.androidtv.details;

import org.jellyfin.androidtv.TvApp;

import org.jellyfin.apiclient.interaction.Response;
import org.jellyfin.apiclient.model.dto.BaseItemDto;

/**
* Created by Eric on 3/23/2015.
*/
import timber.log.Timber;

public class DetailItemLoadResponse extends Response<BaseItemDto> {
private FullDetailsActivity activity;

Expand All @@ -22,6 +19,6 @@ public void onResponse(BaseItemDto response) {

@Override
public void onError(Exception exception) {
TvApp.getApplication().getLogger().ErrorException("Error retrieving full object", exception);
Timber.e(exception, "Error retrieving full object");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
import java.util.Date;
import java.util.List;

import timber.log.Timber;

public class FullDetailsActivity extends BaseActivity implements IRecordingIndicatorView {

private int BUTTON_SIZE;
Expand Down Expand Up @@ -214,11 +216,11 @@ protected void onResume() {
@Override
public void run() {
if (mBaseItem.getBaseItemType() == BaseItemType.Episode && mApplication.getLastPlayback().after(mLastUpdated) && mApplication.getLastPlayedItem() != null && !mBaseItem.getId().equals(mApplication.getLastPlayedItem().getId()) && mApplication.getLastPlayedItem().getBaseItemType() == BaseItemType.Episode) {
mApplication.getLogger().Info("Re-loading after new episode playback");
Timber.i("Re-loading after new episode playback");
loadItem(mApplication.getLastPlayedItem().getId());
mApplication.setLastPlayedItem(null); //blank this out so a detail screen we back up to doesn't also do this
} else {
mApplication.getLogger().Debug("Updating info after playback");
Timber.d("Updating info after playback");
mApplication.getApiClient().GetItemAsync(mBaseItem.getId(), mApplication.getCurrentUser().getId(), new Response<BaseItemDto>() {
@Override
public void onResponse(BaseItemDto response) {
Expand Down Expand Up @@ -461,10 +463,8 @@ protected MyDetailsOverviewRow doInBackground(BaseItemDto... params) {

}
}

} catch (IOException e) {
TvApp.getApplication().getLogger().ErrorException("Error loading image", e);

Timber.e(e, "Error loading image");
}

return mDetailsOverviewRow;
Expand Down Expand Up @@ -512,7 +512,7 @@ protected void addItemRow(ArrayObjectAdapter parent, ItemRowAdapter row, int ind
}

protected void addAdditionalRows(ArrayObjectAdapter adapter) {
TvApp.getApplication().getLogger().Debug("Item type: %s", mBaseItem.getBaseItemType().toString());
Timber.d("Item type: %s", mBaseItem.getBaseItemType().toString());
switch (mBaseItem.getBaseItemType()) {
case Movie:

Expand Down Expand Up @@ -875,7 +875,7 @@ public void onResponse(ItemsResult response) {

@Override
public void onError(Exception exception) {
TvApp.getApplication().getLogger().ErrorException("Error playing next up episode", exception);
Timber.e(exception, "Error playing next up episode");
Utils.showToast(TvApp.getApplication(), getString(R.string.msg_video_playback_error));
}
});
Expand Down Expand Up @@ -951,7 +951,7 @@ public void onResponse(BaseItemDto[] response) {

@Override
public void onError(Exception exception) {
TvApp.getApplication().getLogger().ErrorException("Error retrieving trailers for playback", exception);
Timber.e(exception, "Error retrieving trailers for playback");
Utils.showToast(mActivity, R.string.msg_video_playback_error);
}
});
Expand Down Expand Up @@ -991,15 +991,15 @@ public void onResponse(BaseItemDto response) {

@Override
public void onError(Exception ex) {
mApplication.getLogger().ErrorException("Error creating recording", ex);
Timber.e(ex, "Error creating recording");
thornbill marked this conversation as resolved.
Show resolved Hide resolved
Utils.showToast(mActivity, R.string.msg_unable_to_create_recording);
}
});
}

@Override
public void onError(Exception exception) {
mApplication.getLogger().ErrorException("Error creating recording", exception);
Timber.e(exception, "Error creating recording");
Utils.showToast(mActivity, R.string.msg_unable_to_create_recording);
}
});
Expand Down Expand Up @@ -1051,15 +1051,15 @@ public void onResponse(BaseItemDto response) {

@Override
public void onError(Exception ex) {
mApplication.getLogger().ErrorException("Error creating recording", ex);
Timber.e(ex, "Error creating recording");
Utils.showToast(mActivity, R.string.msg_unable_to_create_recording);
}
});
}

@Override
public void onError(Exception exception) {
mApplication.getLogger().ErrorException("Error creating recording", exception);
Timber.e(exception, "Error creating recording");
Utils.showToast(mActivity, R.string.msg_unable_to_create_recording);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@

import androidx.leanback.app.BackgroundManager;

import timber.log.Timber;

public class ItemListActivity extends BaseActivity {

private int BUTTON_SIZE;
Expand Down Expand Up @@ -254,7 +256,7 @@ protected void onStop() {
private AudioEventListener mAudioEventListener = new AudioEventListener() {
@Override
public void onPlaybackStateChange(PlaybackController.PlaybackState newState, BaseItemDto currentItem) {
TvApp.getApplication().getLogger().Info("Got playback state change event %s for item %s", newState.toString(), currentItem != null ? currentItem.getName() : "<unknown>");
Timber.i("Got playback state change event %s for item %s", newState.toString(), currentItem != null ? currentItem.getName() : "<unknown>");

if (newState != PlaybackController.PlaybackState.PLAYING || currentItem == null) {
if (mCurrentlyPlayingRow != null) mCurrentlyPlayingRow.updateCurrentTime(-1);
Expand Down Expand Up @@ -482,7 +484,7 @@ public void onResponse(ItemsResult response) {

@Override
public void onError(Exception exception) {
mApplication.getLogger().ErrorException("Error loading", exception);
Timber.e(exception, "Error loading");
Utils.showToast(mActivity, exception.getLocalizedMessage());
}
};
Expand Down
Loading