B4J Question jserver can i disable logging ?

tchart

Well-Known Member
Licensed User
Longtime User
There is no out of the box way to disable logging.

In later versions of Jetty there is a setting for the logging called setIgnorePaths which presumably would allow us to ignore some or all handler paths - but this is not implemented in our version of Jetty.

I haven't extensively tested this but this works when I tested it.

You have to stop/start the server for it to pick up the change though - usually you would do this before the webserver.start but jServer only adds the handlers during the start method.

Also, as the request logger is using a OutputStream you need to set this to "NUL" on Windows and "/dev/null" on Linux.

B4X:
    webserver.Start

    Dim jo As JavaObject = webserver
    Dim HandlerCollection As JavaObject = jo.GetFieldJO("server").RunMethod("getHandler", Null)

    Dim Handlers() As Object = HandlerCollection.RunMethod("getHandlers", Null)

    For Each Handler As JavaObject In Handlers
        Dim class As String = Handler.RunMethod("getClass",Null)
        If class = "class org.eclipse.jetty.server.handler.RequestLogHandler" Then
            Dim RequestLog As JavaObject = Handler.RunMethodJO("getRequestLog",Null)
        
            If File.DirApp.StartsWith("/") Then
                RequestLog.RunMethod("setFilename",Array("/dev/null"))
            Else
                RequestLog.RunMethod("setFilename",Array("NUL"))
            End If       
        
            Handler.RunMethod("setRequestLog",Array(RequestLog))       
        End If
    Next

    jo.GetFieldJO("server").RunMethod("stop", Null)
    jo.GetFieldJO("server").RunMethod("start", Null)

    StartMessageLoop
 
Last edited:
Upvote 0
Top