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

Commit 5509fed

Browse files
authored
Merge pull request #3697 from input-output-hk/KtorZ/CO-409/fix-withConfigurations-logging
[CO-409] Fix `withConfigurations` usage of `WithLogger` ==> Allow pure logger to be used.
2 parents 336e531 + 06938a4 commit 5509fed

File tree

5 files changed

+23
-41
lines changed

5 files changed

+23
-41
lines changed

generator/app/VerificationBench.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import Pos.Generator.Block (BlockGenParams (..), TxGenParams (..),
3838
genBlocks)
3939
import Pos.Launcher.Configuration (ConfigurationOptions (..),
4040
HasConfigurations, defaultConfigurationOptions,
41-
withConfigurationsM)
41+
withConfigurations)
4242
import Pos.Util.CompileInfo (withCompileInfo)
4343
import Pos.Util.Log.LoggerConfig (defaultInteractiveConfiguration)
4444
import Pos.Util.Util (realTime)
@@ -183,7 +183,7 @@ readBlocks path = do
183183

184184
main :: IO ()
185185
main = do
186-
setupLogging "generator" loggerConfig
186+
setupLogging "verification-bench" loggerConfig
187187
args <- Opts.execParser
188188
$ Opts.info
189189
(benchArgsParser <**> Opts.helper)
@@ -198,7 +198,7 @@ main = do
198198
, cfoSystemStart = Just (Timestamp startTime)
199199
}
200200
withCompileInfo $
201-
withConfigurationsM "verification-bench" Nothing Nothing False cfo $ \ !genesisConfig !_ !txpConfig !_ -> do
201+
withConfigurations Nothing Nothing False cfo $ \ !genesisConfig !_ !txpConfig !_ -> do
202202
let genesisConfig' = genesisConfig
203203
{ configProtocolConstants =
204204
(configProtocolConstants genesisConfig) { pcK = baK args }

generator/bench/Bench/Pos/Criterion/Block/Logic.hs

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ import Pos.Generator.Block (BlockGenParams (..), TxGenParams (..),
3838
genBlockNoApply, genBlocks, mkBlockGenContext)
3939
import Pos.Launcher.Configuration (ConfigurationOptions (..),
4040
HasConfigurations, defaultConfigurationOptions,
41-
withConfigurationsM)
41+
withConfigurations)
4242
import Pos.Util.CompileInfo (withCompileInfo)
43+
import Pos.Util.Log.LoggerConfig (defaultInteractiveConfiguration)
4344
import Pos.Util.Util (realTime)
45+
import Pos.Util.Wlog (Severity (Debug), setupLogging)
4446

