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

Use the standard LoggerFactory with the ConsoleLoggerProvider #19

Merged
merged 1 commit into from
Feb 28, 2017

Conversation

sgryphon
Copy link
Contributor

I've done a lot of work with diagnostics, and the new .NET Core logging was being used in a slightly non-standard way (it could have been based on early versions/code).

Rather than implement your own ILoggerFactory that creates loggers directly, and your own null logger, generally you use the framework LoggerFactory and configure it with the ILoggerProvider(s) that you want.

If there was/is some grand plan to do your own stuff, then feel free to ignore this; otherwise, this pull request ends up with the same result (a basic console logger) with much less code (removed the two custom classes).

This change:

  • Uses the standard LoggerFactory with the ConsoleLoggerProvider, rather than manually creating loggers. (There is a utility method AddConsole() that does this for you)
  • Remove the custom FuncLoggerFactory.
  • Note the default will already create null loggers (if you have no providers), so that isn't needed either; removed the custom NullLogger.
  • Change the first parameter of the config of the console logger from a func(n,l) => true, to just specify the lowest min level, which is a bit simpler.

… than manually creating loggers. Note the default will already create null loggers, so that isn't needed either. Change the first parameter of the config of the console logger from a func(n,l) => true, to just specify the lowest min level.
@dangershony
Copy link
Contributor

I don't know of any grand plan Nicolas had, however we need to implement logging based on categories.
Specified in the config file will be: "debug=net,db,trx" etc...
From the code it seems the console logger just filters out by trace type ,any suggesting on enhancing the console logger to also filter by categories, or a custom implementation?

@sgryphon
Copy link
Contributor Author

Yes, I've done heaps on diagnostics, so relatively easy to configure by type (including via a configuration file). This current pull request however doesn't change functionality -- it does the same as the current code, just using existing framework classes rather than creating custom ones.

@dangershony
Copy link
Contributor

Gotcha, looks good.

@dangershony dangershony merged commit 1b2d362 into stratisproject:master Feb 28, 2017
@sgryphon
Copy link
Contributor Author

sgryphon commented Feb 28, 2017

Some basics:

  • First of all, each category (ILogger) can have the logging level set; this includes a Default level, system loggers (System, Microsoft), and each of your own loggers.

  • You can also create a hierarchy of loggers, and configure at any level, e.g. "Default" cascades to everything unless overridden, "System" cascades to all System, etc.

  • e.g. You could have loggers like Stratis.Bitcoin.Consensus and then Stratis.Bitcoin.Consensus.CoinViews will inherit.

  • The usual pattern is to use namespace/class names, and these are generated automatically by CreateLogger'T(). Even when you have 10 classes, with 10 loggers, you only need to configure once at the higher level (as they inherit).

Normally the logging is configured via logger=level, but I can add a converter that allows compatibility with core bitcoind parameters (i.e. debug=cat1,cat2,cat3). I will write it up and do another pull request (branched from this one).

@dangershony
Copy link
Contributor

Awesome that would be really great, I guess the categories should coincide with any of the ILoggers in Log.cs (debug=bench,rpc,fullnode, etc), even if its not exactly similar categories to core we can fix this up later if we see fit.

andrasfuchs added a commit to AequitasCoinProject/AequitasFullNode that referenced this pull request Jul 2, 2018
YakupIpek pushed a commit to YakupIpek/StratisBitcoinFullNode that referenced this pull request May 22, 2019
fassadlr pushed a commit that referenced this pull request Jun 19, 2019
* Created FedKeyPairGen console app.

Imported from Changeset 124

* Upgraded SBFN verison in project files.
Imported from Changeset 150

* Moved Payload into feature
Imported from Changeset 154

* Changed 'passphrase' in FedKeyPairGen to 'password'.
Imported from Changeset 198

* Attempt to merge Enigma and EnigmaChain
Imported from Changeset 201

* Updated the solution with the latest Stratis.Bitcoin nuget packages
Imported from Changeset 202

* Removed name, folder and password from the pubkey generation as  they are not required.

The console app will simply show the user their mnemonic and the pubkey they need to share.

* Removed mine premine stuff and added it to the FedKeyPairGen console app for now.

