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

JVM: Logging cannot be configured (PagingLogger spams output) #269

Open
biberesser opened this issue May 5, 2024 · 5 comments
Open

JVM: Logging cannot be configured (PagingLogger spams output) #269

biberesser opened this issue May 5, 2024 · 5 comments

Comments

@biberesser
Copy link

Great work guys with the library, but currently there is a small problem:

Paging version: 3.3.0-alpha02-0.5.1
Platform: JVM

The built-in logging cannot be configured.
This leads to thousands of lines of VERBOSE and DEBUG output.

Currently the JVM PagingLogger is hardwired for some reason: isLoggable() always returns true.

PagingLogger.jvm.kt:

package androidx.paging

import androidx.annotation.RestrictTo

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public actual object PagingLogger {

    public actual fun isLoggable(level: Int): Boolean {
        return true
    }

    // consider using java.util.logging APIs instead
    public actual fun log(level: Int, message: String, tr: Throwable?) {
        print("\n$message")
    }
}

example log spam when scrolling a paginated list:

Generated new PagingSource my.package.MyOffsetQueryMappedPagingSource@58e7f207
Sent PageEvent.LoadStateUpdate (
   sourceLoadStates: LoadStates(refresh=Loading(endOfPaginationReached=false), prepend=NotLoading(endOfPaginationReached=false), append=NotLoading(endOfPaginationReached=false))
)
Collected PageEvent.LoadStateUpdate (
   sourceLoadStates: LoadStates(refresh=Loading(endOfPaginationReached=false), prepend=NotLoading(endOfPaginationReached=false), append=NotLoading(endOfPaginationReached=false))
)
Start REFRESH with loadKey null my.package.MyOffsetQueryMappedPagingSource@58e7f207
End REFRESH with loadKey null. Returned LoadResult.Page(
   data size: 1500
   first Item: MyItem(...)
   last Item: MyItem(...)
   nextKey: 1500
   prevKey: null
   itemsBefore: 0
   itemsAfter: 2691
) 
Sent PageEvent.Insert for REFRESH, with 1500 items (
   first item: MyItem(...)
   last item: MyItem(...)
   placeholdersBefore: 0
   placeholdersAfter: 2691
   sourceLoadStates: LoadStates(refresh=NotLoading(endOfPaginationReached=false), prepend=NotLoading(endOfPaginationReached=true), append=NotLoading(endOfPaginationReached=false))
)
Collected PageEvent.Insert for REFRESH, with 1500 items (
   first item: MyItem(...)
   last item: MyItem(...)
   placeholdersBefore: 0
   placeholdersAfter: 2691
   sourceLoadStates: LoadStates(refresh=NotLoading(endOfPaginationReached=false), prepend=NotLoading(endOfPaginationReached=true), append=NotLoading(endOfPaginationReached=false))
)
Presenting data:
   first item: MyItem(...)
   last item: MyItem(...)
   placeholdersBefore: 0
   placeholdersAfter: 2691
   hintReceiver: androidx.paging.PageFetcher$PagerHintReceiver@36d82710
   sourceLoadStates: LoadStates(refresh=NotLoading(endOfPaginationReached=false), prepend=NotLoading(endOfPaginationReached=true), append=NotLoading(endOfPaginationReached=false))
)PAGING ITEMS: LoadStateNotLoading: NotLoading(endOfPaginationReached=false)
PAGING ITEMS: LoadStateNotLoading: NotLoading(endOfPaginationReached=false)
PAGING ITEMS: LoadStateNotLoading: NotLoading(endOfPaginationReached=false)

Accessing item index[0]
Accessing item index[1]
Accessing item index[2]
Accessing item index[3]
Accessing item index[4]
Accessing item index[5]
Accessing item index[6]
Accessing item index[7]
Accessing item index[8]
Accessing item index[9]
Accessing item index[10]
Accessing item index[11]
Accessing item index[12]
Accessing item index[13]
Accessing item index[14]
Accessing item index[15]
Accessing item index[16]
Accessing item index[17]
Accessing item index[18]
Accessing item index[19]
Accessing item index[20]
Accessing item index[21]
@biberesser biberesser changed the title Logging cannot be configured (PagingLogger spams output) JVM: Logging cannot be configured (PagingLogger spams output) May 5, 2024
@JakeWharton
Copy link
Collaborator

Should be easy to switch to Logger. Want to send a PR? No one is currently working on this repo, but I'd merge a fix if someone else wanted to contribute it.

@srideep-banerjee
Copy link

@JakeWharton Hello I ran into the same issue. can you please tell me how I can change the logger?

@JakeWharton
Copy link
Collaborator

Until you or somebody sends a PR to switch to Logger and there is a release you cannot change it.

@starxg
Copy link

starxg commented Aug 13, 2024

  1. pom.xml
<dependency>
    <groupId>androidx.paging</groupId>
    <artifactId>paging-common-jvm</artifactId>
    <version>1.14</version>
    <scope>3.3.0-alpha02</scope>
    <systemPath>your local path paging-common-jvm-3.3.0-alpha02.jar</systemPath>
</dependency>
  1. FixPagingLogger.java
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import java.nio.file.Files;
import java.nio.file.Paths;

public class FixPagingLogger {
    @Test
    public void test() throws Exception {
        final ClassPool pool = ClassPool.getDefault();
        final CtClass clazz = pool.get("androidx.paging.PagingLogger");
        final CtMethod method = clazz.getDeclaredMethod("isLoggable");
        method.setBody("return false;");
        IOUtils.write(clazz.toBytecode(), Files.newOutputStream(Paths.get("PagingLogger.class")));
        clazz.detach();
    }
}
  1. Open paging-common-jvm-3.3.0-alpha02.jar with 7-zip
  2. Replace the androidx.paging.PagingLogge file
  3. It works by modifying the Class bytecode so that the isLoggable method returns false.

build.gradle.kts(IMPORTANT!!!)

implementation("app.cash.paging:paging-compose-common:3.3.0-alpha02-0.5.1") {
    exclude(group = "androidx.paging", module = "paging-common-jvm")
}
// Here we introduce the modified paging-common-jvm-3.3.0-alpha02.jar file
implementation(fileTree("${projectDir}/libs"))

THIS IS MY MODIFIED JAR FILE (I SUGGEST YOU DON'T TRUST ANY UNOFFICIAL JAR FILE, YOU NEED TO GO THROUGH IT MANUALLY YOURSELF)

paging-common-jvm-3.3.0-alpha02-rm-log.jar.zip

@zt64
Copy link

zt64 commented Aug 30, 2024

@JakeWharton

I had reported to Google this issue and still nothing's been done. I'll make a PR, that should be okay until Google hopefully does something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants