B4J Code Snippet Set slf4j log level

A 3rd party library I am using was outputting INFO level messages frequently and ended up creating a 20gb log file. Ive asked the author to change the log level for the function to DEBUG but in the meantime I had to reduce the logging level of slf4j.

This can be done using the inline code below and calling it via a JavaObject

B4X:
' Possible log levels are  TRACE, DEBUG, INFO, WARN and ERROR
jo.RunMethod("setLevel", Array("WARN"))

Java:
#IF JAVA
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;

public static void setLevel(String LogLevel){
    Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    root.setLevel(Level.toLevel(LogLevel));
    }
#End If
 

FrancescoS

Member
Licensed User
Longtime User
Hi tchart, thanks, I have same problem.
I'm using B4J Region project attribute: #AdditionalJar: slf4j-api-1.7.30

and always I receive the following output:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

So I would like to disable these log messages.

my code doesn't work:

B4X:
#Region Project Attributes
    #CommandLineArgs:
    #MergeLibraries: false     
    #AdditionalJar: slf4j-api-1.7.30
    #AdditionalJar: sshj-0.31.0
    #AdditionalJar: eddsa-0.3.0
    #AdditionalJar: bcprov-jdk15on-168
#End Region

Sub Process_Globals
    Private jo As JavaObject
End Sub

Sub AppStart (Args() As String)
    jo.RunMethod("setLevel", Array("WARN"))
end sub

I get error: java.lang.ClassNotFoundException: java$lang$joclass.

May You help me to write the correct B4J code to disable these warnings ?
Do You have ad example ?
Thanks
 
Top