Sub Process_Globals
...
Public Gen_jetty_log_filter As String
Public Gen_b4j_log_filter As Map
Public Gen_original_out As JavaObject
...
End Sub
Gen_jetty_log_filter = TRACE, DEBUG, INFO (default), WARN, ERROR or OFF
Gen_b4j_log_filter is a map with the keys being filters
'Set up log filters - just before Server.Initialize("", DonatorKey, "start")
Filter_logs
'************************************************************************************
'
'This procedure sets up log filters
'
'Input parameters are:
'
' None
'
'Returns:
'
' -
'
'Notes on this procedure:
'
' o Created with the assistance of Copilot
'
'************************************************************************************
Private Sub Filter_logs
'Set jetty server log level - TRACE, DEBUG, INFO (default), WARN, ERROR or OFF
SetSystemProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog")
SetSystemProperty("org.eclipse.jetty.LEVEL", Gen_jetty_log_filter)
Private wrk_system As JavaObject
wrk_system.InitializeStatic("java.lang.System")
'Capture original System.out before redirection
Gen_original_out = wrk_system.GetField("out")
'Explicitly create an instance of current module instead of using Me
Private moduleInstance As JavaObject
moduleInstance.InitializeNewInstance("com.ab.template.main", Null)
'Pass instance to Java PrintStreamWrapper
Private wrk_filteredstream As JavaObject
wrk_filteredstream.InitializeNewInstance("com.ab.template.main$PrintStreamWrapper", Array(Gen_original_out, moduleInstance))
'Redirect standard output
wrk_system.RunMethod("setOut", Array(wrk_filteredstream))
'Redirect error output
wrk_system.RunMethod("setErr", Array(wrk_filteredstream))
End Sub
'************************************************************************************
'
'This procedure is called by java PrintStreamWrapper when a log message is found
'
'Input parameters are:
'
' Mess_age = message
'
'Returns:
'
' -
'
'Notes on this procedure:
'
' o It has to be Public otherwise java PrintStreamWrapper can't see it
' o I don;t know why this procedure and ProcessLogMessageInternal have to be
' set up like this but it works
' o Created with the assistance of Copilot
'
'************************************************************************************
Public Sub ProcessLogMessage(Mess_age As String)
CallSubDelayed2(Me, "ProcessLogMessageInternal", Mess_age)
End Sub
'************************************************************************************
'
'This procedure is called by ProcessLogMessage when a log message is found
'
'Input parameters are:
'
' Mess_age = message
'
'Returns:
'
' -
'
'Notes on this procedure:
'
' o I don;t know why this procedure and ProcessLogMessage have to be
' set up like this but it works
' o Created with the assistance of Copilot
'
'************************************************************************************
Private Sub ProcessLogMessageInternal(Mess_age As String)
'For each filter...
For Each wrk_key As String In Gen_b4j_log_filter.Keys
'Quit if mesage contains filter
If Mess_age.Contains(wrk_key) Then Return
Next
'If got to here mesage passed filters so print it to original System.out
Gen_original_out.RunMethod("println", Array(Mess_age))
End Sub
#If Java
import java.io.PrintStream;
import java.lang.reflect.Method;
public static class PrintStreamWrapper extends PrintStream {
private Object b4jInstance;
public PrintStreamWrapper(PrintStream original, Object b4jInstance) {
super(original);
this.b4jInstance = b4jInstance;
}
public void println(String message) {
try {
//Use `_processlogmessage` instead of `ProcessLogMessage`
Method method = b4jInstance.getClass().getMethod("_processlogmessage", String.class);
method.invoke(b4jInstance, message);
} catch (Exception e) {
//System.out.println("Exception calling _processlogmessage: " + e.getMessage());
//e.printStackTrace();
}
}
}
#End If