B4J Question Setting the logging level with jServer 4

avalle

Active Member
Licensed User
Longtime User
Hi all, I'm converting a B4J project based on jServer 3 where I'm using the code provided by @rwblinn long time ago (see https://www.b4x.com/android/forum/threads/how-to-disable-jetty-debug-info-please.61448/post-387786):

Set Jetty Logging level:
'Set Jetty Logging Level
'Parameter: Level. Possible values: ALL|DEBUG|INFO|WARN|OFF
'See: https://www.eclipse.org/jetty/documentation/current/configuring-logging.html
'Note: Be aware that logging contains important info. Default is INFO
Public Sub SetLoggingLevel (level As String)
    Log("Set Logging Level to " & level.ToUpperCase)
    If level.Length = 0 Then Return
    Dim joJ As JavaObject        'Jetty Object
    Dim joP As JavaObject        'Properties Object
    joP.InitializeNewInstance("java.util.Properties", Null)
    joP.RunMethod("setProperty", Array("org.eclipse.jetty.LEVEL", level.ToUpperCase))
    joJ.InitializeNewInstance("org.eclipse.jetty.util.log.StdErrLog", Array("JettyLog", joP))
End Sub

With jServer 4 this code generates a ClassNotFoundException: org.eclipse.jetty$util$log$StdErrLog with the last line of code before EndSub:

B4X:
Waiting for debugger to connect...
Program started.
Set Logging Level to INFO
Error occurred on line: 430 (Util)
java.lang.ClassNotFoundException: org.eclipse.jetty$util$log$StdErrLog
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
    at b4j.server.util._setlogginglevel(util.java:58)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
    at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
    at b4j.server.main.main(main.java:29)

Does anyone have an idea on what should be changed to make it work with jServer 4?
Thanks!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

avalle

Active Member
Licensed User
Longtime User
Exactly, I want to control the logging level.
The default INFO level mostly works, but sometimes I need more verbose logging and so I change the level to DEBUG.
For now I've just bypassed the code above and so far everything else moving from jServer 3 to 4 works nicely without any code changes, but I'd like to keep this useful capability in my jServer projects.
It would be great if jServer offered a direct method to control the logging level without having to use Java Objects and direct Jetty API calls, but in the meantime it would be great if someone could help me patch the old code to work with the Jetty 11 logging functions.
 
Upvote 0

avalle

Active Member
Licensed User
Longtime User
Thanks Erel. You're right, but it doesn't seem to work as it did before with jServer 3.
Here's an example of my logs set to DEBUG level with jServer 3:

B4X:
2022-07-07 15:48:26.027:INFO::main: Logging initialized @1003ms to org.eclipse.jetty.util.log.StdErrLog
2022-07-07 15:48:26.042:DBUG:oejuc.ContainerLifeCycle:main: org.eclipse.jetty.server.Server@4bb4de6a[9.4.z-SNAPSHOT] added {QueuedThreadPool[qtp1561408618]@5d11346a{STOPPED,8<=0<=200,i=0,q=0}[org.eclipse.jetty.util.thread.TryExecutor$$Lambda$40/0x00000001000ef040@2bbaf4f0],AUTO}
2022-07-07 15:48:26.081:DBUG:oeju.DecoratedObjectFactory:main: Adding Decorator: org.eclipse.jetty.util.DeprecationWarning@7bc1a03d
2022-07-07 15:48:26.092:DBUG:oejuc.ContainerLifeCycle:main: o.e.j.s.ServletContextHandler@429bd883{/,null,UNAVAILABLE} added {org.eclipse.jetty.servlet.ServletHandler@4d49af10,MANAGED}
2022-07-07 15:48:26.138:DBUG:oejh.PreEncodedHttpField:main: HttpField encoders loaded: [org.eclipse.jetty.http.Http1FieldPreEncoder@c33b74f, org.eclipse.jetty.http2.hpack.HpackFieldPreEncoder@130161f7]

I have dozen of these DEBUG events just when the serverboots up, while there are no DEBUG events with jServer 4 using your code above.
 
Last edited:
Upvote 0
Top