Contents of Transcript?

Ned Konz ned at squeakland.org
Thu Feb 17 23:10:13 UTC 2005


On Thursday 17 February 2005 1:29 pm, Rick Zaccone wrote:
> I would like to capture the contents of the Transcript in a string.
> How do I do this?  Its "collection" instance variable has the first
> line of text, but not the remainder.

You can add a dependent to Transcript.

The attached code is such a logger.

-- 
Ned Konz
http://bike-nomad.com/squeak/
-------------- next part --------------
'From Squeak3.8gamma of ''24 November 2004'' [latest update: #6550] on 17 February 2005 at 3:09:17 pm'!
Object subclass: #TranscriptWriter
	instanceVariableNames: 'stream model'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'NK-Demos'!
!TranscriptWriter commentStamp: 'nk 2/17/2005 15:06' prior: 0!
I am an object that monitors changes to the Transcript and copies them to a disk file.

!


!TranscriptWriter methodsFor: 'logging' stamp: 'nk 2/17/2005 15:08'!
close
	model ifNotNil: [ model endEntry ].
	self release.! !

!TranscriptWriter methodsFor: 'logging' stamp: 'nk 2/17/2005 15:08'!
logFileName: aString
	self close.
	stream := FileStream newFileNamed: aString.
	model := Transcript.
	model addDependent: self.! !


!TranscriptWriter methodsFor: 'dependents access' stamp: 'nk 2/17/2005 15:04'!
release
	model ifNotNil: [
		model removeDependent: self.
		model := nil.
	].
	stream ifNotNil: [
		stream close.
		stream := nil.
	]! !


!TranscriptWriter methodsFor: 'updating' stamp: 'nk 2/17/2005 15:02'!
update: aSymbol
	aSymbol == #appendEntry ifFalse: [ ^self ].
	model ifNil: [ ^self ].
	stream ifNil: [ ^self ].
	stream nextPutAll: model contents.! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

TranscriptWriter class
	instanceVariableNames: ''!

!TranscriptWriter class methodsFor: 'instance creation' stamp: 'nk 2/17/2005 15:06'!
logFileName: aString
	^self new logFileName: aString; yourself! !


More information about the Squeak-dev mailing list