Skip to content

Latest commit

 

History

History
93 lines (62 loc) · 2.05 KB

README.md

File metadata and controls

93 lines (62 loc) · 2.05 KB

Whirl

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.

Logger API Documentation

The Logger module provides a simple logging functionality with support for different severity levels.

Types

LogLevel

Represents the severity levels for log messages.

data LogLevel = INFO | WARNING | ERROR | DEBUG deriving (Eq, Ord, Show)

LogMessage

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)

LoggerConfig

Configuration for the logger.

data LoggerConfig = LoggerConfig
  { logConfigLevel :: LogLevel              -- ^ Minimum severity level to log.
  , logCallback    :: LogMessage -> IO ()   -- ^ Callback function to handle log messages.
  }

Functions

defaultConfig

Returns the default configuration for the logger.

defaultConfig :: LoggerConfig

initLogger

Initializes a new logger with the given configuration.

initLogger :: LoggerConfig -> IO Logger

logMessage

Logs a message with the specified severity level.

logMessage :: Logger -> LogLevel -> String -> IO ()

waitLogger

Helper function to wait for a logger to finish.

waitLogger :: Logger -> IO ()

Example Usage

-- 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.