Skip to content

Commit

Permalink
Simplify logging by sending all logs to stdout
Browse files Browse the repository at this point in the history
Before this change, the data updater logs were sent to a file set in the
configuration of the application, which more or less hid the logs there.
Meanwhile the access logs were sent to stdout. Now both kinds of logs
are sent to stdout which makes it much easier for the programs hosting
mat to read and parse the logs.

Close #63.
  • Loading branch information
Rembane committed Sep 25, 2023
1 parent 67bf6e8 commit 73b474e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
17 changes: 7 additions & 10 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ import System.Console.GetOpt ( ArgDescr(..)
, usageInfo
)
import System.Environment ( getArgs )
import System.IO ( IOMode(AppendMode)
, openFile
)
import System.IO ( stdout )
import Web.Scotty ( get
, html
, middleware
Expand All @@ -60,7 +58,6 @@ opts :: [OptDescr (Config -> Config)]
opts =
[ Option [] ["help"] (NoArg (set cHelp True)) "Show usage info"
, Option [] ["port"] (ReqArg (set cPort . read) "PORT") "Port to run on"
, Option [] ["logfile"] (ReqArg (set cLog) "LOGFILE") "Path to logfile."
, Option []
["interval"]
(ReqArg (set cInterval . (1000000 *) . read) "INTERVAL (s)")
Expand All @@ -81,22 +78,22 @@ main =
else do
upd <- newMVar () -- putMVar when to update
mgr <- newTlsManager
logHandle <- openFile (view cLog config) AppendMode
(viewRef, refreshAction) <- runLoggingT
(runReaderT refresh (ClientContext config mgr))
print
Async.concurrently_
(Async.concurrently_

Async.concurrently_
(Async.concurrently_
-- timer
(forever $ tryPutMVar upd () >> threadDelay (view cInterval config))
-- webserver
(serve config viewRef upd))
-- updater
(forever
$ withFDHandler defaultBatchingOptions logHandle 1.0 80
$ \logToHandle ->
$ withFDHandler defaultBatchingOptions stdout 1.0 80
$ \logCallback ->
runReaderT (refreshAction upd) (ClientContext config mgr)
`runLoggingT` ( logToHandle
`runLoggingT` ( logCallback
. renderWithTimestamp
(formatTime
defaultTimeLocale
Expand Down
3 changes: 1 addition & 2 deletions src/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ data Config = Config
, _cNextDayHour :: !Int
, _cInterval :: !Int
, _cPort :: !Int
, _cLog :: !String
} deriving (Eq, Show)

makeLenses ''Config

defaultConfig :: Config
defaultConfig = Config False 14 (1000000 * 60 * 30) 5007 "mat.log"
defaultConfig = Config False 14 (1000000 * 60 * 30) 5007

0 comments on commit 73b474e

Please sign in to comment.