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

Nmc/2089 Reduce log levels #122

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 42 additions & 0 deletions app/src/main/java/com/nmc/android/ui/utils/Log_NMC.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.nmc.android.ui.utils

import com.owncloud.android.BuildConfig
import com.owncloud.android.lib.common.utils.Log_OC

/**
* NMC log interpreter class
* this class will be used whenever we have to reduce the logs writing
* this will avoid printing logs in release builds
* todo: can be extended later for more functions
*/
object Log_NMC {
@JvmStatic
fun v(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.v(tag, msg)
}

@JvmStatic
fun d(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.d(tag, msg)
}

@JvmStatic
fun d(tag: String, msg: String, e: Exception) {
if (BuildConfig.DEBUG) Log_OC.d(tag, msg, e)
}

@JvmStatic
fun i(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.i(tag, msg)
}

@JvmStatic
fun e(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.e(tag, msg)
}

@JvmStatic
fun w(tag: String?, msg: String?) {
if (BuildConfig.DEBUG) Log_OC.w(tag, msg)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import android.net.Uri;
import android.provider.MediaStore;

import com.nmc.android.ui.utils.Log_NMC;
import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.PermissionUtil;
import com.owncloud.android.utils.theme.ViewThemeUtils;

Expand Down Expand Up @@ -107,7 +107,7 @@ public static List<MediaFolder> getImageFolders(ContentResolver contentResolver,
MediaStore.Images.Media.DATE_TAKEN,
ContentResolverHelper.SORT_DIRECTION_DESCENDING,
itemLimit);
Log_OC.d(TAG, "Reading images for " + mediaFolder.folderName);
Log_NMC.d(TAG, "Reading images for " + mediaFolder.folderName);

if (cursorImages != null) {
String filePath;
Expand Down Expand Up @@ -217,7 +217,7 @@ public static List<MediaFolder> getVideoFolders(ContentResolver contentResolver,
ContentResolverHelper.SORT_DIRECTION_DESCENDING,
itemLimit);

Log_OC.d(TAG, "Reading videos for " + mediaFolder.folderName);
Log_NMC.d(TAG, "Reading videos for " + mediaFolder.folderName);

if (cursorVideos != null) {
String filePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.nextcloud.client.account.User;
import com.nextcloud.client.network.ConnectivityService;
import com.nmc.android.ui.utils.Log_NMC;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.OwnCloudAccount;
Expand Down Expand Up @@ -123,7 +124,7 @@ protected Void doInBackground(File... params) {
}

String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER;
Log_OC.d(TAG, "thumbnail cache dir: " + cachePath);
Log_NMC.d(TAG, "thumbnail cache dir: " + cachePath);
File diskCacheDir = new File(cachePath);

// migrate from external cache to internal cache
Expand All @@ -140,7 +141,7 @@ protected Void doInBackground(File... params) {
mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat,
mCompressQuality);
} catch (Exception e) {
Log_OC.d(TAG, "Disk cache init failed", e);
Log_NMC.d(TAG, "Disk cache init failed", e);
mThumbnailCache = null;
}
}
Expand Down Expand Up @@ -723,7 +724,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {
file.getLocalId() + "&x=" + pxW + "&y=" + pxH;
}

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie",
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
Expand Down Expand Up @@ -756,7 +757,7 @@ private Bitmap doThumbnailFromOCFileInBackground() {

// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
Log_NMC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
}
Expand Down Expand Up @@ -926,13 +927,13 @@ private Bitmap doFileInBackground(File file, Type type) {
thumbnail = retriever.getFrameAtTime(-1);
} catch (Exception ex) {
// can't create a bitmap
Log_OC.w(TAG, "Failed to create bitmap from video " + file.getAbsolutePath());
Log_NMC.w(TAG, "Failed to create bitmap from video " + file.getAbsolutePath());
} finally {
try {
retriever.release();
} catch (RuntimeException | IOException ex) {
// Ignore failure at this point.
Log_OC.w(TAG, "Failed release MediaMetadataRetriever for " + file.getAbsolutePath());
Log_NMC.w(TAG, "Failed release MediaMetadataRetriever for " + file.getAbsolutePath());
}
}

Expand Down Expand Up @@ -1051,7 +1052,7 @@ Drawable doAvatarInBackground() {

int px = mResources.getInteger(R.integer.file_avatar_px);
String uri = mClient.getBaseUri() + "/index.php/avatar/" + Uri.encode(mUserId) + "/" + px;
Log_OC.d("Avatar", "URI: " + uri);
Log_NMC.d("Avatar", "URI: " + uri);
get = new GetMethod(uri);

// only use eTag if available and corresponding avatar is still there
Expand Down Expand Up @@ -1325,7 +1326,7 @@ public static void generateThumbnailFromOCFile(OCFile file, User user, Context c
String uri = client.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
pxW + "/" + pxH + Uri.encode(file.getRemotePath(), "/");

Log_OC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate thumbnail: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");

Expand All @@ -1348,7 +1349,7 @@ public static void generateThumbnailFromOCFile(OCFile file, User user, Context c
thumbnail = handlePNG(thumbnail, pxW, pxH);
}

Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
Log_NMC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
} catch (Exception e) {
Expand Down Expand Up @@ -1402,7 +1403,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan
String uri = mClient.getBaseUri() + "/index.php/core/preview?fileId="
+ file.getRemoteId()
+ "&x=" + (pxW / 2) + "&y=" + (pxH / 2) + "&a=1&mode=cover&forceIcon=0";
Log_OC.d(TAG, "generate resized image: " + file.getFileName() + " URI: " + uri);
Log_NMC.d(TAG, "generate resized image: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);

int status = mClient.executeMethod(getMethod);
Expand All @@ -1420,7 +1421,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan

// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add resized image to cache: " + file.getFileName());
Log_NMC.d(TAG, "add resized image to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}

Expand Down