bumptech / glide

An image loading and caching library for Android focused on smooth scrolling
https://bumptech.github.io/glide/
Other
34.57k stars 6.12k forks source link

How to disable logs for pictures that cannot be loaded (due to Error 404)? #2412

Closed jahirfiquitiva closed 6 years ago

jahirfiquitiva commented 6 years ago

Glide Version: 4.1.1

Integration libraries: None

Device/Android Version: Genymotion Nexus 5X 7.1.1

Issue details / Repro steps / Use case background: I am getting a long log when trying to load a picture that does not exists. I know the easiest fix is to add an updated/working url, but sometimes I won't be able to do that really quick and I don't want the logs to show unnecessary stuff, so I want to disable them.

Stack trace / LogCat:

09-19 19:33:28.176 11070-11070/jahirfiquitiva.apps.frames.sample W/Glide: 
    Load failed for https://raw.githubusercontent.com/username/Repository/master/ice.png with size [524x628]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
        Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
          Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetch failed
            Cause (1 of 1): class com.bumptech.glide.load.HttpException: Not Found
09-19 19:33:28.176 11070-11070/jahirfiquitiva.apps.frames.sample I/Glide:
    Root cause (1 of 1)
        com.bumptech.glide.load.HttpException: Not Found
          at com.bumptech.glide.load.data.HttpUrlFetcher.loadDataWithRedirects(HttpUrlFetcher.java:119)
          at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:54)
          at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:96)
          at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:147)
          at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:141)
          at com.bumptech.glide.load.data.HttpUrlFetcher.loadData(HttpUrlFetcher.java:60)
          at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:96)
          at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:61)
          at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:286)
          at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:256)
          at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:226)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
          at java.lang.Thread.run(Thread.java:761)
          at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:347)
sjudd commented 6 years ago

See http://bumptech.github.io/glide/doc/configuration.html#application-options for how to setup Glide. During setup you can use setLogLevel to reduce the verbosity of logs in Glide.

jahirfiquitiva commented 6 years ago

@sjudd

I only see Log.VERBOSE, Log.DEBUG, Log.INFO,Log.WARN, or Log.ERROR. Isn't there something like Log.NONE or something that could disable them completely?

Muyangmin commented 6 years ago

@jahirfiquitiva Hello, I've reviewed some code in SingleRequest:

private void onLoadFailed(GlideException e, int maxLogLevel) {
    stateVerifier.throwIfRecycled();
    int logLevel = glideContext.getLogLevel();
    if (logLevel <= maxLogLevel) {
      Log.w(GLIDE_TAG, "Load failed for " + model + " with size [" + width + "x" + height + "]", e);
      if (logLevel <= Log.INFO) {
        e.logRootCauses(GLIDE_TAG);
      }
    }
   // other code omitted
}

In your case , if you only don't want to see those exceptions and causes, you can use setLevel() with Log.ERROR, just as @sjudd says.

However, if you are searching for more advanced needs(e.g only exclude 404, or HttpException), maybe currently no solution except fork repo and custom your own Request chain.

jahirfiquitiva commented 6 years ago

@Muyangmin Great. Thank you

parmarravi commented 4 years ago

Please add code to remove the logs

myroniak commented 4 years ago

Please add code to remove the logs

Insert YourAppGlideModule class into your app)

import android.content.Context;
import android.util.Log;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class YourAppGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setLogLevel(Log.ERROR);
    }
}
bkhong87 commented 3 years ago

Please add code to remove the logs

Insert YourAppGlideModule class into your app)

import android.content.Context;
import android.util.Log;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class YourAppGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setLogLevel(Log.ERROR);
    }
}

ensure depencies is added in project build.gradle file

build.gradle

dependencies {
    // Glide Component
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'com.github.bumptech.glide:annotations:4.11.0'
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
}

then remember to clean and rebuild your project to generate GlideApp class

iamradhakrishnab commented 3 years ago

V/ViewTarget: OnGlobalLayoutListener called attachStateListener=com.bumptech.glide.request.target.ViewTarget$SizeDeterminer$SizeDeterminerLayoutListener@a1f6740 V/ViewTarget: OnGlobalLayoutListener called attachStateListener=com.bumptech.glide.request.target.ViewTarget$SizeDeterminer$SizeDeterminerLayoutListener@ee8d88

I tried above mentioned points but still no no luck. Like above unnecessary Logs are printing..How to disable programatically?

shakir915 commented 2 years ago

use logcat filter Log Tag (regx) : ^(?!(Glide|EXCLUDE_TAG2)) package name : your app id

einschneidend commented 2 years ago

This worked for me

  1. create glide module `@GlideModule public class YourAppGlideModule extends AppGlideModule {

    @Override public void applyOptions(Context context, GlideBuilder builder) { builder.setLogLevel(Log.ERROR); } }`

  2. ensure depencies is added in project build.gradle file as @bkhong87 stated `// Glide Component implementation 'com.github.bumptech.glide:glide:4.13.0' implementation 'com.github.bumptech.glide:annotations:4.13.0'

    kapt 'com.github.bumptech.glide:compiler:4.13.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'`

  3. Add the proguard config -keep public class * extends com.bumptech.glide.module.AppGlideModule -keep class com.bumptech.glide.GeneratedAppGlideModuleImpl

  4. voila!

Note: mine wasn't working since I made a Kotlin class module, so preprocessor wasn't using it So you problably won't need both preprocessors Also, to use kapt you require the plugin id 'kotlin-android' id 'kotlin-kapt' Saludos!