Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a log-level argument to set the log level #3651

Merged
merged 5 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Types/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 23 additions & 12 deletions src/Ide/Arguments.hs
Original file line number Diff line number Diff line change
@@ -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(..)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down