bartavelle / language-puppet

A library to work with Puppet manifests, test them and eventually replace everything ruby.
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link

Add priority to the logger output #106

Closed PierreR closed 9 years ago

PierreR commented 9 years ago

I would like to add this snippet to the Daemon:

      setupLogger = do
        f <- LOG.setFormatter
            <$> LOG.streamHandler stdout LOG.WARNING
            <*> pure (LOG.simpleLogFormatter "$prio: $msg")
        LOG.updateGlobalLogger loggerName $ LOG.setHandlers [f]

It works nicely and I have found the output to be clearer.

Still it is a bit odd that I do it just for 'WARNING'. Do you know a better way to do this ? Do I really need to create one f for each priority ?

Another option is to append p when we mapM_ but this is a bit at odd with how a logger is supposed to be used.

PierreR commented 9 years ago

The best I can come up with is:

      stdoutHandler p = setFormatter
                        <$> streamHandler stdout p
                        <*> pure (simpleLogFormatter "$prio: $msg")
      setupLogger = do
         hs <- for [LOG.DEBUG, LOG.INFO, LOG.NOTICE, LOG.WARNING] stdoutHandler
         LOG.updateGlobalLogger loggerName $ LOG.setHandlers hs

It seems good enough for me.

It probably makes sense to do this for both Puppet.Daemon and Hiera.Server logger ?

What do you think ?

PierreR commented 9 years ago

Let me know if the fix is OK or not.

Cheers

bartavelle commented 9 years ago

Seems OK to me !