github.com/klaytn/klaytn@v1.12.1/log/log_modules.go (about)

     1  // Copyright 2018 The klaytn Authors
     2  // This file is part of the klaytn library.
     3  //
     4  // The klaytn library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The klaytn library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package log
    18  
    19  import (
    20  	"strconv"
    21  	"strings"
    22  	"time"
    23  )
    24  
    25  // StatsReportLimit is the time limit during working after which we always print
    26  // out progress. This avoids the user wondering what's going on.
    27  const StatsReportLimit = 10 * time.Second
    28  
    29  type ModuleID int
    30  
    31  // When printID is true, log prints ModuleID instead of ModuleName.
    32  // TODO-Klaytn This can be controlled by runtime configuration.
    33  var printID = true
    34  
    35  func GetModuleName(mi ModuleID) string {
    36  	return moduleNames[int(mi)]
    37  }
    38  
    39  func GetModuleID(moduleName string) ModuleID {
    40  	moduleName = strings.ToLower(moduleName)
    41  	for i := 0; i < len(moduleNames); i++ {
    42  		if moduleName == moduleNames[i] {
    43  			return ModuleID(i)
    44  		}
    45  	}
    46  	return ModuleNameLen
    47  }
    48  
    49  func (mi ModuleID) String() string {
    50  	if printID {
    51  		return strconv.Itoa(int(mi))
    52  	}
    53  	return moduleNames[mi]
    54  }
    55  
    56  // NOTE-Klaytn-Log Please add module in lexicographical order.
    57  const (
    58  	// 0
    59  	BaseLogger ModuleID = iota
    60  
    61  	// 1~10
    62  	AccountsAbiBind
    63  	AccountsKeystore
    64  	API
    65  	APIDebug
    66  	Blockchain
    67  	BlockchainState
    68  	BlockchainTypes
    69  	BlockchainTypesAccount
    70  	BlockchainTypesAccountKey
    71  	CMDIstanbul
    72  
    73  	// 11~20
    74  	CMDKBN
    75  	CMDKCN
    76  	CMDKEN
    77  	CMDKGEN
    78  	CMDKlay
    79  	CMDKPN
    80  	CMDKSCN
    81  	CMDUtils
    82  	CMDUtilsNodeCMD
    83  	Common
    84  
    85  	// 21~30
    86  	ConsensusClique
    87  	ConsensusGxhash
    88  	ConsensusIstanbul
    89  	ConsensusIstanbulBackend
    90  	ConsensusIstanbulCore
    91  	ConsensusIstanbulValidator
    92  	Console
    93  	DatasyncDownloader
    94  	DatasyncFetcher
    95  	Governance
    96  
    97  	// 31~40
    98  	Metrics
    99  	NetworksGRPC
   100  	NetworksP2P
   101  	NetworksP2PDiscover
   102  	NetworksP2PNat
   103  	NetworksP2PSimulations
   104  	NetworksP2PSimulationsAdapters
   105  	NetworksP2PSimulationsCnism
   106  	NetworksRPC
   107  	Node
   108  
   109  	// 41~50
   110  	NodeCN
   111  	NodeCNFilters
   112  	NodeCNTracers
   113  	Reward
   114  	ServiceChain
   115  	Snapshot
   116  	SnapshotSync
   117  	StorageDatabase
   118  	StorageStateDB
   119  	VM
   120  
   121  	// 51~60
   122  	Work
   123  	CMDKSPN
   124  	CMDKSEN
   125  	ChainDataFetcher
   126  	KAS
   127  	FORK
   128  	NodeCnGasPrice
   129  
   130  	// ModuleNameLen should be placed at the end of the list.
   131  	ModuleNameLen
   132  )
   133  
   134  var moduleNames = [ModuleNameLen]string{
   135  	// 0
   136  	"defaultLogger",
   137  
   138  	// 1~10
   139  	"accounts/abi/bind",
   140  	"accounts/keystore",
   141  	"api",
   142  	"api/debug",
   143  	"blockchain",
   144  	"blockchain/state",
   145  	"blockchain/types",
   146  	"blockchain/types/account",
   147  	"blockchain/types/accountkey",
   148  	"cmd/istanbul",
   149  
   150  	// 11~20
   151  	"cmd/kbn",
   152  	"cmd/kcn",
   153  	"cmd/ken",
   154  	"cmd/kgen",
   155  	"cmd/klay",
   156  	"cmd/kpn",
   157  	"cmd/kscn",
   158  	"cmd/utils",
   159  	"cmd/utils/nodecmd",
   160  	"common",
   161  
   162  	// 21~30
   163  	"consensus/clique",
   164  	"consensus/gxhash",
   165  	"consensus/istanbul",
   166  	"consensus/istanbul/backend",
   167  	"consensus/istanbul/core",
   168  	"consensus/istanbul/validator",
   169  	"console",
   170  	"datasync/downloader",
   171  	"datasync/fetcher",
   172  	"governance/governance",
   173  
   174  	// 31~40
   175  	"metrics",
   176  	"networks/grpc",
   177  	"networks/p2p",
   178  	"networks/p2p/discover",
   179  	"networks/p2p/nat",
   180  	"networks/p2p/simulations",
   181  	"networks/p2p/simulations/adapters",
   182  	"networks/p2p/simulations/cnism",
   183  	"networks/rpc",
   184  	"node",
   185  
   186  	// 41~50
   187  	"node/cn",
   188  	"node/cn/filters",
   189  	"node/cn/tracers",
   190  	"contracts/reward",
   191  	"servicechain",
   192  	"snapshot",
   193  	"node/cn/snap",
   194  	"storage/database",
   195  	"storage/statedb",
   196  	"vm",
   197  
   198  	// 51~60
   199  	"work",
   200  	"cmd/kspn",
   201  	"cmd/ksen",
   202  	"datasync/chaindatafetcher",
   203  	"kas",
   204  	"fork",
   205  	"node/cn/gasprice",
   206  }