@@ -41,7 +41,6 @@ import Network.Socket hiding (PortNumber, Type,
4141 sClose )
4242import Options.Applicative (ParseError (.. ))
4343import qualified Options.Applicative as Opts
44- import System.Clock
4544import System.Directory
4645import System.Info as SysInfo
4746import System.FilePath
@@ -70,11 +69,12 @@ data Options = Options
7069 , optionsNoWatch :: Bool
7170 , optionsPolling :: Bool
7271 , optionsDebug :: Bool
72+ , optionsLoglevel :: IdeLogLevel
7373 } deriving (Show )
7474
7575main :: IO ()
7676main = do
77- opts'@ (Options dir globs outputPath port noWatch polling debug) <- Opts. execParser opts
77+ opts'@ (Options dir globs outputPath port noWatch debug logLevel ) <- Opts. execParser opts
7878 when debug (putText " Parsed Options:" *> print opts')
7979 maybe (pure () ) setCurrentDirectory dir
8080 ideState <- newTVarIO emptyIdeState
@@ -89,8 +89,8 @@ main = do
8989
9090 unless noWatch $
9191 void (forkFinally (watcher polling ideState fullOutputPath) print )
92-
93- let conf = Configuration {confDebug = debug, confOutputPath = outputPath, confGlobs = globs}
92+ -- TODO: deprecate and get rid of `debug`
93+ let conf = Configuration {confLogLevel = if debug then LogDebug else logLevel , confOutputPath = outputPath, confGlobs = globs}
9494 env = IdeEnvironment {ideStateVar = ideState, ideConfiguration = conf}
9595 startServer port env
9696 where
@@ -104,7 +104,16 @@ main = do
104104 <*> Opts. switch (Opts. long " no-watch" )
105105 <*> flipIfWindows (Opts. switch (Opts. long " polling" ))
106106 <*> Opts. switch (Opts. long " debug" )
107+ <*> (parseLogLevel <$> Opts. strOption
108+ (Opts. long " log-level"
109+ <> Opts. value " "
110+ <> Opts. help " One of \" debug\" , \" perf\" or \" all\" " ))
107111 opts = Opts. info (version <*> Opts. helper <*> parser) mempty
112+ parseLogLevel s = case s of
113+ " debug" -> LogDebug
114+ " perf" -> LogPerf
115+ " all" -> LogAll
116+ _ -> LogNone
108117 version = Opts. abortOption
109118 (InfoMsg (showVersion Paths. version))
110119 (Opts. long " version" `mappend` Opts. help " Show the version number" )
@@ -116,10 +125,8 @@ main = do
116125startServer :: PortNumber -> IdeEnvironment -> IO ()
117126startServer port env = withSocketsDo $ do
118127 sock <- listenOnLocalhost port
119- runLogger (runReaderT (forever (loop sock)) env)
128+ runLogger (confLogLevel (ideConfiguration env)) ( runReaderT (forever (loop sock)) env)
120129 where
121- runLogger = runStdoutLoggingT . filterLogger (\ _ _ -> confDebug (ideConfiguration env))
122-
123130 loop :: (Ide m , MonadLogger m ) => Socket -> m ()
124131 loop sock = do
125132 accepted <- runExceptT $ acceptCommand sock
@@ -128,10 +135,11 @@ startServer port env = withSocketsDo $ do
128135 Right (cmd, h) -> do
129136 case decodeT cmd of
130137 Just cmd' -> do
131- start <- liftIO (getTime Monotonic )
132- result <- runExceptT (handleCommand cmd')
133- end <- liftIO (getTime Monotonic )
134- $ (logDebug) (" Command " <> commandName cmd' <> " took " <> (displayTimeSpec (diffTimeSpec start end)))
138+ let message duration =
139+ " Command " <> commandName cmd'
140+ <> " took "
141+ <> displayTimeSpec duration
142+ result <- logPerf message (runExceptT (handleCommand cmd'))
135143 -- $(logDebug) ("Answer was: " <> T.pack (show result))
136144 liftIO (hFlush stdout)
137145 case result of
0 commit comments