* Remove custom env mockup helpers (#5)

* created Apex definition

* first bit of cleaning, all the mockup helpers have been removed as no special logic is needed to handle sidechains, they are just another network. Need to add back randomised API port attribution. Need to fix getCoinDetails test if it is being used by anyone (UI ?). The powershell command projects have been removed as they were only here to generate json files that have disappeared.

* delete unused projects

* Bring back FindPorts methods to later find a way to use it

* Fix to get different API ports when creating multiple connected nodes on localhost, fix to GetCoinDetails, a bit basic for the moment, but we'll see how the code evolved

* Put explanatory name on the Class in FederatedSidechains.Tests.Common

* this doesn't work, somehow the constructor is called twice, and once with a null nodesettings, I need to investigate

* Changes after PR comments

* more merge changes ...

* fix get-coindetails logic

* Removed placeholder project and wrongly copied MainchainGeneratorService

* consolidate .Net Sdk

* added code to generate multisig in FedKeyPairGen (#8)

* Jeremy's PR 14 reproduced with pr5 changes in (#15)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* Add new network properties to Apex

* Update ApexNetwork.cs

* Update ApexNetwork.cs

* Networks project addition (#16)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* added CoinbaseMaturity, PremineReward, pow reward, pos reward and max reorg for the apex network.

* new project for ApexNetwork

* remove APexD dependency in IntegrationTest

* remove mainchainD and renamed apex to sidechainD (#19)

OK

* Nuget update (#21)

* updated nuget packages

* Replced ApiPort by GetApiPort from the FN

* create custom node without asking for free api

* added maxMoney and coinTicker

* Networkz (#22)

* using Apex throughout solution

* removed unused assert method in Networks

* remove left behind

* remove extra space

* Moved the FederatedPeg project into the FederationGateway project (#36)

* Upgrade 1.1.11 to 1.1.12 (#42)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* added CoinbaseMaturity, PremineReward, pow reward, pos reward and max reorg for the apex network.

* Add new network properties to Apex

* Update ApexNetwork.cs

* Update ApexNetwork.cs

* upgrade nuget packages

* updated nuget packages (#48)

* upgrade to dotnetcore 2.1, tests as libraries (#98)

well done mate, that is awesome

* Upgrade to fullnode 1.2.1 beta (#110)

* Upgrade NBitcoin and as little dependencies as possible

* Consolidate Stratis.Bitcoin

* Upgrade all other Stratis and external packages

* Trying to resolve genesis hash discrepancies in Apex

* make sure all projects are in full debug mode, needed for code coverage analysis (#127)

* upgrades libraries (#144)

* upgrades to
Stratis.Bitcoin.* 1.2.3-beta
NStratis 4.0.0.67
Microsoft.NET.Test.Sdk 15.9.0
Xunit 2.4.1

That meant removing unused Integration test project which used corrupted Stratis.Bitcoin.IntegrationTests.Common temporarily

* upgrade stratis packages to 1.2.4 and FluentAssertions to 5.5.3 (#181)

* Adding a POA federated peg network (#182)

* Adding a POA federated peg network
Currently no smart contract packages so I have commented out the SC specifics ...

* trying to get rid of Apex references

* refactor network selector usaage
I don't think we need 2 classes for that

* no more need to instantiate a network to get its name

* changes post review

* Change Magic, Cointype and targetSpacingSeconds

* add a "test" to run the different tools from within VisualStudio (#187)

* add a "test" to run the different tools from within VisualStudio

* Clear white spaces.

* Federation Setup Console. (#189)

* Add GenesisMiner and MultisigAddressCreator to console.

Renamed console.

* Changes after PR review.

Changed switch values.

Allow end user to select network.

Allow end user to select quorum.

* Quorum and Fed member argument validation.

* Console OutputUsage update.

* Reduced commandLineArgs in debug from 6 fed addresses down to 5.

Removed actual keys from FederationSetup.OutputUsage().

MultisigAddressCreator now takes fed pubkeys from argument list not hard wired as before.

Generating Fed pubkeys creates two lots.  One for transfer of funds to sidechain and the other for sidechain mining.

* Removed ReadLine() switch check.

* Stratis packages upgrade 1.2.4 to 1.2.5 (#193)

* Add locks and check that the federated wallet manager dealt with any forks (#202)

* Add locks and check fedwalletmanager during forks

* Reformat and reduce whitespace

* Add missing waits

* Back off if errors when send to counter node

* Optimize performance by batching block data

* Avoid large re-orgs

* Add transaction serialization workaround to Initialize method

* Upgrade packages

* Adapted the console app to have a menu (#216)

Changed the console app to have a menu rather than being a command line tool.
The reason for that is that this utility is to be used by federation members and this change makes that easier.
Also changed it so that it loops until the user exits

![image](https://user-images.githubusercontent.com/1867877/49459731-a276c980-f7e7-11e8-8db3-2e8ce39ec441.png)

* Federation Setup tool - small improvements (#217)

* Made Network non-optional
Added text option to genesis block

* Generate pubkeys properly, with file for migning priv key

* Setup of  FederatedPegTest (#221)

* Use SmartContractPoAConsensusFactory for genesis block generation

* No genesis reward for sidechains

* Find (real) Genesis Block for FederatedPegTest

* Increase Console input limit

* Use RegTest for the local sidechain network

* Add mining FedPubKeys and additional network fields

* updtae to ports to be like Stratis+1

* Update FederatedPegTest.cs

* premine reward back to 20 000 000

* Update FederatedPegTest.cs

* upgrade fullnode from 1.2.6 to 1.2.7 (#236)

* upgrade to release version of FullNode (#238)

* upgrade to release version of FullNode
1.2.6-beta => 3.0.0.0
4.0.0.70 => 4.0.0.71

* remove stratis-dev nuget source

* just to trigger a rebuild

* Fixing codestyle issues (#253)

* refactoring

* edits

* var for simple types

* private and readonly

* access modifiers

* access modifier

* fix codestyle violations part 2 (#256)

* package upgrade to 3.0.0.0 to 3.0.0.1 (#257)

* package upgrade to 3.0.0.0 to 3.0.0.1
add --no-build back to the script

* fix FederatedPegBlockDefinition constructor

* Refactored federation setup tool and added menue option to generate powershell script (#286)

* Upgrade stratis nuget packages (#292)

* NuGet update and Dbreeze serialization fix (#309)

Allows the sidechains repo to serialize everything given the changes to the FN Dbreeze serialization and ultimately allows multiple nodes to run in the one process by removing static dependencies.

I haven't actually connected to the network and completed a transfer yet - if someone could do that it would be ace.

* add a arg for passphrase for multisig key derivation (#328)

* add a arg for passphrase for multisig key derivation

* place the passphrase correctly in the do not share section

* FedPegMain definition (#343)

* Moved coinbase text out of the CreateGenesis method

* removed some unused variables

* Brought the name and cointicker of the networks inline with the definition of the networks

* Brought some more network data for Main inline

* Upgrade # of coins to 100M

* Create new genesis block for Main

* updated to SBFN 3.0.0.4 beta (#355)

* WPF Federation Key Generation App (#379)

* Initial commit for fed setup GUI wizard in WPF Blend

* POC for creating the keys with WPF and making sure we can have nugets working

* Changes to FedKeyPairGen/Program.cs to allow to run it from command line
Added Stratis logo on the top of the window and Statis icon

* Add splash screen
Add center window on startup

* Added datadir argument to FederationSetup
Removed redundent files from FederationApp

* Changes to GUI to adopt it to consultancy website

* First working version

* Updated to displayed text, initial working version candidate

* Added handling for pass phrase

* Fixed name on the folder label

* Removed POC projects

* Removed unused left over build references for Xamarin

* Updated FederationSetup.cs with help text for new args
Cleaned up Program.cs and fixed exit SwitchCommand

* Folders restructured

* References fixed

* Network values are updated.

* Coinbase text updated.

* Skipped tests removed.
fassadlr pushed a commit that referenced this pull request Jun 21, 2019
* Created FedKeyPairGen console app.

Imported from Changeset 124

* Upgraded SBFN verison in project files.
Imported from Changeset 150

* Moved Payload into feature
Imported from Changeset 154

* Changed 'passphrase' in FedKeyPairGen to 'password'.
Imported from Changeset 198

* Attempt to merge Enigma and EnigmaChain
Imported from Changeset 201

* Updated the solution with the latest Stratis.Bitcoin nuget packages
Imported from Changeset 202

* Removed name, folder and password from the pubkey generation as  they are not required.

The console app will simply show the user their mnemonic and the pubkey they need to share.

* Removed mine premine stuff and added it to the FedKeyPairGen console app for now.

* Remove custom env mockup helpers (#5)

* created Apex definition

* first bit of cleaning, all the mockup helpers have been removed as no special logic is needed to handle sidechains, they are just another network. Need to add back randomised API port attribution. Need to fix getCoinDetails test if it is being used by anyone (UI ?). The powershell command projects have been removed as they were only here to generate json files that have disappeared.

* delete unused projects

* Bring back FindPorts methods to later find a way to use it

* Fix to get different API ports when creating multiple connected nodes on localhost, fix to GetCoinDetails, a bit basic for the moment, but we'll see how the code evolved

* Put explanatory name on the Class in FederatedSidechains.Tests.Common

* this doesn't work, somehow the constructor is called twice, and once with a null nodesettings, I need to investigate

* Changes after PR comments

* more merge changes ...

* fix get-coindetails logic

* Removed placeholder project and wrongly copied MainchainGeneratorService

* consolidate .Net Sdk

* added code to generate multisig in FedKeyPairGen (#8)

* Jeremy's PR 14 reproduced with pr5 changes in (#15)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* Add new network properties to Apex

* Update ApexNetwork.cs

* Update ApexNetwork.cs

* Networks project addition (#16)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* added CoinbaseMaturity, PremineReward, pow reward, pos reward and max reorg for the apex network.

* new project for ApexNetwork

* remove APexD dependency in IntegrationTest

* remove mainchainD and renamed apex to sidechainD (#19)

OK

* Nuget update (#21)

* updated nuget packages

* Replced ApiPort by GetApiPort from the FN

* create custom node without asking for free api

* added maxMoney and coinTicker

* Networkz (#22)

* using Apex throughout solution

* removed unused assert method in Networks

* remove left behind

* remove extra space

* Moved the FederatedPeg project into the FederationGateway project (#36)

* Upgrade 1.1.11 to 1.1.12 (#42)

* upgrade nuget 1.1.7 to 1.1.9 and 4.0.0.57 and 4.0.0.58

* add NLog

* added CoinbaseMaturity, PremineReward, pow reward, pos reward and max reorg for the apex network.

* Add new network properties to Apex

* Update ApexNetwork.cs

* Update ApexNetwork.cs

* upgrade nuget packages

* updated nuget packages (#48)

* upgrade to dotnetcore 2.1, tests as libraries (#98)

well done mate, that is awesome

* Upgrade to fullnode 1.2.1 beta (#110)

* Upgrade NBitcoin and as little dependencies as possible

* Consolidate Stratis.Bitcoin

* Upgrade all other Stratis and external packages

* Trying to resolve genesis hash discrepancies in Apex

* make sure all projects are in full debug mode, needed for code coverage analysis (#127)

* upgrades libraries (#144)

* upgrades to
Stratis.Bitcoin.* 1.2.3-beta
NStratis 4.0.0.67
Microsoft.NET.Test.Sdk 15.9.0
Xunit 2.4.1

That meant removing unused Integration test project which used corrupted Stratis.Bitcoin.IntegrationTests.Common temporarily

* upgrade stratis packages to 1.2.4 and FluentAssertions to 5.5.3 (#181)

* Adding a POA federated peg network (#182)

* Adding a POA federated peg network
Currently no smart contract packages so I have commented out the SC specifics ...

* trying to get rid of Apex references

* refactor network selector usaage
I don't think we need 2 classes for that

* no more need to instantiate a network to get its name

* changes post review

* Change Magic, Cointype and targetSpacingSeconds

* add a "test" to run the different tools from within VisualStudio (#187)

* add a "test" to run the different tools from within VisualStudio

* Clear white spaces.

* Federation Setup Console. (#189)

* Add GenesisMiner and MultisigAddressCreator to console.

Renamed console.

* Changes after PR review.

Changed switch values.

Allow end user to select network.

Allow end user to select quorum.

* Quorum and Fed member argument validation.

* Console OutputUsage update.

* Reduced commandLineArgs in debug from 6 fed addresses down to 5.

Removed actual keys from FederationSetup.OutputUsage().

MultisigAddressCreator now takes fed pubkeys from argument list not hard wired as before.

Generating Fed pubkeys creates two lots.  One for transfer of funds to sidechain and the other for sidechain mining.

* Removed ReadLine() switch check.

* Stratis packages upgrade 1.2.4 to 1.2.5 (#193)

* Add locks and check that the federated wallet manager dealt with any forks (#202)

* Add locks and check fedwalletmanager during forks

* Reformat and reduce whitespace

* Add missing waits

* Back off if errors when send to counter node

* Optimize performance by batching block data

* Avoid large re-orgs

* Add transaction serialization workaround to Initialize method

* Upgrade packages

* Adapted the console app to have a menu (#216)

Changed the console app to have a menu rather than being a command line tool.
The reason for that is that this utility is to be used by federation members and this change makes that easier.
Also changed it so that it loops until the user exits

![image](https://user-images.githubusercontent.com/1867877/49459731-a276c980-f7e7-11e8-8db3-2e8ce39ec441.png)

* Federation Setup tool - small improvements (#217)

* Made Network non-optional
Added text option to genesis block

* Generate pubkeys properly, with file for migning priv key

* Setup of  FederatedPegTest (#221)

* Use SmartContractPoAConsensusFactory for genesis block generation

* No genesis reward for sidechains

* Find (real) Genesis Block for FederatedPegTest

* Increase Console input limit

* Use RegTest for the local sidechain network

* Add mining FedPubKeys and additional network fields

* updtae to ports to be like Stratis+1

* Update FederatedPegTest.cs

* premine reward back to 20 000 000

* Update FederatedPegTest.cs

* upgrade fullnode from 1.2.6 to 1.2.7 (#236)

* upgrade to release version of FullNode (#238)

* upgrade to release version of FullNode
1.2.6-beta => 3.0.0.0
4.0.0.70 => 4.0.0.71

* remove stratis-dev nuget source

* just to trigger a rebuild

* Fixing codestyle issues (#253)

* refactoring

* edits

* var for simple types

* private and readonly

* access modifiers

* access modifier

* fix codestyle violations part 2 (#256)

* package upgrade to 3.0.0.0 to 3.0.0.1 (#257)

* package upgrade to 3.0.0.0 to 3.0.0.1
add --no-build back to the script

* fix FederatedPegBlockDefinition constructor

* Refactored federation setup tool and added menue option to generate powershell script (#286)

* Upgrade stratis nuget packages (#292)

* NuGet update and Dbreeze serialization fix (#309)

Allows the sidechains repo to serialize everything given the changes to the FN Dbreeze serialization and ultimately allows multiple nodes to run in the one process by removing static dependencies.

I haven't actually connected to the network and completed a transfer yet - if someone could do that it would be ace.

* add a arg for passphrase for multisig key derivation (#328)

* add a arg for passphrase for multisig key derivation

* place the passphrase correctly in the do not share section

* FedPegMain definition (#343)

* Moved coinbase text out of the CreateGenesis method

* removed some unused variables

* Brought the name and cointicker of the networks inline with the definition of the networks

* Brought some more network data for Main inline

* Upgrade # of coins to 100M

* Create new genesis block for Main

* updated to SBFN 3.0.0.4 beta (#355)

* WPF Federation Key Generation App (#379)

* Initial commit for fed setup GUI wizard in WPF Blend

* POC for creating the keys with WPF and making sure we can have nugets working

* Changes to FedKeyPairGen/Program.cs to allow to run it from command line
Added Stratis logo on the top of the window and Statis icon

* Add splash screen
Add center window on startup

* Added datadir argument to FederationSetup
Removed redundent files from FederationApp

* Changes to GUI to adopt it to consultancy website

* First working version

* Updated to displayed text, initial working version candidate

* Added handling for pass phrase

* Fixed name on the folder label

* Removed POC projects

* Removed unused left over build references for Xamarin

* Updated FederationSetup.cs with help text for new args
Cleaned up Program.cs and fixed exit SwitchCommand

* Folders restructured

* References fixed

* Network values are updated.

* Coinbase text updated.

* Skipped tests removed.
dangershony added a commit to dangershony/StratisBitcoinFullNode that referenced this pull request Oct 15, 2019
Test the new consensus rules and block time adjustments
dangershony added a commit to dangershony/StratisBitcoinFullNode that referenced this pull request Nov 20, 2019
* Fix the currently failing build

* fix test
codingupastorm pushed a commit to codingupastorm/StratisBitcoinFullNode that referenced this pull request Dec 13, 2019
Upgrade ChainRepository to use KeyValueStore
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants