diff --git a/exe/Main.hs b/exe/Main.hs index fc118eaffb..f688fc6e6b 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -9,8 +9,7 @@ import Control.Monad.IO.Class (liftIO) import Data.Function ((&)) import Data.Text (Text) import qualified Development.IDE.Main as GhcideMain -import Development.IDE.Types.Logger (Doc, - Priority (Debug, Error, Info), +import Development.IDE.Types.Logger (Doc, Priority (Error, Info), WithPriority (WithPriority, priority), cfilter, cmapWithPrio, defaultLayoutOptions, @@ -61,9 +60,8 @@ main = do let (argsTesting, minPriority, logFilePath) = case args of - Ghcide GhcideArguments{ argsTesting, argsDebugOn, argsLogFile} -> - let minPriority = if argsDebugOn || argsTesting then Debug else Info - in (argsTesting, minPriority, argsLogFile) + Ghcide GhcideArguments{ argsTesting, argsLogLevel, argsLogFile} -> + (argsTesting, argsLogLevel, argsLogFile) _ -> (False, Info, Nothing) withDefaultRecorder logFilePath Nothing $ \textWithPriorityRecorder -> do diff --git a/ghcide/src/Development/IDE/Types/Logger.hs b/ghcide/src/Development/IDE/Types/Logger.hs index f42c54237f..5b62dccfe8 100644 --- a/ghcide/src/Development/IDE/Types/Logger.hs +++ b/ghcide/src/Development/IDE/Types/Logger.hs @@ -76,7 +76,7 @@ data Priority -- ^ These error messages should not occur in a expected usage, and -- should be investigated. | Error -- ^ Such log messages must never occur in expected usage. - deriving (Eq, Show, Ord, Enum, Bounded) + deriving (Eq, Show, Read, Ord, Enum, Bounded) -- | Note that this is logging actions _of the program_, not of the user. -- You shouldn't call warning/error if the user has caused an error, only diff --git a/src/Ide/Arguments.hs b/src/Ide/Arguments.hs index 43826dbd93..8c03f1b0fc 100644 --- a/src/Ide/Arguments.hs +++ b/src/Ide/Arguments.hs @@ -1,10 +1,11 @@ -- Copyright (c) 2019 The DAML Authors. All rights reserved. -- SPDX-License-Identifier: Apache-2.0 -{-# LANGUAGE CPP #-} -{-# LANGUAGE RecordWildCards #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TupleSections #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE RecordWildCards #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TupleSections #-} {-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above +{-# LANGUAGE TypeApplications #-} module Ide.Arguments ( Arguments(..) @@ -19,6 +20,7 @@ module Ide.Arguments import Data.Version import Development.IDE (IdeState) import Development.IDE.Main (Command (..), commandP) +import Development.IDE.Types.Logger (Priority (..)) import GitHash (giHash, tGitInfoCwdTry) import Ide.Types (IdePlugins) import Options.Applicative @@ -43,10 +45,9 @@ data GhcideArguments = GhcideArguments ,argsShakeProfiling :: Maybe FilePath ,argsTesting :: Bool ,argsExamplePlugin :: Bool - -- These next two are for compatibility with existing hie clients, allowing - -- them to just change the name of the exe and still work. - , argsDebugOn :: Bool + , argsLogLevel :: Priority , argsLogFile :: Maybe String + -- ^ the minimum log level to show , argsThreads :: Int , argsProjectGhcVersion :: Bool } deriving Show @@ -122,13 +123,23 @@ arguments plugins = GhcideArguments <*> switch (long "example" <> help "Include the Example Plugin. For Plugin devs only") - <*> switch - ( long "debug" + <*> + (option @Priority auto + (long "log-level" + <> help "Only show logs at or above this log level" + <> metavar "LOG_LEVEL" + <> value Info + <> showDefault + ) + <|> + flag' Debug + (long "debug" <> short 'd' - <> help "Generate debug output" - ) + <> help "Sets the log level to Debug, alias for '--log-level Debug'" + ) + ) <*> optional (strOption - ( long "logfile" + (long "logfile" <> short 'l' <> metavar "LOGFILE" <> help "File to log to, defaults to stdout"