Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[CO-357] Re-emit: Fix 'overrideConsoleLog'
Browse files Browse the repository at this point in the history
This was done in 7c59b1a but
then overriden by a wrong merge-conflict resolution in f337564bf2743258dca7074867253d8f.

This commits re-applies the patch on top of the new changes.
Note that it turns out the  'Semigroup' instance for 'LoggerTree'
was broken :/ (being left-associative instead of right-associative).
  • Loading branch information
KtorZ committed Sep 21, 2018
1 parent 34337f5 commit daf029e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/src/Pos/Launcher/Resource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ import Pos.Launcher.Mode (InitMode, InitModeContext (..), runInitMode)
import Pos.Launcher.Param (BaseParams (..), LoggingParams (..),
NodeParams (..))
import Pos.Util (bracketWithLogging, newInitFuture)
import Pos.Util.Log.LoggerConfig (defaultInteractiveConfiguration)
import Pos.Util.Log.LoggerConfig (defaultInteractiveConfiguration,
isWritingToConsole, lcLoggerTree, ltHandlers)
import Pos.Util.Wlog (LoggerConfig (..), Severity (..), WithLogger,
logDebug, logInfo, parseLoggerConfig, removeAllHandlers,
setupLogging)
Expand Down Expand Up @@ -243,9 +244,9 @@ getRealLoggerConfig LoggingParams{..} = do
overrideConsoleLog :: LoggerConfig -> LoggerConfig
overrideConsoleLog = case lpConsoleLog of
Nothing -> identity
Just True -> (<>) (defaultInteractiveConfiguration Info)
Just True -> (<> defaultInteractiveConfiguration Info)
-- add output to the console with severity filter >= Info
Just False -> identity
Just False -> lcLoggerTree . ltHandlers %~ filter (not . isWritingToConsole)

setupLoggers :: MonadIO m => Text -> LoggingParams -> m ()
setupLoggers cfoKey params = setupLogging cfoKey =<< getRealLoggerConfig params
Expand Down
9 changes: 8 additions & 1 deletion util/src/Pos/Util/Log/LoggerConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module Pos.Util.Log.LoggerConfig
, parseLoggerConfig
, retrieveLogFiles
, setLogPrefix
, isWritingToConsole
) where

import Data.Yaml as Y
Expand Down Expand Up @@ -124,6 +125,12 @@ filterKnowns = HM.filterWithKey (\k _ -> k `notElem` known)
where
known = ["file","files","severity","handlers"]


isWritingToConsole :: LogHandler -> Bool
isWritingToConsole lh =
_lhBackend lh `elem` [StderrBE, StdoutBE]


-- | @'LoggerTree'@ contains the actual logging configuration,
-- 'Severity' and 'LogHandler'
data LoggerTree = LoggerTree
Expand Down Expand Up @@ -171,7 +178,7 @@ mkUniq handlers = mkUniq' handlers []
any (\lh' -> _lhName lh == _lhName lh') lhs
mkUniq' [] acc = acc
mkUniq' (lh:lhs) acc | lh `containedIn` acc = mkUniq' lhs acc
| otherwise = mkUniq' lhs (lh:acc)
| otherwise = mkUniq' lhs (acc ++ [lh])

instance Semigroup LoggerTree where
lt1 <> lt2 = LoggerTree {
Expand Down

0 comments on commit daf029e

Please sign in to comment.