Сryptocurrency development analysis

Description

This PR introduces `katip` as the new logging library, a framework for structured logging (JSON structures). In a first step, we bring in this new library and clean all code from references to the old one. Unfortunately, this translates to changes all over the codebase.

* introduce `katip` library for logging
* provide compatible interface
* logging in IO with `Trace`

replaces PR #3358 which replaced PR #3332

### notes to reviewers

The order of the commits follows the modules’ dependencies.
Start with ‘util’ where new logging is implemented. This is also the home of `Trace` (by AVieth).
All other modules can be reviewed independently (aka «in parallel»).

### notes on `Trace`

Trace has been introduced by @avieth in `networking` first. It is very handy in that we pass around a `Trace` argument that eventually will `contramap` to the underlying logging. It also allows to stack names to the context using `appendName`, which only affects downstream Trace invocations and is reset after the function returns.
In tests, a simple `noTrace` is passed in as a Trace to inhibit logging.

### notes on `CanJsonLog`

This is a complete implementation of event logging to JSON structures. We will come up with a refactored implementation that is using the new logging and thus should be simpler to maintain. This is not part of this PR. Some parts to the current JSON logging have been commented out, and will be reenabled in a second PR.

## Open issues

to be introduced in subsequent PRs.

* log rotation (CBR-211)
* reenabling logging (CBR-345)
* replace `CanJsonLog` (CBR-321)
* logger tree severity filter (CBR-348)
* from WriterT to StateT (CBR-357)
* remove compatibility layer `CanLog` (CBR-361)

## Linked issues

[CBR-97] U/S
[CBR-207] introduce katip
[CBR-208] rewriting Pos.Util.Log.LogSafe
[CBR-209] ‘katip’ scribe for JSON logging
[CBR-213] logging in IO — Pos.Util.Trace
[CBR-271] logging configuration parser
[CBR-274] tests for Pos.Util.Log (and Trace)
[CBR-345] cleanup

## Type of change

