{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Provides the types for logging.
module Navi.Data.NaviLog
  ( LogFile (..),
    LogEnv (..),
  )
where

import Effects.LoggerNamespace (Namespace)
import Navi.Prelude

-- | Data for file logging.
--
-- @since 0.1
data LogFile = MkLogFile
  { -- | File handle.
    --
    -- @since 0.1
    LogFile -> Handle
handle :: !Handle,
    -- Finalizer to run e.g. flush/close.
    --
    -- @since 0.1
    LogFile -> IO ()
finalizer :: IO ()
  }

-- | @since 0.1
makeFieldLabelsNoPrefix ''LogFile

-- | Holds logging env data.
--
-- @since 0.1
data LogEnv = MkLogEnv
  { -- | Data for file logging.
    --
    -- @since 0.1
    LogEnv -> Maybe LogFile
logFile :: !(Maybe LogFile),
    -- | Level in which to log.
    --
    -- @since 0.1
    LogEnv -> LogLevel
logLevel :: !LogLevel,
    -- | The current logging namespace.
    --
    -- @since 0.1
    LogEnv -> Namespace
logNamespace :: !Namespace
  }

-- | @since 0.1
makeFieldLabelsNoPrefix ''LogEnv