These classes come from Zinc, they compose a stripped down, minimal, Beacon
logging implementation. Subclass AwfulLogEvent
to log Beacons
.
See: How to log Zinc events using Beacon where this was ripped from.
After installing with Metacello
, you will be able to execute
#BaselineOfAwfulLog asClass loadLepiter
The class side of AwfulLogEvent
Announcement subclass: #AwfulLogEvent
instanceVariableNames: 'id processId timestamp'
classVariableNames: 'IdCounter LogEventAnnouncer'
package: 'AwfulLog'
maintains a singleton announcer, accessed through AwfulLogEvent>>#announcer
, that is used to announce all log events. Consumers interested in log events can register with that announcer.
AwfulLogEvent announcer
when: AwfulLogEvent
do: [ :event |
self inform: 'Awful Log: ', event printString ].
The simples way to log all AwfulLog events is using AwfulLogEvent>>#logToTranscript
. That registers a consumer for logging announcements and prints them to the transcript. It does not use Beacon
, but directly prints announcements.
This is a global announcer. The subscription remains there until explicitly removed.
A different subclass of AwfulLogEvent
can be used to listen only for events of a given type.
The first and simplest way to use Beacon with AwfulLog events is through AwfulLogEvent>>#logToBeacon . This captures all log events raised by AwfulLog
and converts them to Beacon
signals, by wrapping them in an instance of AwfulLogEventSignal
.
We can work with any Beacon
logger to handle these signals; for example a MemoryLogger
to save the signals in memory, or a NonInteractiveTranscriptLogger
logger to directly print siglans to stdout.
MemoryLogger startFor: AwfulLogEventSignal
.
To filter for particular types of announcements we can use a custom condition:
MemoryLogger startFor: (AwfulLogEventSignal where: [ :aSignal |
aSignal target isKindOf: AwfulClientLogEvent]).
MemoryLogger stop
MemoryLogger reset.
MemoryLogger instance
The second, and more complex way to handle AwfulLog
log events using Beacon
, is to create a new Beacon
instance that directly listens for announcement announced by AwfulLogEvent>>#announcer
.
In this case the log announcements from AwfulLog
are directly used as Beacon
signals without any conversion.
beacon := Beacon new
announcer: AwfulLogEvent announcer
The logger that we use next needs to explicitly listed to the Beacon
instance we previously created.
logger := MemoryLogger new
beacon: beacon;
startFor: AwfulClientLogEvent
logger stop.
logger reset