From 17c44751be3d4a516b92b6db967c1c40411cb658 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Mon, 17 Nov 2014 14:22:06 +0200 Subject: [PATCH] Slightly improved logging --- Application.hs | 10 ++++++++-- Data/Hackage.hs | 6 +++++- stackage-server.cabal | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Application.hs b/Application.hs index 568cb8f..43cea9d 100644 --- a/Application.hs +++ b/Application.hs @@ -8,7 +8,7 @@ module Application import qualified Aws import Control.Concurrent (forkIO, threadDelay) -import Control.Monad.Logger (runLoggingT, LoggingT, runStdoutLoggingT) +import Control.Monad.Logger (runLoggingT, LoggingT, runStdoutLoggingT, defaultLogStr, LogLevel (LevelDebug)) import Control.Monad.Reader (MonadReader (..)) import Control.Monad.Reader (runReaderT, ReaderT) import Control.Monad.Trans.Control @@ -220,7 +220,7 @@ cabalLoaderMain = do manager <- newManager bs <- loadBlobStore manager conf hSetBuffering stdout LineBuffering - runStdoutLoggingT $ appLoadCabalFiles + flip runLoggingT logFunc $ appLoadCabalFiles CabalLoaderEnv { cleSettings = conf , cleBlobStore = bs @@ -228,6 +228,10 @@ cabalLoaderMain = do } dbconf pool + where + logFunc loc src level str + | level > LevelDebug = hPutStrLn stdout $ fromLogStr $ defaultLogStr loc src level str + | otherwise = return () appLoadCabalFiles :: ( PersistConfig c , PersistConfigBackend c ~ SqlPersistT @@ -254,7 +258,9 @@ appLoadCabalFiles env dbconf p = do , m E.^. MetadataHash ) UploadState uploadHistory newUploads _ newMD <- loadCabalFiles uploadHistory0 metadata0 + $logInfo "Inserting to new uploads" runDB' $ mapM_ insert_ newUploads + $logInfo "Updating metadatas" runDB' $ forM_ newMD $ \x -> do deleteBy $ UniqueMetadata $ metadataName x insert_ x diff --git a/Data/Hackage.hs b/Data/Hackage.hs index 5bda8d3..f737142 100644 --- a/Data/Hackage.hs +++ b/Data/Hackage.hs @@ -75,7 +75,11 @@ loadCabalFiles uploadHistory0 metadata0 = (>>= runUploadState) $ flip execStateT liftIO $ hClose handleOut withBinaryFile tempIndex ReadMode $ \handleIn -> do bss <- lazyConsume $ sourceHandle handleIn $= ungzip - tarSource (Tar.read $ fromChunks bss) $$ parMapMC 32 go =$ sinkNull -- FIXME parMapM_C + tarSource (Tar.read $ fromChunks bss) + $$ parMapMC 32 go + =$ scanlC (\x _ -> x + 1) 0 + =$ filterC ((== 0) . (`mod` 1000)) + =$ mapM_C (\i -> $logInfo $ "Processing cabal file #" ++ tshow i) where metadata1 = flip fmap metadata0 $ \(v, h) -> MetaSig v diff --git a/stackage-server.cabal b/stackage-server.cabal index f109839..a435774 100644 --- a/stackage-server.cabal +++ b/stackage-server.cabal @@ -142,6 +142,7 @@ library , unix , markdown , formatting + , blaze-html executable stackage-server if flag(library-only)