How do I do logging in Haskell?

后端 未结 3 396
后悔当初
后悔当初 2021-01-30 16:12

I\'m attempting to use HSlogger to get some information about my program. So I add the following line to my function

import Data.Word
import qualified Data.Byte         


        
3条回答
  •  一整个雨季
    2021-01-30 16:57

    Disclaimer: I'm the author of the Logger Haskell framework.

    Although McCann's answer is greatly detailed, it does not tell, that Haskell was lacking a general purpose logging framework at the time the question was asked. The HSLogger is a standard now, but it provides very basic logging functionality while being slow and not extensible. To be clear, here are some defects of HSLogger:

    1. It is slow. By being slow I mean, that every time you log a message it parses (in a very simple way) a string describing the origin of the log and uses some existential datatypes under the hood, which have to introduce some performance overhead at runtime.
    2. It does not allow logging in other monads than IO, so you have to use WriterT or other solutions not to mess your code.
    3. It is not extensible - you cannot create your own priority levels, define custom behaviours (like inter-thread logging) or compile time logs filtering.
    4. It does not provide some information, like line numbers or file names where the logs were placed. And of course it is very hard to extend it to support such information.

    That being said I would love to introduce the Logger Haskell framework. It allows for efficient & extensible logging, including:

    1. logging in sequential pure code (performing as well as using WriterT monad)
    2. advanced message filtering (including compile-time filtering)
    3. inter-thread logging ability
    4. provides TemplateHaskell interface allowing logging additional details, like file numbers or module names
    5. is very easily extensible - all the features are created as extensions to a simple BaseLogger, which cannot do anything sensible. To be clear - the filtering functionality is created in less than 20 lines as a logger-transformer and you can define your own transformers. How to do it is described in the documentation.
    6. Provides colored output on all platforms by default.

    But the library is pretty new, so it can lack some needed functionality. The good information is, that you can create this functionality easily by yourself or help us improve it by reporting issues on GitHub.

    The logger is developed internally by the company I'm working at (luna-lang.org) and is used inside a compiler we are creating.

提交回复
热议问题