— [ ] 🐞 Bug fix (non-breaking change which fixes an issue)
— [x] 🛠 New feature (non-breaking change which adds functionality)
— [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
— [x] 🏭 Refactoring that does not change existing functionality but does improve things like code readability, structure etc
— [x] 🔨 New or improved tests for existing code
— [ ] ⛑ git-flow chore (backport, hotfix, etc)

## Developer checklist

— [x] I have read the [style guide](https://github.com/input-output-hk/cardano-sl/blob/develop/docs/style-guide.md) document, and my code follows the code style of this project.
— [x] If my code deals with exceptions, it follows the [guidelines](https://github.com/input-output-hk/cardano-sl/blob/develop/docs/exceptions.md).
— [x] I have updated any documentation accordingly, if needed. Documentation changes can be reflected in opening a PR on [cardanodocs.com](https://github.com/input-output-hk/cardanodocs.com), amending the inline [Haddock](https://www.haskell.org/haddock/) comments, any relevant README file or one of the document listed in the [docs](https://github.com/input-output-hk/cardano-sl/tree/develop/docs) directory.

## Testing checklist

— [x] I have added tests to cover my changes.
— [x] All new and existing tests passed.

## QA Steps

«`
stack build
stack test
«`

or in a module, e.g. ‘networking’: `stack build cardano-sl-networking`

## Screenshots (if available)

You can view, comment on, or merge this pull request online at:

https://github.com/input-output-hk/cardano-sl/pull/3401

— Commit Summary —

* [CBR-97] logging implementation based on ‘katip’
* [CBR-97] module ‘binary’ adapted to new logging
* [CBR-97] module ‘crypto’ adapted to new logging
* [CBR-97] module ‘core’ adapted to new logging
* [CBR-97] module ‘chain’ adapted to new logging
* [CBR-97] module ‘db’ adapted to new logging
* [CBR-97] module ‘networking’ adapted to new logging
* [CBR-97] module ‘infra’ adapted to new logging
* [CBR-97] module ‘node-ipc’ adapted to new logging
* [CBR-97] module ‘lib’ adapted to new logging
* [CBR-97] module ‘node’ adapted to new logging
* [CBR-97] module ‘client’ adapted to new logging
* [CBR-97] module ‘generator’ adapted to new logging
* [CBR-97] module ‘auxx’ adapted to new logging
* [CBR-97] module ‘explorer’ adapted to new logging
* [CBR-97] module ‘wallet’ adapted to new logging
* [CBR-97] module ‘wallet-new’ adapted to new logging
* [CBR-97] module ‘tools’ adapted to new logging
* [CBR-345] cleanup and adaptation
* [CBR-345] benchmark and wallet-integration-test adapted to new logging

— File Changes —

M .gitignore (1)
M auxx/Main.hs (72)
M auxx/cardano-sl-auxx.cabal (7)
M auxx/src/Command/BlockGen.hs (18)
M auxx/src/Command/Proc.hs (34)
M auxx/src/Command/Rollback.hs (22)
M auxx/src/Command/Tx.hs (47)
M auxx/src/Command/Update.hs (49)
M auxx/src/Mode.hs (31)
M auxx/src/Plugin.hs (45)
M binary/cardano-sl-binary.cabal (5)
M binary/test/cardano-sl-binary-test.cabal (5)
M chain/cardano-sl-chain.cabal (7)
M chain/src/Pos/Chain/Ssc/Mem.hs (56)
M chain/src/Pos/Chain/Ssc/Shares.hs (34)
M chain/src/Pos/Chain/Ssc/Toss/Base.hs (25)
M chain/src/Pos/Chain/Ssc/Toss/Class.hs (3)
M chain/src/Pos/Chain/Ssc/Toss/Logic.hs (40)
M chain/src/Pos/Chain/Ssc/Toss/Pure.hs (63)
M chain/src/Pos/Chain/Txp/Toil/Monad.hs (17)
M chain/src/Pos/Chain/Txp/Toil/Stakes.hs (5)
M chain/src/Pos/Chain/Update/Poll/Class.hs (29)
M chain/test/cardano-sl-chain-test.cabal (5)
M client/cardano-sl-client.cabal (6)
M client/src/Pos/Client/KeyStorage.hs (18)
M client/src/Pos/Client/Txp/History.hs (9)
M client/src/Pos/Client/Txp/Network.hs (14)
M client/src/Pos/Client/Txp/Util.hs (2)
M client/src/Pos/Client/Update/Network.hs (18)
M core/cardano-sl-core.cabal (34)
M core/src/Pos/Core/Common/Address.hs (6)
M core/src/Pos/Core/Conc.hs (10)
M core/src/Pos/Core/Exception.hs (21)
M core/src/Pos/Core/JsonLog/CanJsonLog.hs (13)
M core/src/Pos/Core/JsonLog/JsonLogT.hs (32)
M core/src/Pos/Core/JsonLog/LogEvents.hs (4)
M core/src/Pos/Core/Reporting/Metrics.hs (13)
M core/src/Pos/Core/Slotting/SlotId.hs (24)
M core/src/Pos/Core/Util/LogSafe.hs (279)
M core/src/Pos/Core/Util/TimeLimit.hs (52)
M crypto/cardano-sl-crypto.cabal (5)
M crypto/test/cardano-sl-crypto-test.cabal (5)
M db/cardano-sl-db.cabal (8)
M db/src/Pos/DB/Block/BListener.hs (21)
M db/src/Pos/DB/Block/GState/SanityCheck.hs (16)
M db/src/Pos/DB/Block/Logic/Creation.hs (119)
M db/src/Pos/DB/Block/Logic/Header.hs (17)
M db/src/Pos/DB/Block/Logic/Internal.hs (67)
M db/src/Pos/DB/Block/Logic/Util.hs (14)
M db/src/Pos/DB/Block/Logic/VAR.hs (94)
M db/src/Pos/DB/Block/Lrc.hs (81)
M db/src/Pos/DB/Block/Slog/Logic.hs (26)
M db/src/Pos/DB/Delegation/Logic/VAR.hs (29)
M db/src/Pos/DB/GState/Lock.hs (35)
M db/src/Pos/DB/Lrc/Context.hs (15)
M db/src/Pos/DB/Lrc/Mode.hs (4)
M db/src/Pos/DB/Ssc/Logic/Global.hs (10)
M db/src/Pos/DB/Ssc/Logic/Local.hs (123)
M db/src/Pos/DB/Ssc/Logic/VAR.hs (103)
M db/src/Pos/DB/Ssc/State.hs (12)
M db/src/Pos/DB/Ssc/State/Global.hs (14)
M db/src/Pos/DB/Txp/Logic/Global.hs (15)
M db/src/Pos/DB/Txp/Logic/Local.hs (74)
M db/src/Pos/DB/Txp/MemState/Class.hs (17)
M db/src/Pos/DB/Txp/MemState/Metrics.hs (13)
M db/src/Pos/DB/Txp/Settings.hs (18)
M db/src/Pos/DB/Txp/Stakes.hs (11)
M db/src/Pos/DB/Txp/Utxo.hs (11)
M db/src/Pos/DB/Update/GState.hs (6)
M db/src/Pos/DB/Update/Logic/Global.hs (67)
M db/src/Pos/DB/Update/Logic/Local.hs (92)
M db/src/Pos/DB/Update/Poll/DBPoll.hs (2)
M db/src/Pos/DB/Update/Poll/Logic/Apply.hs (99)
M db/src/Pos/DB/Update/Poll/Logic/Base.hs (25)
M db/src/Pos/DB/Update/Poll/Logic/Normalize.hs (71)
M db/src/Pos/DB/Update/Poll/Logic/Rollback.hs (9)
M db/src/Pos/DB/Update/Poll/Logic/Softfork.hs (36)
M db/src/Pos/DB/Update/Poll/Pure.hs (34)
M db/test/cardano-sl-db-test.cabal (3)
M explorer/cardano-sl-explorer.cabal (6)
M explorer/src/Pos/Explorer/BListener.hs (24)
M explorer/src/Pos/Explorer/DB.hs (12)
M explorer/src/Pos/Explorer/ExplorerMode.hs (21)
M explorer/src/Pos/Explorer/Socket/App.hs (102)
M explorer/src/Pos/Explorer/Socket/Holder.hs (11)
M explorer/src/Pos/Explorer/Socket/Methods.hs (126)
M explorer/src/Pos/Explorer/Socket/Util.hs (16)
M explorer/src/Pos/Explorer/Txp/Global.hs (41)
M explorer/src/Pos/Explorer/Txp/Local.hs (33)
M explorer/src/Pos/Explorer/Txp/Toil/Logic.hs (48)
M explorer/src/Pos/Explorer/Txp/Toil/Monad.hs (9)
M explorer/src/Pos/Explorer/Web/Server.hs (53)
M explorer/src/Pos/Explorer/Web/Transform.hs (23)
M explorer/src/explorer/Main.hs (52)
M explorer/test/Test/Pos/Explorer/MockFactory.hs (7)
M explorer/test/Test/Pos/Explorer/Socket/AppSpec.hs (3)
M explorer/test/Test/Pos/Explorer/Socket/MethodsSpec.hs (35)
M generator/app/VerificationBench.hs (66)
M generator/bench/Bench/Pos/Criterion/Block/Logic.hs (22)
M generator/cardano-sl-generator.cabal (8)
M generator/src/Pos/Generator/Block/Logic.hs (39)
M generator/src/Pos/Generator/Block/Mode.hs (20)
M generator/src/Pos/Generator/Block/Payload.hs (3)
M generator/src/Pos/Generator/BlockEvent.hs (32)
M generator/src/Pos/Generator/BlockEvent/DSL.hs (10)
M generator/src/Test/Pos/Block/Logic/Emulation.hs (4)
M generator/src/Test/Pos/Block/Logic/Event.hs (5)
M generator/src/Test/Pos/Block/Logic/Mode.hs (48)
M generator/src/Test/Pos/Block/Logic/Util.hs (20)
M generator/test/Test/Pos/Binary/CommunicationSpec.hs (11)
M generator/test/Test/Pos/Block/Logic/VarSpec.hs (18)
M generator/test/Test/Pos/Generator/Block/LrcSpec.hs (22)
M infra/cardano-sl-infra.cabal (12)
M infra/src/Pos/Infra/Communication/Listener.hs (4)
M infra/src/Pos/Infra/Communication/Protocol.hs (18)
M infra/src/Pos/Infra/Communication/Relay/Logic.hs (85)
M infra/src/Pos/Infra/DHT/Real/Real.hs (43)
M infra/src/Pos/Infra/DHT/Workers.hs (22)
M infra/src/Pos/Infra/Diffusion/Subscription/Common.hs (44)
M infra/src/Pos/Infra/Diffusion/Subscription/Dht.hs (11)
M infra/src/Pos/Infra/Diffusion/Subscription/Dns.hs (32)
M infra/src/Pos/Infra/Diffusion/Transport/TCP.hs (10)
M infra/src/Pos/Infra/Network/CLI.hs (67)
M infra/src/Pos/Infra/Network/Types.hs (9)
M infra/src/Pos/Infra/Recovery/Info.hs (13)
M infra/src/Pos/Infra/Reporting.hs (1)
M infra/src/Pos/Infra/Reporting/Http.hs (29)
R infra/src/Pos/Infra/Reporting/Logfiles.hs (47)
M infra/src/Pos/Infra/Reporting/Methods.hs (17)
M infra/src/Pos/Infra/Shutdown/Logic.hs (11)
M infra/src/Pos/Infra/Slotting/Util.hs (61)
D infra/src/Pos/Infra/StateLock.hs (5)
D infra/src/Pos/Infra/Util/LogSafe.hs (5)
M infra/test/cardano-sl-infra-test.cabal (3)
M lib/bench/Bench/Pos/Diffusion/BlockDownload.hs (19)
M lib/cardano-sl.cabal (7)
M lib/configuration.yaml (39)
M lib/src/Pos/Client/CLI/NodeOptions.hs (2)
M lib/src/Pos/Client/CLI/Params.hs (8)
M lib/src/Pos/Client/CLI/Secrets.hs (38)
M lib/src/Pos/Client/CLI/Util.hs (35)
M lib/src/Pos/Communication/Server.hs (2)
M lib/src/Pos/Context/Context.hs (9)
M lib/src/Pos/Diffusion/Full.hs (23)
M lib/src/Pos/Diffusion/Full/Block.hs (116)
M lib/src/Pos/Diffusion/Full/Delegation.hs (6)
M lib/src/Pos/Diffusion/Full/Ssc.hs (4)
M lib/src/Pos/Diffusion/Full/Txp.hs (6)
M lib/src/Pos/Diffusion/Full/Update.hs (8)
M lib/src/Pos/GState/Context.hs (7)
M lib/src/Pos/Launcher/Configuration.hs (21)
M lib/src/Pos/Launcher/Launcher.hs (13)
M lib/src/Pos/Launcher/Param.hs (4)
M lib/src/Pos/Launcher/Resource.hs (170)
M lib/src/Pos/Launcher/Runner.hs (44)
M lib/src/Pos/Launcher/Scenario.hs (49)
M lib/src/Pos/Listener/Delegation.hs (22)
M lib/src/Pos/Listener/Txp.hs (24)
M lib/src/Pos/Listener/Update.hs (48)
M lib/src/Pos/Logic/Full.hs (42)
M lib/src/Pos/Network/Block/Logic.hs (143)
M lib/src/Pos/Network/Block/Retrieval.hs (105)
M lib/src/Pos/Network/Block/WorkMode.hs (7)
M lib/src/Pos/Network/Update/Download.hs (69)
M lib/src/Pos/Reporting/Production.hs (9)
M lib/src/Pos/Util/Servant.hs (78)
M lib/src/Pos/Util/UserSecret.hs (57)
M lib/src/Pos/WorkMode.hs (31)
M lib/src/Pos/WorkMode/Class.hs (8)
M lib/src/Pos/Worker.hs (18)
M lib/src/Pos/Worker/Block.hs (169)
M lib/src/Pos/Worker/Delegation.hs (19)
M lib/src/Pos/Worker/Ssc.hs (160)
M lib/src/Pos/Worker/Update.hs (49)
M lib/test/Test/Pos/Diffusion/BlockSpec.hs (10)
M lib/test/Test/Pos/Launcher/ConfigurationSpec.hs (4)
M lib/test/Test/Pos/Ssc/Toss/BaseSpec.hs (13)
M lib/test/Test/Pos/Ssc/VssCertDataSpec.hs (3)
M lib/test/Test/Pos/Update/PollSpec.hs (3)
M networking/bench/LogReader/Main.hs (19)
M networking/bench/Receiver/Main.hs (30)
M networking/bench/Sender/Main.hs (29)
M networking/bench/launch.sh (2)
M networking/cardano-sl-networking.cabal (5)
M networking/examples/Discovery.hs (17)
M networking/examples/PingPong.hs (17)
M networking/src/Bench/Network/Commons.hs (35)
M networking/src/Network/Broadcast/OutboundQueue.hs (31)
M networking/src/Network/Broadcast/OutboundQueue/Demo.hs (120)
M networking/src/Node.hs (17)
M networking/src/Node/Internal.hs (67)
M networking/src/Ntp/Client.hs (101)
M networking/src/Ntp/Util.hs (68)
M networking/test/Test/Network/Broadcast/OutboundQueueSpec.hs (18)
M networking/test/Test/NodeSpec.hs (23)
M networking/test/Test/NtpSpec.hs (2)
M networking/test/Test/Util.hs (10)
M node-ipc/cardano-sl-node-ipc.cabal (8)
M node-ipc/src/Cardano/NodeIPC.hs (100)
M node/Main.hs (47)
M node/cardano-sl-node.cabal (6)
M pkgs/default.nix (194)
M scripts/bench/runbench.sh (3)
M scripts/common-functions.sh (16)
M scripts/launch/demo-cluster/default.nix (12)
M scripts/test/wallet/integration/default.nix (5)
M stack.yaml (10)
M tools/cardano-sl-tools.cabal (11)
M tools/src/Pos/Tools/Dbgen/Lib.hs (77)
M tools/src/blockchain-analyser/Main.hs (13)
M tools/src/dbgen/Main.hs (32)
M tools/src/keygen/Dump.hs (77)
M tools/src/keygen/Main.hs (93)
M tools/src/launcher/Main.hs (265)
M tools/src/post-mortem/Main.hs (131)
M util/Pos/Util.hs (16)
A util/Pos/Util/Log.hs (232)
A util/Pos/Util/Log/Internal.hs (100)
A util/Pos/Util/Log/LogSafe.hs (0)
A util/Pos/Util/Log/Scribes.hs (0)
A util/Pos/Util/Log/Severity.hs (0)
A util/Pos/Util/LoggerConfig.hs (0)
M util/Pos/Util/LoggerName.hs (0)
M util/Pos/Util/Orphans.hs (0)
M util/Pos/Util/Trace.hs (0)
A util/Pos/Util/Trace/Named.hs (0)
A util/Pos/Util/Trace/Unstructured.hs (0)
A util/Pos/Util/Trace/Writer.hs (0)
M util/Pos/Util/Util.hs (0)
M util/README.md (0)
M util/cardano-sl-util.cabal (0)
A util/test/Test/Pos/Util/LogSpec.hs (0)
A util/test/Test/Pos/Util/TraceSpec.hs (0)
M util/test/cardano-sl-util-test.cabal (0)
M wallet-new/cardano-sl-wallet-new.cabal (0)
M wallet-new/server/Main.hs (0)
M wallet-new/src/Cardano/Wallet/API/Internal/Handlers.hs (0)
M wallet-new/src/Cardano/Wallet/API/Request.hs (0)
M wallet-new/src/Cardano/Wallet/API/Request/Filter.hs (0)
M wallet-new/src/Cardano/Wallet/API/Request/Sort.hs (0)
M wallet-new/src/Cardano/Wallet/API/V0/Handlers.hs (0)
M wallet-new/src/Cardano/Wallet/API/V1/LegacyHandlers.hs (0)
M wallet-new/src/Cardano/Wallet/API/V1/LegacyHandlers/Accounts.hs (0)
M wallet-new

Добавить комментарий