Giter Club home page Giter Club logo

awfullog's Introduction

Awful Log

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.

Load Lepiter

After installing with Metacello, you will be able to execute

#BaselineOfAwfulLog asClass loadLepiter

How to Log AwfulLog events

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 ].

Direct logging to transcript

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.

AwfulLogEvent logToTranscript

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.

Direct logging with Beacon

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 .

AwfulLogEvent logToBeacon.

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

Using a custom Beacon

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

awfullog's People

Contributors

tgentry-bamboo avatar graves avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.