B4J Question How can i monitor on desktop a Non UI app

ocalle

Active Member
Licensed User
Longtime User
Hi, Im using JRC2, when i do release version cant see what happen on server as see in debug with logs.
Is there a way to show something on screen to see its running?
or a Iconize.
Well any suggest wellcomed.

Thanks
 

AHilton

Active Member
Licensed User
Longtime User
A few suggestions...

1) A basic one is to just direct all logging to a file with (do a forum search for more info on this) and just open the file when you want to see what's going on:

B4X:
    #If RELEASE
        ' Anything that would normally show in the console (log(), errors, etc.) will go to this file so that I can see what's going on later
        Utils.RedirectOutputToFile(File.DirApp & DirectorySeparator & "logs", "logs.txt")
    #End If

' Redirects Output to a file
' Usage: RedirectOutput(File.DirApp, "logs.txt")
Sub RedirectOutputToFile (Dir As String, FileName As String)
    #if RELEASE
        Dim out As OutputStream = File.OpenOutput(Dir, FileName, True) 'Set to True to append the logs
        Dim ps As JavaObject
        ps.InitializeNewInstance("java.io.PrintStream", Array(out, True, "utf8"))
        Dim jo As JavaObject
        jo.InitializeStatic("java.lang.System")
        jo.RunMethod("setOut", Array(ps))
        jo.RunMethod("setErr", Array(ps))
    #end if
End Sub
' Redirects Output back to the (standard) screen
Sub RedirectOutputToScreen (Dir As String, FileName As String)
    #if RELEASE
        Dim out As OutputStream = File.OpenOutput(Dir, FileName, False) 'Set to True to append the logs
        Dim ps As JavaObject
        ps.InitializeNewInstance("java.io.PrintStream", Array(out, True, "utf8"))
        Dim fd As JavaObject
        fd.InitializeStatic("java.io.FileDescriptor")
        Dim jout As JavaObject
        jout.InitializeNewInstance("java.io.FileOutputStream", Array(fd.GetField("out")))
        ps.InitializeNewInstance("java.io.PrintStream", Array(jout, True, "utf8"))

        Dim jo As JavaObject
        jo.InitializeStatic("java.lang.System")
        jo.RunMethod("setOut", Array(ps))
        jo.RunMethod("setErr", Array(ps))
    #end if
End Sub

2) Do #1 (above) but make it prettier, indexable, etc. by making a simple GUI B4J app that reads the file created. Or, alternatively, have your NON-GUI B4J app write to a database instead of log() that your GUI app then reads.

3) Make a GUI B4J app that connects to your NON-GUI B4J app (via Websockets, for example) that not only can read the log() output / database but can also interact with the NON-GUI B4J app itself to control / test / update / restart / whatever it.

I'm sure there are other options. Just do a search.
 
Upvote 0

roerGarcia

Active Member
Licensed User
Longtime User
I get it.

A line like this is needed
B4X:
   ExitApplication2(0) 'exit the application. Without this call the program will just hang.
 
Upvote 0
Top