Logging Facility

Hi there, does Xojo provide some sort of built in logging facility? Something akin to NSLog in Objective-C? Thanks

http://documentation.xojo.com/index.php/System.Log and also http://documentation.xojo.com/index.php/System.DebugLog

I have always found SYSTEM.LOG to be very very slow, and the time lag between when the event occurs and something shows in the log to be up to several seconds… So I abandoned that method years ago in favor of my own (presented here only as an alternative)

SUB mylog(msg as string)
  Dim f As FolderItem
  Dim t As TextOutputStream
  f=SpecialFolder.Desktop.child("myprogram.trace_log")
  t=TextOutputStream.Append(f)
  t.writewrite msg
  t.close
END SUB

It puts the log where I want it, when I want it, and can be read/edit/deleted by an text editor.
I use an extension of this to produce activity/progress logs for the user in apps where events need to be kept track of

The speed issue you are experiencing… Are you saying using System.Log slows down your application or just that there is a delay before you can see the information in the logs? One real benefit of System.Log is it uses the system logging facilities, thus you get log browsing and rotation for free. You could of course find the appropriate directory to log in and then configure some log rotators in Linux to rotate your own log, not sure about on OS X nor about logging in Windows though.

I am saying the results do no show up until some time AFTER they have happened…
If got very frustrating to have an app crash… and have to wait 20 or 30 seconds for my logging information to appear

The method I put above is near Real-Time,.

log rotation is not important consideration for the way I work.

[quote=17883:@Dave S]I am saying the results do no show up until some time AFTER they have happened…
If got very frustrating to have an app crash… and have to wait 20 or 30 seconds for my logging information to appear

The method I put above is near Real-Time,.

log rotation is not important consideration for the way I work.[/quote]

On which platform ?

[quote=17879:@Dave S]I have always found SYSTEM.LOG to be very very slow, and the time lag between when the event occurs and something shows in the log to be up to several seconds… So I abandoned that method years ago in favor of my own (presented here only as an alternative)

SUB mylog(msg as string)
  Dim f As FolderItem
  Dim t As TextOutputStream
  f=SpecialFolder.Desktop.child("myprogram.trace_log")
  t=TextOutputStream.Append(f)
  t.writewrite msg
  t.close
END SUB

It puts the log where I want it, when I want it, and can be read/edit/deleted by an text editor.
I use an extension of this to produce activity/progress logs for the user in apps where events need to be kept track of[/quote]

If you tail -f on the system log in question they’re there right away - the Console app may not refresh quickly

and if I open my logfile in UltraEdit… all I need to do it look at the screen… the messages are there as fast as I can write them

no need for terminal, unix commands etc…

Thanks… I’ll stay with my method…

Just saying that the messages not showing up is not Xojo’s issue but how console works
And there are other mechanisms like opening that file using BBEdit or just tailing it

I never blamed Xojo for the sloweness… I know how OSX logging queue works…

and (my opinion) UltraEdit blows BBEdit away :slight_smile:

Thanks for the replies!

New method?? :wink:

I’m happy with using System.Log, because later on I can retrieve not only my own logged messages, but other information which was generated automatically by the OS.

However, it seems that from a sandboxed app one cannot access the log using a shell command syslog, like this:

Dim s As New Shell Dim cmd As String = "syslog -k Sender '" + App.kAppName + "'" s.Execute(cmd)

Does anyone know an equivalent way to retrieve an app’s log data, which works from a sandboxed app?