Open larskuhtz opened 9 years ago
We use them in several places. The purpose is to add labels to log-messages.
The original motivation was to add scope to log messages. For example services often have several subcomponents and it is helpful to see from where a log comes:
httpClientComponent = withLabel ("component", "http-client") $ do...
awsClient httpClient = withLabel ("component", "aws-client") $ do {- may use httpClient -}...
adminInternface = withLabel ("service-interface", "admin") $ do ...
publicInterface = withLabel ("service-interface", "public") $ do....
It also helps with building services in a modular way, since the code that generates log messages them doesn't need to know about it's context.
Consumers, for example the backend, can use this labels to pattern match and apply special processing.
In the past I had to write a log-analyzer that aggregated all the logs from all our services. Those labels where extremely useful. The alternative would have been to match with regex into the text messages.
It's also helpful for debugging:
someWeirdFunction = withLevel Debug $ withLabel ("function", "someWeirdFunction") $ ....
where
crazy = withLabel ("function", "crazy") $ ...
Right now the labels are not typed -- so users should agree on certain labels. I consider to make the type of the labels (either the key, or the value, or both, or the complete label type) a type parameter (that would be instantiated to (Text,Text)
in the high-level default API).
An alternative approach would be to have library users implement labels them self as part of the log message type. But often (for simple projects) it is convenient to just use Text
as message type and get labels out of the box.
Also it's nice to have direct support for the labels in MonadLog
which wouldn't be possible if labels would be part of the log messages without rolling your own monad on top of MonadLog
.
ok, that makes sense. Log sections (component labels) are a standard logging feature.
We aren't using these right? What is the purpose supposed to be?