serokell / log-warper

Logging library to provide more convenient, extremely configurable but simple monadic interface with pretty output
MIT License
19 stars 11 forks source link

Add lens for changing logger names #86

Closed chshersh closed 6 years ago

chshersh commented 6 years ago

Sometimes it happens so that you want to change default logger configuration by changing properties of some logger. For example, in order to change default severity of specified logger you need to write something like this:

defaultConfig myName & lcTree . ltSubloggers . at myName . _Just . ltSeverity ?~ mySeverity

This is a lot of code... It will be much more convenient, if log-warper provides additional helper lens

atLogger :: LoggerName -> Traversal' LoggerConfig (Maybe LoggerTree)  -- not sure about type, didn't type check it
atLogger myName = lcTree . ltSubloggers . at myName . _Just  -- also not sure about name

Previous example can be rewritten in much shorter way using this lens:

defaultConfig myName & atLogger myName . ltSeverity ?~ mySeverity
vrom911 commented 6 years ago

@ChShersh I propose to support also subloggers like node.comm etc. So atLogger should parse the logger name and go to deeper level to get the logger we need.. What do you think?

chshersh commented 6 years ago

@vrom911 That's a nice idea! But probably we should think more about it. With lenses it's even possible to apply them several times. So something like this is possible with atLogger lens:

myConfig & atLogger "node"      . ltSeverity ?~ warningPlus
         & atLogger "node.comm" . ltSeverity ?~ debugPlus

But it won't be possible with defaultConfig because defaultConfig creates only single LoggerName. So if you want to change settings for "node.comm" you still need to create LoggerConfig either through combination of fromScratch, zoomLogger and ?= or through .yaml file. In case if person creates LoggeConfig through our monadic interface, he don't need this smart behavior of atLogger lens because he don't need atLogger lens at all.

But I still think that implementing this more smart behavior is better because such implementation makes usages of this lens more convenient.