Accessing VM log messages using Beacon
The virtual machine has a logging system that usually prints to the console several types of log messages.
However, as they are only printed to the console, these log messages cannot be accessed from within the image and combined with other application-specific
Object subclass: #Beacon
signals for debugging. With
Object subclass: #GtVirtualMachineBeacon
instanceVariableNames: 'semaphore semaphoreIndex process signalMap'
we can access log messages from inside the image as Beacon signals.
When starting the logging we specify what types of log messages we want to have accessible as Beacon signals. We use
GtVirtualMachineSignal subclass: #GtVirtualMachineLevelSignal
to enable all default types of log messages.
GtVirtualMachineBeacon startFor: GtVirtualMachineLevelSignal
Alternatively, we can indicate individual types of log messages.
GtVirtualMachineBeacon startFor: GtVirtualMachineTraceSignal, GtVirtualMachineDebugSignal
Now we can use any Beacon logger to consume these messages, as normal Beacon signals.
CircularMemoryLogger startFor: GtVirtualMachineLevelSignal.
We can inspect the logger and stop collecting signals when we are done. Saving the image for example, generares several signals.
When done we can also stop the Beacon signals from comming from the VM into the image.
Custom log events
When debugging the VM, custom types of log messages could be added. We can enable them using
GtVirtualMachineSignal subclass: #GtVirtualMachineGenericSignal
For example, if the VM has a log message of type
SOCKET we can enable it using the snippt below:
GtVirtualMachineBeacon startFor: ( GtVirtualMachineGenericSignal named: 'SOCKET')
Then we could have a logger that only select Beacon signals for
SOCKET log events.
CircularMemoryLogger startFor: ( GtVirtualMachineGenericSignal where: [ :signal | signal name = 'SOCKET' ])