github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/logger/types.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package logger 18 19 import ( 20 "math/big" 21 "time" 22 ) 23 24 type utctime8601 struct{} 25 26 func (utctime8601) MarshalJSON() ([]byte, error) { 27 timestr := time.Now().UTC().Format(time.RFC3339Nano) 28 // Bounds check 29 if len(timestr) > 26 { 30 timestr = timestr[:26] 31 } 32 return []byte(`"` + timestr + `Z"`), nil 33 } 34 35 type JsonLog interface { 36 EventName() string 37 } 38 39 type LogEvent struct { 40 // Guid string `json:"guid"` 41 Ts utctime8601 `json:"ts"` 42 // Level string `json:"level"` 43 } 44 45 type LogStarting struct { 46 ClientString string `json:"client_impl"` 47 ProtocolVersion int `json:"eth_version"` 48 LogEvent 49 } 50 51 func (l *LogStarting) EventName() string { 52 return "starting" 53 } 54 55 type P2PConnected struct { 56 RemoteId string `json:"remote_id"` 57 RemoteAddress string `json:"remote_addr"` 58 RemoteVersionString string `json:"remote_version_string"` 59 NumConnections int `json:"num_connections"` 60 LogEvent 61 } 62 63 func (l *P2PConnected) EventName() string { 64 return "p2p.connected" 65 } 66 67 type P2PDisconnected struct { 68 NumConnections int `json:"num_connections"` 69 RemoteId string `json:"remote_id"` 70 LogEvent 71 } 72 73 func (l *P2PDisconnected) EventName() string { 74 return "p2p.disconnected" 75 } 76 77 type EthMinerNewBlock struct { 78 BlockHash string `json:"block_hash"` 79 BlockNumber *big.Int `json:"block_number"` 80 ChainHeadHash string `json:"chain_head_hash"` 81 BlockPrevHash string `json:"block_prev_hash"` 82 LogEvent 83 } 84 85 func (l *EthMinerNewBlock) EventName() string { 86 return "eth.miner.new_block" 87 } 88 89 type EthChainReceivedNewBlock struct { 90 BlockHash string `json:"block_hash"` 91 BlockNumber *big.Int `json:"block_number"` 92 ChainHeadHash string `json:"chain_head_hash"` 93 BlockPrevHash string `json:"block_prev_hash"` 94 RemoteId string `json:"remote_id"` 95 LogEvent 96 } 97 98 func (l *EthChainReceivedNewBlock) EventName() string { 99 return "eth.chain.received.new_block" 100 } 101 102 type EthChainNewHead struct { 103 BlockHash string `json:"block_hash"` 104 BlockNumber *big.Int `json:"block_number"` 105 ChainHeadHash string `json:"chain_head_hash"` 106 BlockPrevHash string `json:"block_prev_hash"` 107 LogEvent 108 } 109 110 func (l *EthChainNewHead) EventName() string { 111 return "eth.chain.new_head" 112 } 113 114 type EthTxReceived struct { 115 TxHash string `json:"tx_hash"` 116 RemoteId string `json:"remote_id"` 117 LogEvent 118 } 119 120 func (l *EthTxReceived) EventName() string { 121 return "eth.tx.received" 122 } 123 124 // 125 // 126 // The types below are legacy and need to be converted to new format or deleted 127 // 128 // 129 130 // type P2PConnecting struct { 131 // RemoteId string `json:"remote_id"` 132 // RemoteEndpoint string `json:"remote_endpoint"` 133 // NumConnections int `json:"num_connections"` 134 // LogEvent 135 // } 136 137 // func (l *P2PConnecting) EventName() string { 138 // return "p2p.connecting" 139 // } 140 141 // type P2PHandshaked struct { 142 // RemoteCapabilities []string `json:"remote_capabilities"` 143 // RemoteId string `json:"remote_id"` 144 // NumConnections int `json:"num_connections"` 145 // LogEvent 146 // } 147 148 // func (l *P2PHandshaked) EventName() string { 149 // return "p2p.handshaked" 150 // } 151 152 // type P2PDisconnecting struct { 153 // Reason string `json:"reason"` 154 // RemoteId string `json:"remote_id"` 155 // NumConnections int `json:"num_connections"` 156 // LogEvent 157 // } 158 159 // func (l *P2PDisconnecting) EventName() string { 160 // return "p2p.disconnecting" 161 // } 162 163 // type P2PDisconnectingBadHandshake struct { 164 // Reason string `json:"reason"` 165 // RemoteId string `json:"remote_id"` 166 // NumConnections int `json:"num_connections"` 167 // LogEvent 168 // } 169 170 // func (l *P2PDisconnectingBadHandshake) EventName() string { 171 // return "p2p.disconnecting.bad_handshake" 172 // } 173 174 // type P2PDisconnectingBadProtocol struct { 175 // Reason string `json:"reason"` 176 // RemoteId string `json:"remote_id"` 177 // NumConnections int `json:"num_connections"` 178 // LogEvent 179 // } 180 181 // func (l *P2PDisconnectingBadProtocol) EventName() string { 182 // return "p2p.disconnecting.bad_protocol" 183 // } 184 185 // type P2PDisconnectingReputation struct { 186 // Reason string `json:"reason"` 187 // RemoteId string `json:"remote_id"` 188 // NumConnections int `json:"num_connections"` 189 // LogEvent 190 // } 191 192 // func (l *P2PDisconnectingReputation) EventName() string { 193 // return "p2p.disconnecting.reputation" 194 // } 195 196 // type P2PDisconnectingDHT struct { 197 // Reason string `json:"reason"` 198 // RemoteId string `json:"remote_id"` 199 // NumConnections int `json:"num_connections"` 200 // LogEvent 201 // } 202 203 // func (l *P2PDisconnectingDHT) EventName() string { 204 // return "p2p.disconnecting.dht" 205 // } 206 207 // type P2PEthDisconnectingBadBlock struct { 208 // Reason string `json:"reason"` 209 // RemoteId string `json:"remote_id"` 210 // NumConnections int `json:"num_connections"` 211 // LogEvent 212 // } 213 214 // func (l *P2PEthDisconnectingBadBlock) EventName() string { 215 // return "p2p.eth.disconnecting.bad_block" 216 // } 217 218 // type P2PEthDisconnectingBadTx struct { 219 // Reason string `json:"reason"` 220 // RemoteId string `json:"remote_id"` 221 // NumConnections int `json:"num_connections"` 222 // LogEvent 223 // } 224 225 // func (l *P2PEthDisconnectingBadTx) EventName() string { 226 // return "p2p.eth.disconnecting.bad_tx" 227 // } 228 229 // type EthNewBlockBroadcasted struct { 230 // BlockNumber int `json:"block_number"` 231 // HeadHash string `json:"head_hash"` 232 // BlockHash string `json:"block_hash"` 233 // BlockDifficulty int `json:"block_difficulty"` 234 // BlockPrevHash string `json:"block_prev_hash"` 235 // LogEvent 236 // } 237 238 // func (l *EthNewBlockBroadcasted) EventName() string { 239 // return "eth.newblock.broadcasted" 240 // } 241 242 // type EthNewBlockIsKnown struct { 243 // BlockNumber int `json:"block_number"` 244 // HeadHash string `json:"head_hash"` 245 // BlockHash string `json:"block_hash"` 246 // BlockDifficulty int `json:"block_difficulty"` 247 // BlockPrevHash string `json:"block_prev_hash"` 248 // LogEvent 249 // } 250 251 // func (l *EthNewBlockIsKnown) EventName() string { 252 // return "eth.newblock.is_known" 253 // } 254 255 // type EthNewBlockIsNew struct { 256 // BlockNumber int `json:"block_number"` 257 // HeadHash string `json:"head_hash"` 258 // BlockHash string `json:"block_hash"` 259 // BlockDifficulty int `json:"block_difficulty"` 260 // BlockPrevHash string `json:"block_prev_hash"` 261 // LogEvent 262 // } 263 264 // func (l *EthNewBlockIsNew) EventName() string { 265 // return "eth.newblock.is_new" 266 // } 267 268 // type EthNewBlockMissingParent struct { 269 // BlockNumber int `json:"block_number"` 270 // HeadHash string `json:"head_hash"` 271 // BlockHash string `json:"block_hash"` 272 // BlockDifficulty int `json:"block_difficulty"` 273 // BlockPrevHash string `json:"block_prev_hash"` 274 // LogEvent 275 // } 276 277 // func (l *EthNewBlockMissingParent) EventName() string { 278 // return "eth.newblock.missing_parent" 279 // } 280 281 // type EthNewBlockIsInvalid struct { 282 // BlockNumber int `json:"block_number"` 283 // HeadHash string `json:"head_hash"` 284 // BlockHash string `json:"block_hash"` 285 // BlockDifficulty int `json:"block_difficulty"` 286 // BlockPrevHash string `json:"block_prev_hash"` 287 // LogEvent 288 // } 289 290 // func (l *EthNewBlockIsInvalid) EventName() string { 291 // return "eth.newblock.is_invalid" 292 // } 293 294 // type EthNewBlockChainIsOlder struct { 295 // BlockNumber int `json:"block_number"` 296 // HeadHash string `json:"head_hash"` 297 // BlockHash string `json:"block_hash"` 298 // BlockDifficulty int `json:"block_difficulty"` 299 // BlockPrevHash string `json:"block_prev_hash"` 300 // LogEvent 301 // } 302 303 // func (l *EthNewBlockChainIsOlder) EventName() string { 304 // return "eth.newblock.chain.is_older" 305 // } 306 307 // type EthNewBlockChainIsCanonical struct { 308 // BlockNumber int `json:"block_number"` 309 // HeadHash string `json:"head_hash"` 310 // BlockHash string `json:"block_hash"` 311 // BlockDifficulty int `json:"block_difficulty"` 312 // BlockPrevHash string `json:"block_prev_hash"` 313 // LogEvent 314 // } 315 316 // func (l *EthNewBlockChainIsCanonical) EventName() string { 317 // return "eth.newblock.chain.is_cannonical" 318 // } 319 320 // type EthNewBlockChainNotCanonical struct { 321 // BlockNumber int `json:"block_number"` 322 // HeadHash string `json:"head_hash"` 323 // BlockHash string `json:"block_hash"` 324 // BlockDifficulty int `json:"block_difficulty"` 325 // BlockPrevHash string `json:"block_prev_hash"` 326 // LogEvent 327 // } 328 329 // func (l *EthNewBlockChainNotCanonical) EventName() string { 330 // return "eth.newblock.chain.not_cannonical" 331 // } 332 333 // type EthTxCreated struct { 334 // TxHash string `json:"tx_hash"` 335 // TxSender string `json:"tx_sender"` 336 // TxAddress string `json:"tx_address"` 337 // TxHexRLP string `json:"tx_hexrlp"` 338 // TxNonce int `json:"tx_nonce"` 339 // LogEvent 340 // } 341 342 // func (l *EthTxCreated) EventName() string { 343 // return "eth.tx.created" 344 // } 345 346 // type EthTxBroadcasted struct { 347 // TxHash string `json:"tx_hash"` 348 // TxSender string `json:"tx_sender"` 349 // TxAddress string `json:"tx_address"` 350 // TxNonce int `json:"tx_nonce"` 351 // LogEvent 352 // } 353 354 // func (l *EthTxBroadcasted) EventName() string { 355 // return "eth.tx.broadcasted" 356 // } 357 358 // type EthTxValidated struct { 359 // TxHash string `json:"tx_hash"` 360 // TxSender string `json:"tx_sender"` 361 // TxAddress string `json:"tx_address"` 362 // TxNonce int `json:"tx_nonce"` 363 // LogEvent 364 // } 365 366 // func (l *EthTxValidated) EventName() string { 367 // return "eth.tx.validated" 368 // } 369 370 // type EthTxIsInvalid struct { 371 // TxHash string `json:"tx_hash"` 372 // TxSender string `json:"tx_sender"` 373 // TxAddress string `json:"tx_address"` 374 // Reason string `json:"reason"` 375 // TxNonce int `json:"tx_nonce"` 376 // LogEvent 377 // } 378 379 // func (l *EthTxIsInvalid) EventName() string { 380 // return "eth.tx.is_invalid" 381 // }