How to write to a system log that I created?

Hello all.
Rather than have the log entries for my apps go to “/var/log/debug” I created one for my app “/var/log/axcys”. It is managed just like the debug or syslog but will only hold exceptions generated by my app - other than those the OS deems necessary to log elsewhere.

This is the code used to write to the var/log/debug file

Call System.Log(System.LogLevelDebug, msg )

My question is, how to tell Xojo to write to my specific log?
Thanks,
Tim

You make a folderitem with a name. Then you make a binarystream, create the folderitem and write the data to the folderitem. There is no difference to any other file.

Hi Beatrix.
I thought there would be some mechanism similar to the code I included.
Thanks for your response!
Tim

It does not appear to work. Trying to find out if it is a permissions issue or something else… Writing to a text file in one of my controlled folders works perfectly (and has been). But I really want the automation the OS provides for log rotation etc. control.
Tim

Beatrix,

Is it mandatory that a binary stream is used and not a textstream? This is the code I used to write to my own log files in a sub folder of the one holding the application.

  Dim fileStream As TextOutputStream = TextOutputStream.Append(f)
  fileStream.Write TextLine
  
  fileStream.Write TextLine
  fileStream.Close

Is there any difference?

For a log there is no difference. What goes wrong with the code that you posted?

Hi Beatrix.

No Error that I can find, but also not log entry. It creates an entry to my local *.log file but none for the other. One thing I was thinking is that I have no extension in the file name. I could not find one in an of the log files but at this point it could be many things including a lack of extension or possibly a permissions issue. I believe the /var/log/debug has no extension, and my log, /var/log/axcys_engine has no extension either.

Any ideas what I should look for?

Thank you again for your response and help!
Tim

Windows certainly doesn’t let you do that unless your app has elevated permissions.

On a Mac, this folder resolves to ‘inside the app bundle’, and that’s not allowed either.

“/var/log/axcys” in theory, is not a “sub folder of the one holding the application”.
On my Mac , VAR is a 'folder on the root of the drive holding the application"
Thats (probably volume(0) or volume(1) depending upon how things are set up on your machine)

If you want your logs to show up like the system logs, use the API calls.
If you just want to add text to a text file, create that log as specialfolder.applicationdata.child(“yourapp”).child(“axcys”)

Trimming the oldest rows off so that it doesn’t grow in size for ever would be down to you.

It appears you can have a log file located at an arbitrary location still be handled by the OS. Here’s a discussion about it on StackOverflow. Look for newsyslog.

This would allow a log file located as per Jeff’s advice to be handled automatically and correctly. You would need sudo privileges to write to newsyslog.d.

Hello all and thank you for your reply.

This only pertains to Linux - not windows.

My post may have been misleading or confusing. I have been writing to text files in a subfolder of my app, but they are not managed by the OS - so they are not rotated. I wanted the management/rotation of them which is one reason why I wanted to create one in a managed area. I used the webmin tools to add my log to the existing folder " /var/log/". The name of the file is ‘axcys’. Using the “edit system log” function of Webmin, I created that log file. Then, using Webmin “log file rotation” I added my file to the group that is rotated weekly and includes the ‘debug’ log. All of the files permissions are 644 in that folder ‘/var/log’, including the new one I added - I did not change it.

To be clear, what I had been writing before was:

  1. I can write to the files I created that are in my app’s folder or subfolder.
  2. I can write the the system debug file
  3. I cannot write to the new log file created.

I was trying not to have my logs in a location outside of the system folder, basically for grouping and ease of reviewing with Webmin. But for some reason, nothing is written to the file and no errors appear to be thrown. However, I can still write to my own text file logs without issue.

Finally, the reason to not use the debug file was that there are other log items entered there. I wanted only my apps logs.

I appreciate all of your responses, I will also have a look at the link you provided Tanner.

Thank you again
Tim