B4J Question rename the log file

JTmartins

Active Member
Licensed User
Longtime User
In B4J we get a logfile for the requests as :
B4X:
    srvr.Initialize("srvr")
    srvr.Port = 8090
    srvr.LogsFileFolder="Gagent.log"
    srvr.LogsRetainDays=1

However the log filename is always in the format b4j-date.request.log

Is there anyway to rename the log file ?

Thanks in advance.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code seems to work:
B4X:
    srvr.Start
   For Each h As JavaObject In GetHandlers
       If GetType(h) = "org.eclipse.jetty.server.handler.RequestLogHandler" Then
           Dim NCSARequestLog As JavaObject
           NCSARequestLog.InitializeNewInstance("org.eclipse.jetty.server.NCSARequestLog", Array(File.Combine(srvr.LogsFileFolder, _
               "my-format-must-include_yyyy_mm_dd.txt")))
           NCSARequestLog.RunMethod("setRetainDays", Array(srvr.LogsRetainDays))
           NCSARequestLog.RunMethod("setExtended", Array(True))
           NCSARequestLog.RunMethod("setAppend", Array(True))
           NCSARequestLog.RunMethod("start", Null)
           h.RunMethod("setRequestLog", Array(NCSARequestLog))
       End If
   Next
   StartMessageLoop
End Sub

Sub GetHandlers As Object()
   Dim josrvr As JavaObject = srvr
   josrvr = josrvr.GetField("server")
   Dim jo As JavaObject = josrvr
   Do While GetType(jo) <> "org.eclipse.jetty.server.handler.HandlerCollection"
       Log(jo)
       Log(jo.RunMethodJO("getHandler", Null))
       jo = jo.RunMethodJO("getHandler", Null)
   Loop
   Return jo.RunMethod("getHandlers", Null)
End Sub

I'm writing that it seems to work because I haven't tested that it actually works when the day changes (it will probably work).
 
Upvote 0
Top