Sub Process_Globals
Private LogsOutput As OutputStream
End Sub
Sub AppStart (Args() As String)
HandleLogs
StartMessageLoop
End Sub
Sub HandleLogs
Dim CurrentDay As Long = 0
Do While True
Dim year As Int = DateTime.GetYear(DateTime.Now)
Dim month As Int = DateTime.GetMonth(DateTime.Now)
Dim day As Int = DateTime.GetDayOfMonth(DateTime.Now)
Dim d As Long = DateUtils.SetDate(year, month, day)
If d <> CurrentDay Then
CurrentDay = d
RedirectOutput(File.DirApp, $"Logs-$4{year}-$2{month}-$2{day}.txt"$)
End If
Sleep(60000)
Loop
End Sub
Sub RedirectOutput (Dir As String, FileName As String)
#if RELEASE
If LogsOutput.IsInitialized Then LogsOutput.Close
LogsOutput = File.OpenOutput(Dir, FileName, False) 'Set to True to append the logs
Log("Redirecting logs to: " & FileName)
Dim ps As JavaObject
ps.InitializeNewInstance("java.io.PrintStream", Array(LogsOutput, 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