diff --git a/README.md b/README.md index 9a7f822..64aca54 100644 --- a/README.md +++ b/README.md @@ -47,5 +47,4 @@ By setting `$BASE_DIR` you can persist the database for later runs. - [x] Test leap second handling in the `time` package - [x] Fix container shutdown delay - [ ] Fix `responseFile` always returning 200 -- [ ] use queue to sync logging of indexer and main thread - [x] Vendor PDF.js for consistent cross-platform PDF rendering diff --git a/app/Main.hs b/app/Main.hs index 9e2550f..80aee13 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -65,7 +65,6 @@ import Yore.Time (addYears, getCurrentDay, getSecondsUntilMidnight) import Data.Fixed (Pico) import Data.Time.Clock.POSIX (getPOSIXTime) import qualified Envy -import System.IO (BufferMode (..), hSetBuffering, stdout) import qualified Yore.DB as DB import qualified Yore.Log as Log @@ -83,7 +82,7 @@ deriving instance Show Config main :: IO () main = do - hSetBuffering stdout NoBuffering + Log.setup cfg <- Envy.load @ConfigT >>= \case diff --git a/src/Yore/Log.hs b/src/Yore/Log.hs index 701abba..142a90d 100644 --- a/src/Yore/Log.hs +++ b/src/Yore/Log.hs @@ -1,11 +1,18 @@ -module Yore.Log (Yore.Log.error, info) where +module Yore.Log (Yore.Log.error, info, setup) where import Control.Monad.IO.Class (MonadIO (..)) import Data.Time (ZonedTime, getZonedTime) import Data.Time.Format (defaultTimeLocale, formatTime) import GHC.Stack (HasCallStack, SrcLoc (..), callStack, getCallStack) +import System.IO (BufferMode (..), hSetBuffering, stdout) import Text.Printf (printf) +import qualified Data.Text as Text +import qualified Data.Text.IO as TextIO + +setup :: IO () +setup = hSetBuffering stdout LineBuffering + info :: (HasCallStack, MonadIO m) => String -> m () info = doLog "INF" @@ -16,7 +23,7 @@ doLog :: (HasCallStack, MonadIO m) => String -> String -> m () doLog level msg = liftIO $ do now <- getZonedTime let location = getLocation $ getCallStack callStack - printf "(%s) (%s) (%s) %s\n" (iso8601Show now) level location msg + TextIO.putStrLn $ Text.pack $ printf "(%s) (%s) (%s) %s" (iso8601Show now) level location msg where getLocation :: [(String, SrcLoc)] -> String -- First entry is always a function from this module, skip it