Location of System.log?

I am looking for the location of System.Log when using it in a WebApp.
The app is running on Linux (Debian 12) through nginx, installed with Lifeboat.

I am using:

System.Log(system.LogLevelInformation, DateTime.Now.SQLDateTime + " " + "Some data")
1 Like

the online help wrote

On macOS and Linux, it writes to the System logger, which is typically at /var/log

https://documentation.xojo.com/api/os/system.html#system-log

1 Like

I also see this in the docs:

It’s mentioning MacOS but maybe it applies to Linux too?

Also, some “glorp” about logging from digital ocean (which I’m pretty sure is where you’re hosting?)

1 Like

So it seems that using System.Log writes out to

/var/log/user.log

Is there a command I can use to write to a specific file in /var/log, such as /var/log/my_app_name/info.log ?

Or do I need to use TextOutputStream.Append ?

journalctl -b -a -f -n 1000 | grep yourAppName

Of it’s a systemd process:
journalctl -b -a -f -n 1000 -u yourSystemdServiceName

-b means from the current boot
-a means all (including information, warning, error etc)
-f means follow
-n [num] of lines to load

This is for Debian that uses systemd where normally the journal is the logger system.

1 Like

/var/log/lifeboat/myappVVVppppp.log where

VVV is App.Version with periods removed, and ppppp is App.Port.

Private Function GetLogPath() As String
  Try
    // Construct the expected filename pattern
    Dim port As String = App.Port.ToString
    Dim version As String = App.Version.ReplaceAll(".", "").Left(3) // e.g., "402" from "4.0.2"
    Dim filename As String = <appname> + version + port + ".log"
    
    Return "/var/log/lifeboat/" + filename
    
  Catch e As RuntimeException
    Return ""
  End Try
End Function

The funny thing is I’m not sure where appname is coming from. In my case it’s not what’s in the IDE under Linux App Name, but it is the same as what I have in MacOS App Name. Maybe Lifeboat extracts it as LinuxAppName.NthField(" ",1), (true in my case), but in any case, you can find out by entering

ls -la /var/log/lifeboat/

in your server’s bash terminal - you’ll see the name+version+port in a number of filenames.

You could also use a shell and

echo "message" >> log.txt

Thanks Julia.

That is part of what I was looking for.

I won’t use System.Log method anymore as it doesn’t write to a specific file for the app but in

/var/log/user.log

I need a specific file for each app/instance.
I will probably use your code to create a specific path that I can analyse more rapidly.

I use System.DebugLog.

Make sure you allocate that stream when your app launches if you intend to use it for logging exceptions because your app could be in a state where it can’t allocate new objects.

3 Likes

Good point!

I am trying to pinpoint which URLConnection is making my app crash, so I will log each call to the URLConnection.Send method
And then log again on ContentReceived or Error

Analyzing the logs will be difficult as there are 100s of http requests per minute…

you could write it into sqlite table?
or log in memory and output at need in extra window with a search/listview.

app crash means there is no error handling or it just disappears?

If you include the first 8 characters of the session ID in your log messages, you should be able to sufficiently separate them when analyzing the logs.

Just FYI, I too have been having URLConnection issues lately where after running for a while, trying to initiate a new URLConnection from within the context of another’s ContentReceived event will hang the app. It’s hard to quantify which version of Xojo this started in because the whole reason I updated to a newer version was to replace Workers with preemptive threads, but something about URLConnection is definitely broken.

1 Like

That is something I do a lot in my app, I will try to refactor and add a delay before initiating a new URLConnection. Thank you for the heads up!