Unified Logging System in Go

Hi,

I'm developing a multi-platform project in Windows, Mac and Linux. I am trying to create a wrapper class in Go that will query system information and history.

I see that the Unified Logging System is a sophisticated way to get all sorts of kernel information (and even a long history including rotated logs). However, I am struggling to see how I can use the APIs in other languages aside from Swift itself (or C). I do not want to use the log or last commands to query information in separate child processes in my project. I would like to simply query the database itself, similar to using OSLog in Swift.

If this is something that is entirely proprietary or not possible, let me know :)

Answered by DTS Engineer in 823042022

There are two parts to this:

  • Adding log points to your code, which log to the system log

  • Getting information back from the system log

The first is tricky. Good integration with the system log requires compiler support. If you were up for modifying the Go compiler, I could help you with the Apple side of that (DTS tends to go the extra mile for folks building developers tools). However, it is by no means an easy task.

Fortunately it sounds like you’re primarily interested in the second part. That’s relatively straightforward. The OSLog framework is a relatively straightforward Objective-C API. You can call it like you would any other Objective-C API.

I don’t maintain expertise in third-party tools, so I can’t offer advice on how to do that. I recommend that you escalate this via your tool’s support channel.

If there’s no direct support for calling Objective-C APIs in your tools, you could create a bridge from a language that does have such support, including C (Objective-C), C++ (Objective-C++), Swift, and numerous others.

Finally, Your Friend the System Log has lots of hints and tips about the system log.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

There are two parts to this:

  • Adding log points to your code, which log to the system log

  • Getting information back from the system log

The first is tricky. Good integration with the system log requires compiler support. If you were up for modifying the Go compiler, I could help you with the Apple side of that (DTS tends to go the extra mile for folks building developers tools). However, it is by no means an easy task.

Fortunately it sounds like you’re primarily interested in the second part. That’s relatively straightforward. The OSLog framework is a relatively straightforward Objective-C API. You can call it like you would any other Objective-C API.

I don’t maintain expertise in third-party tools, so I can’t offer advice on how to do that. I recommend that you escalate this via your tool’s support channel.

If there’s no direct support for calling Objective-C APIs in your tools, you could create a bridge from a language that does have such support, including C (Objective-C), C++ (Objective-C++), Swift, and numerous others.

Finally, Your Friend the System Log has lots of hints and tips about the system log.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

It’s better if you reply as a reply, rather than in the comments. See Quinn’s Top Ten DevForums Tips for this and other titbits.

I believe we can modify the Golang compiler but I guess to what degree would this be needed?

I think you’d have to ask someone who knew something about the Go compiler (-:

But, again, you need to split this into two:

  • Adding log points that work efficiently

  • Reading the system log

The first requires careful compiler integration. The second requires the ability to import and use an Objective-C API. These are different problems and it would be a mistake to conflate them.

For example, the Swift compiler was able to access Objective-C APIs from day one, but it took a while to get good log point support (in the form of the Logger type).

can I query the unified logging system directly somehow?

I think that depends on your definition of “directly”. I know of two ways to extract information from the system log:

  • The OSLog framework, which vends on Objective-C API

  • The log command-line tool

IMO the first is more direct than the second.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unified Logging System in Go
 
 
Q