Skip to content

Commit

Permalink
Reduce log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshayChaurasia98 authored and surinder-tsys committed Jul 13, 2023
1 parent 4f28185 commit 64f7805
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
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 @@ -26,8 +26,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 @@ -121,7 +121,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 @@ -231,7 +231,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 @@ -48,6 +48,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 @@ -135,7 +136,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 @@ -152,7 +153,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 @@ -737,7 +738,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 @@ -770,7 +771,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 @@ -941,13 +942,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 @@ -1066,7 +1067,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 @@ -1340,7 +1341,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 @@ -1363,7 +1364,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 @@ -1417,7 +1418,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan
String uri = mClient.getBaseUri() + "/index.php/core/preview.png?file="
+ URLEncoder.encode(file.getRemotePath())
+ "&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 @@ -1435,7 +1436,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

0 comments on commit 64f7805

Please sign in to comment.