diff --git a/src/TinyLogger-Tests/TinyLoggerTest.class.st b/src/TinyLogger-Tests/TinyLoggerTest.class.st index 8bbc4fe..75c747a 100644 --- a/src/TinyLogger-Tests/TinyLoggerTest.class.st +++ b/src/TinyLogger-Tests/TinyLoggerTest.class.st @@ -222,6 +222,25 @@ No time : End: This is a new test stream close ] ] +{ #category : #test } +TinyLoggerTest >> testExecuteRecordedAsReturnBlockContent [ + | contents stream bool | + self skipInPharo6. + bool := false. + logger + removeAllLoggers; + addStdoutLogger. + stream := '' writeStream. + [ Stdio stub stdout willReturn: stream. + bool := logger execute: [ true ] recordedAs: 'This is a new test'. + contents := Stdio stdout contents asString. + self assert: bool. + self assert: (contents includesSubstring: 'Begin: This is a new test'). + self assert: (contents includesSubstring: 'End: This is a new test') ] + ensure: [ Stdio recoverFromGHMutation. + stream close ] +] + { #category : #test } TinyLoggerTest >> testFileLoggers [ logger diff --git a/src/TinyLogger/Object.extension.st b/src/TinyLogger/Object.extension.st index 7760cfb..79e0530 100644 --- a/src/TinyLogger/Object.extension.st +++ b/src/TinyLogger/Object.extension.st @@ -2,7 +2,7 @@ Extension { #name : #Object } { #category : #'*TinyLogger' } Object >> execute: aBlock recordedAs: aString [ - TinyCurrentLogger value execute: aBlock recordedAs: aString + ^ TinyCurrentLogger value execute: aBlock recordedAs: aString ] { #category : #'*TinyLogger' } diff --git a/src/TinyLogger/TinyLogger.class.st b/src/TinyLogger/TinyLogger.class.st index 834b76b..a918aa0 100644 --- a/src/TinyLogger/TinyLogger.class.st +++ b/src/TinyLogger/TinyLogger.class.st @@ -181,17 +181,19 @@ TinyLogger >> ensureTranscriptLogger [ { #category : #'public API' } TinyLogger >> execute: aBlock recordedAs: aString [ + | result | self increaseDepthLevel. self record: 'Begin: ' , aString. self increaseDepthLevel. - [ aBlock cull: aString ] + [ result := aBlock cull: aString ] ifCurtailed: [ "If there is an error, we ensure we keep the right indentation and we print an end of action with error." self decreaseDepthLevel. self record: 'End with error: ' , aString. self decreaseDepthLevel ]. self decreaseDepthLevel. self record: 'End: ' , aString. - self decreaseDepthLevel + self decreaseDepthLevel. + ^ result ] { #category : #'accessing - loggers' }