jServer has a great system to create a log per day. I was wondering if there is an easy way to do this for our own logs too. At this moment I'm using this snippet to redirect the output:
But it only creates a new file per jar startup: when the jar runs multiple days it keeps writing in the same file. If it could make a file per day, one could easily do some cleanup (e.g. after a week) of old logs.
How would the above redirect snippet have to look to archieve this?
B4X:
Sub RedirectOutput (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 jo As JavaObject
jo.InitializeStatic("java.lang.System")
jo.RunMethod("setOut", Array(ps))
jo.RunMethod("setErr", Array(ps))
#end if
End Sub
But it only creates a new file per jar startup: when the jar runs multiple days it keeps writing in the same file. If it could make a file per day, one could easily do some cleanup (e.g. after a week) of old logs.
How would the above redirect snippet have to look to archieve this?