mirror of
https://github.com/Start9Labs/registry.git
synced 2026-03-30 11:51:57 +00:00
improves logging
This commit is contained in:
@@ -15,6 +15,7 @@ default-extensions:
|
|||||||
dependencies:
|
dependencies:
|
||||||
- base >=4.12 && <5
|
- base >=4.12 && <5
|
||||||
- aeson
|
- aeson
|
||||||
|
- ansi-terminal
|
||||||
- attoparsec
|
- attoparsec
|
||||||
- binary
|
- binary
|
||||||
- bytestring
|
- bytestring
|
||||||
@@ -36,6 +37,7 @@ dependencies:
|
|||||||
- interpolate
|
- interpolate
|
||||||
- lens
|
- lens
|
||||||
- monad-logger
|
- monad-logger
|
||||||
|
- monad-logger-extras
|
||||||
- persistent
|
- persistent
|
||||||
- persistent-postgresql
|
- persistent-postgresql
|
||||||
- persistent-template
|
- persistent-template
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
appmgr downloaded
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
get it all up down around
|
|
||||||
@@ -291,9 +291,9 @@ startWeb foundation = do
|
|||||||
where
|
where
|
||||||
startWeb' app = (`onException` (appStopFsNotify foundation)) $ do
|
startWeb' app = (`onException` (appStopFsNotify foundation)) $ do
|
||||||
let AppSettings {..} = appSettings foundation
|
let AppSettings {..} = appSettings foundation
|
||||||
putStrLn @Text $ "Launching Tor Web Server on port " <> show torPort
|
runLog $ $logInfo $ "Launching Tor Web Server on port " <> show torPort
|
||||||
torAction <- async $ runSettings (warpSettings torPort foundation) app
|
torAction <- async $ runSettings (warpSettings torPort foundation) app
|
||||||
putStrLn @Text $ "Launching Web Server on port " <> show appPort
|
runLog $ $logInfo $ "Launching Web Server on port " <> show appPort
|
||||||
action <- if sslAuto
|
action <- if sslAuto
|
||||||
then async $ runTLS (tlsSettings sslCertLocation sslKeyLocation) (warpSettings appPort foundation) app
|
then async $ runTLS (tlsSettings sslCertLocation sslKeyLocation) (warpSettings appPort foundation) app
|
||||||
else async $ runSettings (warpSettings appPort foundation) app
|
else async $ runSettings (warpSettings appPort foundation) app
|
||||||
@@ -316,6 +316,7 @@ startWeb foundation = do
|
|||||||
putMVar (appShouldRestartWeb foundation) False
|
putMVar (appShouldRestartWeb foundation) False
|
||||||
putStrLn @Text "Restarting Web Server"
|
putStrLn @Text "Restarting Web Server"
|
||||||
startWeb' app
|
startWeb' app
|
||||||
|
runLog a = runLoggingT a (messageLoggerSource foundation (appLogger foundation))
|
||||||
|
|
||||||
restartWeb :: RegistryCtx -> IO ()
|
restartWeb :: RegistryCtx -> IO ()
|
||||||
restartWeb foundation = do
|
restartWeb foundation = do
|
||||||
|
|||||||
@@ -2,27 +2,47 @@
|
|||||||
{-# LANGUAGE MultiParamTypeClasses #-}
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
{-# LANGUAGE RankNTypes #-}
|
{-# LANGUAGE RankNTypes #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
module Foundation where
|
module Foundation where
|
||||||
|
|
||||||
import Startlude hiding ( Handler )
|
import Startlude hiding ( Handler )
|
||||||
|
|
||||||
import Control.Monad.Logger ( LogSource )
|
import Control.Monad.Logger ( Loc
|
||||||
|
, LogSource
|
||||||
|
, LogStr
|
||||||
|
, ToLogStr(toLogStr)
|
||||||
|
, fromLogStr
|
||||||
|
)
|
||||||
import Database.Persist.Sql hiding ( update )
|
import Database.Persist.Sql hiding ( update )
|
||||||
import Lib.Registry
|
import Lib.Registry
|
||||||
import Yesod.Core
|
import Yesod.Core
|
||||||
import Yesod.Core.Types ( HandlerData(handlerEnv)
|
import Yesod.Core.Types ( HandlerData(handlerEnv)
|
||||||
, Logger
|
, Logger(loggerDate)
|
||||||
, RunHandlerEnv(rheChild, rheSite)
|
, RunHandlerEnv(rheChild, rheSite)
|
||||||
|
, loggerPutStr
|
||||||
)
|
)
|
||||||
import qualified Yesod.Core.Unsafe as Unsafe
|
import qualified Yesod.Core.Unsafe as Unsafe
|
||||||
|
|
||||||
|
import qualified Control.Monad.Logger.Extras as Extra
|
||||||
|
import Control.Monad.Logger.Extras ( wrapSGRCode )
|
||||||
import Control.Monad.Reader.Has ( Has(extract, update) )
|
import Control.Monad.Reader.Has ( Has(extract, update) )
|
||||||
|
import Data.String.Interpolate.IsString
|
||||||
|
( i )
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Language.Haskell.TH ( Loc(..) )
|
||||||
import Lib.PkgRepository
|
import Lib.PkgRepository
|
||||||
import Lib.Types.AppIndex
|
import Lib.Types.AppIndex
|
||||||
import Settings
|
import Settings
|
||||||
|
import System.Console.ANSI.Codes ( Color(..)
|
||||||
|
, ColorIntensity(..)
|
||||||
|
, ConsoleLayer(Foreground)
|
||||||
|
, SGR(SetColor)
|
||||||
|
)
|
||||||
import System.FilePath ( (</>) )
|
import System.FilePath ( (</>) )
|
||||||
|
import Yesod ( defaultMessageLoggerSource )
|
||||||
import Yesod.Persist.Core
|
import Yesod.Persist.Core
|
||||||
|
|
||||||
-- | The foundation datatype for your application. This can be a good place to
|
-- | The foundation datatype for your application. This can be a good place to
|
||||||
@@ -101,6 +121,42 @@ instance Yesod RegistryCtx where
|
|||||||
makeLogger :: RegistryCtx -> IO Logger
|
makeLogger :: RegistryCtx -> IO Logger
|
||||||
makeLogger = return . appLogger
|
makeLogger = return . appLogger
|
||||||
|
|
||||||
|
messageLoggerSource :: RegistryCtx -> Logger -> Loc -> LogSource -> LogLevel -> LogStr -> IO ()
|
||||||
|
messageLoggerSource ctx logger = \loc src lvl str -> do
|
||||||
|
shouldLog <- shouldLogIO ctx src lvl
|
||||||
|
when shouldLog $ do
|
||||||
|
date <- loggerDate logger
|
||||||
|
let
|
||||||
|
formatted =
|
||||||
|
toLogStr date
|
||||||
|
<> ( toLogStr
|
||||||
|
. wrapSGRCode [SetColor Foreground Vivid (colorFor lvl)]
|
||||||
|
$ fromLogStr
|
||||||
|
( " ["
|
||||||
|
<> renderLvl lvl
|
||||||
|
<> (if T.null src then mempty else "#" <> toLogStr src)
|
||||||
|
<> "] "
|
||||||
|
<> str
|
||||||
|
)
|
||||||
|
)
|
||||||
|
<> (toLogStr
|
||||||
|
(wrapSGRCode [SetColor Foreground Dull White]
|
||||||
|
[i| @ #{loc_filename loc}:#{fst $ loc_start loc}\n|]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
loggerPutStr logger formatted
|
||||||
|
where
|
||||||
|
renderLvl lvl = case lvl of
|
||||||
|
LevelOther t -> toLogStr t
|
||||||
|
_ -> toLogStr @String $ drop 5 $ show lvl
|
||||||
|
colorFor = \case
|
||||||
|
LevelDebug -> Green
|
||||||
|
LevelInfo -> Blue
|
||||||
|
LevelWarn -> Yellow
|
||||||
|
LevelError -> Red
|
||||||
|
LevelOther _ -> White
|
||||||
|
|
||||||
|
|
||||||
-- How to run database actions.
|
-- How to run database actions.
|
||||||
instance YesodPersist RegistryCtx where
|
instance YesodPersist RegistryCtx where
|
||||||
type YesodPersistBackend RegistryCtx = SqlBackend
|
type YesodPersistBackend RegistryCtx = SqlBackend
|
||||||
|
|||||||
@@ -173,6 +173,7 @@ extractPkg fp = (`onException` cleanup) $ do
|
|||||||
|
|
||||||
watchPkgRepoRoot :: (MonadUnliftIO m, MonadReader r m, Has PkgRepo r, MonadLoggerIO m) => m (IO Bool)
|
watchPkgRepoRoot :: (MonadUnliftIO m, MonadReader r m, Has PkgRepo r, MonadLoggerIO m) => m (IO Bool)
|
||||||
watchPkgRepoRoot = do
|
watchPkgRepoRoot = do
|
||||||
|
$logInfo "Starting FSNotify Watch Manager"
|
||||||
root <- asks pkgRepoFileRoot
|
root <- asks pkgRepoFileRoot
|
||||||
runInIO <- askRunInIO
|
runInIO <- askRunInIO
|
||||||
box <- newEmptyMVar @_ @()
|
box <- newEmptyMVar @_ @()
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ packages:
|
|||||||
extra-deps:
|
extra-deps:
|
||||||
- protolude-0.3.0
|
- protolude-0.3.0
|
||||||
- esqueleto-3.5.1.0
|
- esqueleto-3.5.1.0
|
||||||
|
- monad-logger-extras-0.1.1.1
|
||||||
|
- wai-request-spec-0.10.2.4
|
||||||
# Override default flag values for local packages and extra-deps
|
# Override default flag values for local packages and extra-deps
|
||||||
# flags: {}
|
# flags: {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user