Skip to content

Commit 408a2af

Browse files
Add a log-level argument to set the log level (#3651)
* Add a log-level argument to set the log level `--debug` remains as an alias for `--log-level Debug`. * Fix warning --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a951ad3 commit 408a2af

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

exe/Main.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import Control.Monad.IO.Class (liftIO)
99
import Data.Function ((&))
1010
import Data.Text (Text)
1111
import qualified Development.IDE.Main as GhcideMain
12-
import Development.IDE.Types.Logger (Doc,
13-
Priority (Debug, Error, Info),
12+
import Development.IDE.Types.Logger (Doc, Priority (Error, Info),
1413
WithPriority (WithPriority, priority),
1514
cfilter, cmapWithPrio,
1615
defaultLayoutOptions,
@@ -61,9 +60,8 @@ main = do
6160

6261
let (argsTesting, minPriority, logFilePath) =
6362
case args of
64-
Ghcide GhcideArguments{ argsTesting, argsDebugOn, argsLogFile} ->
65-
let minPriority = if argsDebugOn || argsTesting then Debug else Info
66-
in (argsTesting, minPriority, argsLogFile)
63+
Ghcide GhcideArguments{ argsTesting, argsLogLevel, argsLogFile} ->
64+
(argsTesting, argsLogLevel, argsLogFile)
6765
_ -> (False, Info, Nothing)
6866

6967
withDefaultRecorder logFilePath Nothing $ \textWithPriorityRecorder -> do

ghcide/src/Development/IDE/Types/Logger.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ data Priority
7676
-- ^ These error messages should not occur in a expected usage, and
7777
-- should be investigated.
7878
| Error -- ^ Such log messages must never occur in expected usage.
79-
deriving (Eq, Show, Ord, Enum, Bounded)
79+
deriving (Eq, Show, Read, Ord, Enum, Bounded)
8080

8181
-- | Note that this is logging actions _of the program_, not of the user.
8282
-- You shouldn't call warning/error if the user has caused an error, only

src/Ide/Arguments.hs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
22
-- SPDX-License-Identifier: Apache-2.0
3-
{-# LANGUAGE CPP #-}
4-
{-# LANGUAGE RecordWildCards #-}
5-
{-# LANGUAGE TemplateHaskell #-}
6-
{-# LANGUAGE TupleSections #-}
3+
{-# LANGUAGE CPP #-}
4+
{-# LANGUAGE RecordWildCards #-}
5+
{-# LANGUAGE TemplateHaskell #-}
6+
{-# LANGUAGE TupleSections #-}
77
{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above
8+
{-# LANGUAGE TypeApplications #-}
89

910
module Ide.Arguments
1011
( Arguments(..)
@@ -19,6 +20,7 @@ module Ide.Arguments
1920
import Data.Version
2021
import Development.IDE (IdeState)
2122
import Development.IDE.Main (Command (..), commandP)
23+
import Development.IDE.Types.Logger (Priority (..))
2224
import GitHash (giHash, tGitInfoCwdTry)
2325
import Ide.Types (IdePlugins)
2426
import Options.Applicative
@@ -43,10 +45,9 @@ data GhcideArguments = GhcideArguments
4345
,argsShakeProfiling :: Maybe FilePath
4446
,argsTesting :: Bool
4547
,argsExamplePlugin :: Bool
46-
-- These next two are for compatibility with existing hie clients, allowing
47-
-- them to just change the name of the exe and still work.
48-
, argsDebugOn :: Bool
48+
, argsLogLevel :: Priority
4949
, argsLogFile :: Maybe String
50+
-- ^ the minimum log level to show
5051
, argsThreads :: Int
5152
, argsProjectGhcVersion :: Bool
5253
} deriving Show
@@ -122,13 +123,23 @@ arguments plugins = GhcideArguments
122123
<*> switch (long "example"
123124
<> help "Include the Example Plugin. For Plugin devs only")
124125

125-
<*> switch
126-
( long "debug"
126+
<*>
127+
(option @Priority auto
128+
(long "log-level"
129+
<> help "Only show logs at or above this log level"
130+
<> metavar "LOG_LEVEL"
131+
<> value Info
132+
<> showDefault
133+
)
134+
<|>
135+
flag' Debug
136+
(long "debug"
127137
<> short 'd'
128-
<> help "Generate debug output"
129-
)
138+
<> help "Sets the log level to Debug, alias for '--log-level Debug'"
139+
)
140+
)
130141
<*> optional (strOption
131-
( long "logfile"
142+
(long "logfile"
132143
<> short 'l'
133144
<> metavar "LOGFILE"
134145
<> help "File to log to, defaults to stdout"

0 commit comments

Comments
 (0)