4547
import Test.Pos.Block.Logic.Emulation (runEmulation, sudoLiftIO)
4648
import Test.Pos.Block.Logic.Mode (BlockTestContext, BlockTestMode,
@@ -220,14 +222,16 @@ verifyHeaderBenchmark !genesisConfig !secretKeys !tp = env (runBlockTestMode gen
220222

221223
runBenchmark :: IO ()
222224
runBenchmark = do
225+
let loggerConfig = defaultInteractiveConfiguration Debug
226+
setupLogging "verifyBenchmark" loggerConfig
223227
startTime <- realTime
224228
let cfo = defaultConfigurationOptions
225229
{ cfoFilePath = "../lib/configuration.yaml"
226230
, cfoKey = "bench-validation"
227231
, cfoSystemStart = Just (Timestamp startTime)
228232
}
229233
withCompileInfo
230-
$ withConfigurationsM "verifyBenchmark" Nothing Nothing False cfo
234+
$ withConfigurations Nothing Nothing False cfo
231235
$ \genesisConfig _ txpConfig _ -> do
232236
let tp = TestParams
233237
{ _tpStartTime = Timestamp (convertUnit startTime)

lib/src/Pos/Launcher/Configuration.hs

+7-32
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module Pos.Launcher.Configuration
2323

2424
-- Exposed mostly for testing.
2525
, readAssetLockedSrcAddrs
26-
, withConfigurationsM
2726
) where
2827

2928
import Universum
@@ -53,8 +52,7 @@ import Pos.Core.Conc (currentTime)
5352
import Pos.Core.Slotting (Timestamp (..))
5453
import Pos.Util.AssertMode (inAssertMode)
5554
import Pos.Util.Config (parseYamlConfig)
56-
import Pos.Util.Wlog (LoggerName, WithLogger, askLoggerName, logInfo,
57-
usingLoggerName)
55+
import Pos.Util.Wlog (WithLogger, logInfo)
5856

5957
import Pos.Chain.Block
6058
import Pos.Chain.Delegation
@@ -174,17 +172,16 @@ instance Default ConfigurationOptions where
174172

175173
-- | Parse some big yaml file to 'MultiConfiguration' and then use the
176174
-- configuration at a given key.
177-
withConfigurationsM
178-
:: forall m r. (MonadThrow m, MonadIO m)
179-
=> LoggerName
180-
-> Maybe AssetLockPath
175+
withConfigurations
176+
:: (WithLogger m, MonadThrow m, MonadIO m)
177+
=> Maybe AssetLockPath
181178
-> Maybe FilePath
182179
-> Bool
183180
-> ConfigurationOptions
184181
-> (HasConfigurations => Genesis.Config -> WalletConfiguration -> TxpConfiguration -> NtpConfiguration -> m r)
185182
-> m r
186-
withConfigurationsM logName mAssetLockPath dumpGenesisPath dumpConfig cfo act = do
187-
logInfo' ("using configurations: " <> show cfo)
183+
withConfigurations mAssetLockPath dumpGenesisPath dumpConfig cfo act = do
184+
logInfo ("using configurations: " <> show cfo)
188185
cfg <- parseYamlConfig (cfoFilePath cfo) (cfoKey cfo)
189186
assetLock <- case mAssetLockPath of
190187
Nothing -> pure mempty
@@ -201,7 +198,7 @@ withConfigurationsM logName mAssetLockPath dumpGenesisPath dumpConfig cfo act =
201198
withBlockConfiguration (ccBlock cfg) $
202199
withNodeConfiguration (ccNode cfg) $ do
203200
let txpConfig = addAssetLock assetLock $ ccTxp cfg
204-
liftIO . usingLoggerName logName $ printInfoOnStart
201+
printInfoOnStart
205202
dumpGenesisPath
206203
dumpConfig
207204
(configGenesisData genesisConfig)
@@ -211,28 +208,6 @@ withConfigurationsM logName mAssetLockPath dumpGenesisPath dumpConfig cfo act =
211208
txpConfig
212209
act genesisConfig (ccWallet cfg) txpConfig (ccNtp cfg)
213210

214-
where
215-
logInfo' :: Text -> m ()
216-
logInfo' = liftIO . usingLoggerName logName . logInfo
217-
218-
withConfigurations
219-
:: (WithLogger m, MonadThrow m, MonadIO m)
220-
=> Maybe AssetLockPath
221-
-> Maybe FilePath
222-
-> Bool
223-
-> ConfigurationOptions
224-
-> (HasConfigurations => Genesis.Config-> WalletConfiguration -> TxpConfiguration -> NtpConfiguration -> m r)
225-
-> m r
226-
withConfigurations mAssetLockPath dumpGenesisPath dumpConfig cfo act = do
227-
loggerName <- askLoggerName
228-
withConfigurationsM
229-
loggerName
230-
mAssetLockPath
231-
dumpGenesisPath
232-
dumpConfig
233-
cfo
234-
act
235-
236211
addAssetLock :: Set Address -> TxpConfiguration -> TxpConfiguration
237212
addAssetLock bset tcfg =
238213
tcfg { tcAssetLockedSrcAddrs = Set.union (tcAssetLockedSrcAddrs tcfg) bset }

lib/test/Test/Pos/Launcher/ConfigurationSpec.hs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import Test.Hspec (Spec, describe, it, shouldSatisfy)
99

1010
import Pos.Core.Slotting (Timestamp (..))
1111
import Pos.Launcher.Configuration (ConfigurationOptions (..),
12-
defaultConfigurationOptions, withConfigurationsM)
12+
defaultConfigurationOptions, withConfigurations)
1313
import Pos.Util.Config (ConfigurationException)
1414
import Pos.Util.Wlog (setupTestLogging)
1515

1616
spec :: Spec
1717
spec = describe "Pos.Launcher.Configuration" $ do
18-
describe "withConfigurationsM" $ do
18+
describe "withConfigurations" $ do
1919
it "should parse `lib/configuration.yaml` file" $ do
20-
liftIO $ setupTestLogging
20+
liftIO setupTestLogging
2121
startTime <- Timestamp . round . (* 1000000) <$> liftIO getPOSIXTime
2222
let cfo = defaultConfigurationOptions
2323
{ cfoFilePath = "./configuration.yaml"
@@ -26,6 +26,6 @@ spec = describe "Pos.Launcher.Configuration" $ do
2626
let catchFn :: ConfigurationException -> IO (Maybe ConfigurationException)
2727
catchFn e = return $ Just e
2828
res <- liftIO $ catch
29-
(withConfigurationsM "test" Nothing Nothing False cfo (\_ _ _ _ -> return Nothing))
29+
(withConfigurations Nothing Nothing False cfo (\_ _ _ _ -> return Nothing))
3030
catchFn
3131
res `shouldSatisfy` isNothing

util/src/Pos/Util/Wlog/Compatibility.hs

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module Pos.Util.Wlog.Compatibility
3232
-- * Named Pure logging
3333
, NamedPureLogger (..)
3434
, launchNamedPureLog
35+
, usingNamedPureLogger
3536
, runNamedPureLog
3637
-- * reimplementations
3738
, removeAllHandlers
@@ -219,6 +220,8 @@ instance Monad m => CanLog (NamedPureLogger m) where
219220
NamedPureLogger $ dispatchMessage name sev msg
220221
instance MFunctor NamedPureLogger where
221222
hoist f = NamedPureLogger . hoist (hoist f) . runNamedPureLogger
223+
instance MonadIO m => MonadIO (NamedPureLogger m) where
224+
liftIO = lift . liftIO
222225

223226
runNamedPureLog
224227
:: (Monad m, HasLoggerName m)

0 commit comments

Comments
 (0)