Skip to content

Commit 6b639be

Browse files
committed
Change the default logger to print to stderr
1 parent 02a7040 commit 6b639be

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

ghcide/exe/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ main = do
8888
Typecheck x | not argLSP -> Just x
8989
_ -> Nothing
9090

91-
,Main.argsLogger = logger
91+
,Main.argsLogger = pure logger
9292

9393
,Main.argsRules = do
9494
-- install the main and ghcide-plugin rules

ghcide/src/Development/IDE/Main.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Data.Hashable (hashed)
6767
data Arguments = Arguments
6868
{ argsOTMemoryProfiling :: Bool
6969
, argFiles :: Maybe [FilePath] -- ^ Nothing: lsp server ; Just: typecheck and exit
70-
, argsLogger :: Logger
70+
, argsLogger :: IO Logger
7171
, argsRules :: Rules ()
7272
, argsHlsPlugins :: IdePlugins IdeState
7373
, argsGhcidePlugin :: Plugin Config -- ^ Deprecated
@@ -82,7 +82,7 @@ instance Default Arguments where
8282
def = Arguments
8383
{ argsOTMemoryProfiling = False
8484
, argFiles = Nothing
85-
, argsLogger = noLogging
85+
, argsLogger = stderrLogger
8686
, argsRules = mainRule >> action kick
8787
, argsGhcidePlugin = mempty
8888
, argsHlsPlugins = pluginDescToIdePlugins Ghcide.descriptors
@@ -93,9 +93,18 @@ instance Default Arguments where
9393
, argsGetHieDbLoc = getHieDbLoc
9494
}
9595

96+
-- | Cheap stderr logger that relies on LineBuffering
97+
stderrLogger :: IO Logger
98+
stderrLogger = do
99+
lock <- newLock
100+
return $ Logger $ \p m -> withLock lock $
101+
T.hPutStrLn stderr $ "[" <> T.pack (show p) <> "] " <> m
102+
96103
defaultMain :: Arguments -> IO ()
97104
defaultMain Arguments{..} = do
98105
pid <- T.pack . show <$> getProcessID
106+
logger <- argsLogger
107+
hSetBuffering stderr LineBuffering
99108

100109
let hlsPlugin = asGhcIdePlugin argsDefaultHlsConfig argsHlsPlugins
101110
hlsCommands = allLspCmdIds' pid argsHlsPlugins
@@ -134,7 +143,7 @@ defaultMain Arguments{..} = do
134143
argsDefaultHlsConfig
135144
rules
136145
(Just env)
137-
argsLogger
146+
logger
138147
debouncer
139148
options
140149
vfs
@@ -171,7 +180,7 @@ defaultMain Arguments{..} = do
171180
{ optCheckParents = pure NeverCheck
172181
, optCheckProject = pure False
173182
}
174-
ide <- initialise argsDefaultHlsConfig rules Nothing argsLogger debouncer options vfs hiedb hieChan
183+
ide <- initialise argsDefaultHlsConfig rules Nothing logger debouncer options vfs hiedb hieChan
175184
registerIdeConfiguration (shakeExtras ide) $ IdeConfiguration mempty (hashed Nothing)
176185

177186
putStrLn "\nStep 4/4: Type checking the files"
@@ -199,7 +208,7 @@ defaultMain Arguments{..} = do
199208
Key GhcSessionDeps :
200209
[k | (_, k) <- HashMap.keys values, k /= Key GhcSessionIO]
201210
++ [Key GhcSessionIO]
202-
measureMemory argsLogger [keys] consoleObserver valuesRef
211+
measureMemory logger [keys] consoleObserver valuesRef
203212

204213
unless (null failed) (exitWith $ ExitFailure (length failed))
205214
{-# ANN defaultMain ("HLint: ignore Use nubOrd" :: String) #-}

src/Ide/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ runLspMode lspArgs@LspArguments{..} idePlugins = do
9494
Main.defaultMain def
9595
{ Main.argFiles = if argLSP then Nothing else Just []
9696
, Main.argsHlsPlugins = idePlugins
97-
, Main.argsLogger = hlsLogger
97+
, Main.argsLogger = pure hlsLogger
9898
, Main.argsIdeOptions = \_config sessionLoader ->
9999
let defOptions = Ghcide.defaultIdeOptions sessionLoader
100100
in defOptions

0 commit comments

Comments
 (0)