On 06 May 2013, at 08:00, Denis Kudriashov <dionisi...@gmail.com> wrote:

> I like "logInfo:", "logDebug:", "logTrace:". Or maybe it is better to split 
> log with levels: "self log info:", "self log debug:", "self log trace:"

That is actually the interface that I use, as implemented in Zinc-HTTP-Logging, 
together with optional block arguments.

Here is a simple example:

logRequest: request
        "Log a request that was just read"
        
        self log info: [ 
                lastRequest := request.
                'Read ', request printString ]

And a more complicated one (transaction is also a log level here):

logRequest: request response: response started: initialMilliseconds
        self log transaction: [
                String streamContents: [ :stream |
                        request requestLine printMethodAndUriOn: stream.  
                        stream space; print: response code.
                        response hasEntity ifTrue: [
                                stream space; print: response entity 
contentLength; nextPut: $B ].  
                        stream space; print: (Time millisecondsSince: 
initialMilliseconds); nextPutAll:  'ms' ] ]

I think it is really useful that the block is not executed when logging is 
disabled.
Another advantage of block arguments is that there can be an error handler 
around its evaluation: errors while logging are very annoying and are better 
handled automatically.

Sven


--
Sven Van Caekenberghe
Proudly supporting Pharo
http://pharo.org
http://association.pharo.org
http://consortium.pharo.org





Reply via email to