Skip to content

Commit 3ee5303

Browse files
committed
Use default timestamp as default format
Fixes #8
1 parent cf18e85 commit 3ee5303

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

documentation/UserGuide.md

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,23 @@ If you with to know all the loggers of a kind, you can use:
103103
By default, the preamble of the log will be a timestamp with a human readable format like this:
104104

105105
```
106-
29 November 2018 00:06:30 : Test
106+
2018-11-29T23:19:55.511775+01:00 : Test
107107
```
108108

109109
But this format is configurable. The `timestampFormatBlock:` method can be use with a parameter that is a block taking a stream as parameter and the timestamp (instance of DateAndTime) and use that to write the preamble on the stream.
110110

111111
```Smalltalk
112-
TinyLogger default timestampFormatBlock: [ :s :timestamp | s << timestamp asString ]
112+
TinyLogger default
113+
timestampFormatBlock: [ :aStream :timestamp |
114+
timestamp asDate printOn: aStream.
115+
aStream << ' '. "Cannot use #space because of Stdio streams"
116+
timestamp asTime print24: true on: aStream ]
113117
```
114118

115119
This will produce logs of this format:
116120

117121
```
118-
2018-11-29T00:46:37.389775+01:00 : Test
122+
29 November 2018 00:06:30 : Test
119123
```
120124

121125
## Record with your logger
@@ -133,7 +137,7 @@ To record a single line log you can just use the method `record`:
133137
This will produce a log like this with the default `timestampFormatBlock`:
134138

135139
```
136-
29 November 2018 00:49:20 : This is a string to log
140+
2018-11-29T23:19:55.511775+01:00 : This is a string to log
137141
```
138142

139143
### Recording the execution of a task
@@ -147,13 +151,13 @@ self execute: [ 1 to: 5 do: [ :value | value asString record ] ] recordedAs: 'Ta
147151
Will produce a log like this:
148152

149153
```
150-
29 November 2018 00:56:20 : Begin: Task with only one nesting.
151-
29 November 2018 00:56:20 : 1
152-
29 November 2018 00:56:20 : 2
153-
29 November 2018 00:56:20 : 3
154-
29 November 2018 00:56:20 : 4
155-
29 November 2018 00:56:20 : 5
156-
29 November 2018 00:56:20 : End: Task with only one nesting.
154+
2018-11-29T23:21:04.897775+01:00 : Begin: Task with only one nesting.
155+
2018-11-29T23:21:04.900775+01:00 : 1
156+
2018-11-29T23:21:04.902775+01:00 : 2
157+
2018-11-29T23:21:04.904775+01:00 : 3
158+
2018-11-29T23:21:04.906775+01:00 : 4
159+
2018-11-29T23:21:04.908775+01:00 : 5
160+
2018-11-29T23:21:04.909775+01:00 : End: Task with only one nesting.
157161
```
158162

159163
It is also possible to nest them like that:
@@ -171,26 +175,26 @@ self execute: [
171175
It will produce this kind of output:
172176

173177
```
174-
29 November 2018 00:57:45 : Begin: My first nest
175-
29 November 2018 00:57:45 : Begin: My second nest
176-
29 November 2018 00:57:45 : 1
177-
29 November 2018 00:57:45 : End: My second nest
178-
29 November 2018 00:57:45 : Begin: My second nest
179-
29 November 2018 00:57:45 : 1
180-
29 November 2018 00:57:45 : 2
181-
29 November 2018 00:57:45 : End: My second nest
182-
29 November 2018 00:57:45 : Begin: My second nest
183-
29 November 2018 00:57:45 : 1
184-
29 November 2018 00:57:45 : 2
185-
29 November 2018 00:57:45 : 3
186-
29 November 2018 00:57:45 : End: My second nest
187-
29 November 2018 00:57:45 : Begin: My second nest
188-
29 November 2018 00:57:45 : 1
189-
29 November 2018 00:57:45 : 2
190-
29 November 2018 00:57:45 : 3
191-
29 November 2018 00:57:45 : 4
192-
29 November 2018 00:57:45 : End: My second nest
193-
29 November 2018 00:57:45 : End: My first nest
178+
2018-11-29T23:21:20.147775+01:00 : Begin: My first nest
179+
2018-11-29T23:21:20.151775+01:00 : Begin: My second nest
180+
2018-11-29T23:21:20.153775+01:00 : 1
181+
2018-11-29T23:21:20.155775+01:00 : End: My second nest
182+
2018-11-29T23:21:20.157775+01:00 : Begin: My second nest
183+
2018-11-29T23:21:20.158775+01:00 : 1
184+
2018-11-29T23:21:20.160775+01:00 : 2
185+
2018-11-29T23:21:20.161775+01:00 : End: My second nest
186+
2018-11-29T23:21:20.163775+01:00 : Begin: My second nest
187+
2018-11-29T23:21:20.164775+01:00 : 1
188+
2018-11-29T23:21:20.165775+01:00 : 2
189+
2018-11-29T23:21:20.167775+01:00 : 3
190+
2018-11-29T23:21:20.169775+01:00 : End: My second nest
191+
2018-11-29T23:21:20.171775+01:00 : Begin: My second nest
192+
2018-11-29T23:21:20.172775+01:00 : 1
193+
2018-11-29T23:21:20.175775+01:00 : 2
194+
2018-11-29T23:21:20.176775+01:00 : 3
195+
2018-11-29T23:21:20.177775+01:00 : 4
196+
2018-11-29T23:21:20.179775+01:00 : End: My second nest
197+
2018-11-29T23:21:20.180775+01:00 : End: My first nest
194198
```
195199

196200
## Use another logger than the global logger

src/TinyLogger/TinyLogger.class.st

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ Examples
5757
]
5858
5959
""Change the default timestamp format""
60-
TinyLogger default timestampFormatBlock: [ :stream :timestamp | stream << timestamp asString ].
60+
TinyLogger default
61+
timestampFormatBlock:
62+
[ :aStream :timestamp | timestamp asDate printOn: aStream. aStream << ' '. ""Cannot use #space because of Stdio streams"" timestamp asTime print24: true on: aStream ].
6163
6264
Internal Representation and Key Implementation Points.
6365
--------------------
@@ -131,10 +133,7 @@ TinyLogger >> decreaseDepthLevel [
131133

132134
{ #category : #accessing }
133135
TinyLogger >> defaultTimestampFormatBlock [
134-
^ [ :aStream :timestamp |
135-
timestamp asDate printOn: aStream.
136-
aStream << ' '. "Cannot use #space because Stdio streams does not implements it."
137-
timestamp asTime print24: true on: aStream ]
136+
^ [ :aStream :timestamp | aStream << timestamp asString ]
138137
]
139138

140139
{ #category : #accessing }

0 commit comments

Comments
 (0)