Whirl is a basic logging library for Haskell. I took on this project to teach myself the basics of Haskell and experience setting up a full library in the language.
The Logger module provides a simple logging functionality with support for different severity levels.
Represents the severity levels for log messages.
data LogLevel = INFO | WARNING | ERROR | DEBUG deriving (Eq, Ord, Show)
Represents a log message with a severity level and a message.
data LogMessage = LogMessage
{ logLevel :: LogLevel -- ^ Severity level of the log message.
, message :: String -- ^ The log message.
} deriving (Show)
Configuration for the logger.
data LoggerConfig = LoggerConfig
{ logConfigLevel :: LogLevel -- ^ Minimum severity level to log.
, logCallback :: LogMessage -> IO () -- ^ Callback function to handle log messages.
}
Returns the default configuration for the logger.
defaultConfig :: LoggerConfig
Initializes a new logger with the given configuration.
initLogger :: LoggerConfig -> IO Logger
Logs a message with the specified severity level.
logMessage :: Logger -> LogLevel -> String -> IO ()
Helper function to wait for a logger to finish.
waitLogger :: Logger -> IO ()
-- Initialize logger with default configuration
logger <- initLogger defaultConfig
-- Log messages with different severity levels
logMessage logger DEBUG "This is a debug message."
logMessage logger INFO "This is an informational message."
logMessage logger WARNING "This is a warning message."
logMessage logger ERROR "This is an error message."
-- Wait for the logger to finish
waitLogger logger
This example demonstrates how to use the Logger API to initialize a logger, log messages with various severity levels, and wait for the logger to finish processing.