Move standard fields to LogEvent

pull/265/head
Taylor Gerring 10 years ago
parent 3d6fd601c5
commit db24fb792c
  1. 2
      eth/backend.go
  2. 6
      logger/loggers.go
  3. 314
      logger/types.go
  4. 2
      p2p/server.go

@ -224,9 +224,9 @@ func (s *Ethereum) MaxPeers() int {
func (s *Ethereum) Start(seed bool) error { func (s *Ethereum) Start(seed bool) error {
jsonlogger.LogJson(&ethlogger.LogStarting{ jsonlogger.LogJson(&ethlogger.LogStarting{
ClientString: s.ClientIdentity().String(), ClientString: s.ClientIdentity().String(),
Guid: ethutil.Bytes2Hex(s.ClientIdentity().Pubkey()),
Coinbase: ethutil.Bytes2Hex(s.KeyManager().Address()), Coinbase: ethutil.Bytes2Hex(s.KeyManager().Address()),
ProtocolVersion: ProtocolVersion, ProtocolVersion: ProtocolVersion,
LogEvent: ethlogger.LogEvent{Guid: ethutil.Bytes2Hex(s.ClientIdentity().Pubkey())},
}) })
err := s.net.Start() err := s.net.Start()

@ -114,13 +114,15 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) {
os.Exit(0) os.Exit(0)
} }
type JsonLogger struct{} type JsonLogger struct {
Coinbase string
}
func NewJsonLogger() *JsonLogger { func NewJsonLogger() *JsonLogger {
return &JsonLogger{} return &JsonLogger{}
} }
func (logger *JsonLogger) LogJson(v LogEvent) { func (logger *JsonLogger) LogJson(v JsonLog) {
msgname := v.EventName() msgname := v.EventName()
obj := map[string]interface{}{ obj := map[string]interface{}{
msgname: v, msgname: v,

@ -11,16 +11,21 @@ func (utctime8601) MarshalJSON() ([]byte, error) {
return []byte(`"` + time.Now().UTC().Format(time.RFC3339Nano)[:26] + `Z"`), nil return []byte(`"` + time.Now().UTC().Format(time.RFC3339Nano)[:26] + `Z"`), nil
} }
type LogEvent interface { type JsonLog interface {
EventName() string EventName() string
} }
type LogEvent struct {
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
// Level string `json:"level"`
}
type LogStarting struct { type LogStarting struct {
ClientString string `json:"version_string"` ClientString string `json:"version_string"`
Guid string `json:"guid"` Coinbase string `json:"coinbase"`
Coinbase string `json:"coinbase"` ProtocolVersion int `json:"eth_version"`
ProtocolVersion int `json:"eth_version"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *LogStarting) EventName() string { func (l *LogStarting) EventName() string {
@ -28,11 +33,10 @@ func (l *LogStarting) EventName() string {
} }
type P2PConnecting struct { type P2PConnecting struct {
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
RemoteEndpoint string `json:"remote_endpoint"` RemoteEndpoint string `json:"remote_endpoint"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PConnecting) EventName() string { func (l *P2PConnecting) EventName() string {
@ -40,10 +44,9 @@ func (l *P2PConnecting) EventName() string {
} }
type P2PConnected struct { type P2PConnected struct {
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` RemoteId string `json:"remote_id"`
RemoteId string `json:"remote_id"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PConnected) EventName() string { func (l *P2PConnected) EventName() string {
@ -53,9 +56,8 @@ func (l *P2PConnected) EventName() string {
type P2PHandshaked struct { type P2PHandshaked struct {
RemoteCapabilities []string `json:"remote_capabilities"` RemoteCapabilities []string `json:"remote_capabilities"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"` NumConnections int `json:"num_connections"`
Ts string `json:"ts"` LogEvent
} }
func (l *P2PHandshaked) EventName() string { func (l *P2PHandshaked) EventName() string {
@ -63,10 +65,9 @@ func (l *P2PHandshaked) EventName() string {
} }
type P2PDisconnected struct { type P2PDisconnected struct {
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` RemoteId string `json:"remote_id"`
RemoteId string `json:"remote_id"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnected) EventName() string { func (l *P2PDisconnected) EventName() string {
@ -74,11 +75,10 @@ func (l *P2PDisconnected) EventName() string {
} }
type P2PDisconnecting struct { type P2PDisconnecting struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnecting) EventName() string { func (l *P2PDisconnecting) EventName() string {
@ -86,11 +86,10 @@ func (l *P2PDisconnecting) EventName() string {
} }
type P2PDisconnectingBadHandshake struct { type P2PDisconnectingBadHandshake struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnectingBadHandshake) EventName() string { func (l *P2PDisconnectingBadHandshake) EventName() string {
@ -98,11 +97,10 @@ func (l *P2PDisconnectingBadHandshake) EventName() string {
} }
type P2PDisconnectingBadProtocol struct { type P2PDisconnectingBadProtocol struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnectingBadProtocol) EventName() string { func (l *P2PDisconnectingBadProtocol) EventName() string {
@ -110,11 +108,10 @@ func (l *P2PDisconnectingBadProtocol) EventName() string {
} }
type P2PDisconnectingReputation struct { type P2PDisconnectingReputation struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnectingReputation) EventName() string { func (l *P2PDisconnectingReputation) EventName() string {
@ -122,11 +119,10 @@ func (l *P2PDisconnectingReputation) EventName() string {
} }
type P2PDisconnectingDHT struct { type P2PDisconnectingDHT struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PDisconnectingDHT) EventName() string { func (l *P2PDisconnectingDHT) EventName() string {
@ -134,11 +130,10 @@ func (l *P2PDisconnectingDHT) EventName() string {
} }
type P2PEthDisconnectingBadBlock struct { type P2PEthDisconnectingBadBlock struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PEthDisconnectingBadBlock) EventName() string { func (l *P2PEthDisconnectingBadBlock) EventName() string {
@ -146,11 +141,10 @@ func (l *P2PEthDisconnectingBadBlock) EventName() string {
} }
type P2PEthDisconnectingBadTx struct { type P2PEthDisconnectingBadTx struct {
Reason string `json:"reason"` Reason string `json:"reason"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
Guid string `json:"guid"` NumConnections int `json:"num_connections"`
NumConnections int `json:"num_connections"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *P2PEthDisconnectingBadTx) EventName() string { func (l *P2PEthDisconnectingBadTx) EventName() string {
@ -158,14 +152,13 @@ func (l *P2PEthDisconnectingBadTx) EventName() string {
} }
type EthNewBlockMined struct { type EthNewBlockMined struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockHexRlp string `json:"block_hexrlp"` BlockHexRlp string `json:"block_hexrlp"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockMined) EventName() string { func (l *EthNewBlockMined) EventName() string {
@ -173,13 +166,12 @@ func (l *EthNewBlockMined) EventName() string {
} }
type EthNewBlockBroadcasted struct { type EthNewBlockBroadcasted struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockBroadcasted) EventName() string { func (l *EthNewBlockBroadcasted) EventName() string {
@ -187,13 +179,12 @@ func (l *EthNewBlockBroadcasted) EventName() string {
} }
type EthNewBlockReceived struct { type EthNewBlockReceived struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockReceived) EventName() string { func (l *EthNewBlockReceived) EventName() string {
@ -201,13 +192,12 @@ func (l *EthNewBlockReceived) EventName() string {
} }
type EthNewBlockIsKnown struct { type EthNewBlockIsKnown struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockIsKnown) EventName() string { func (l *EthNewBlockIsKnown) EventName() string {
@ -215,13 +205,12 @@ func (l *EthNewBlockIsKnown) EventName() string {
} }
type EthNewBlockIsNew struct { type EthNewBlockIsNew struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockIsNew) EventName() string { func (l *EthNewBlockIsNew) EventName() string {
@ -229,13 +218,12 @@ func (l *EthNewBlockIsNew) EventName() string {
} }
type EthNewBlockMissingParent struct { type EthNewBlockMissingParent struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockMissingParent) EventName() string { func (l *EthNewBlockMissingParent) EventName() string {
@ -243,13 +231,12 @@ func (l *EthNewBlockMissingParent) EventName() string {
} }
type EthNewBlockIsInvalid struct { type EthNewBlockIsInvalid struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockIsInvalid) EventName() string { func (l *EthNewBlockIsInvalid) EventName() string {
@ -257,13 +244,12 @@ func (l *EthNewBlockIsInvalid) EventName() string {
} }
type EthNewBlockChainIsOlder struct { type EthNewBlockChainIsOlder struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockChainIsOlder) EventName() string { func (l *EthNewBlockChainIsOlder) EventName() string {
@ -271,13 +257,12 @@ func (l *EthNewBlockChainIsOlder) EventName() string {
} }
type EthNewBlockChainIsCanonical struct { type EthNewBlockChainIsCanonical struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockChainIsCanonical) EventName() string { func (l *EthNewBlockChainIsCanonical) EventName() string {
@ -285,13 +270,12 @@ func (l *EthNewBlockChainIsCanonical) EventName() string {
} }
type EthNewBlockChainNotCanonical struct { type EthNewBlockChainNotCanonical struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockChainNotCanonical) EventName() string { func (l *EthNewBlockChainNotCanonical) EventName() string {
@ -299,14 +283,13 @@ func (l *EthNewBlockChainNotCanonical) EventName() string {
} }
type EthNewBlockChainSwitched struct { type EthNewBlockChainSwitched struct {
BlockNumber int `json:"block_number"` BlockNumber int `json:"block_number"`
HeadHash string `json:"head_hash"` HeadHash string `json:"head_hash"`
OldHeadHash string `json:"old_head_hash"` OldHeadHash string `json:"old_head_hash"`
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"` BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"` BlockPrevHash string `json:"block_prev_hash"`
BlockPrevHash string `json:"block_prev_hash"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthNewBlockChainSwitched) EventName() string { func (l *EthNewBlockChainSwitched) EventName() string {
@ -314,13 +297,12 @@ func (l *EthNewBlockChainSwitched) EventName() string {
} }
type EthTxCreated struct { type EthTxCreated struct {
TxHash string `json:"tx_hash"` TxHash string `json:"tx_hash"`
TxSender string `json:"tx_sender"` TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"` TxAddress string `json:"tx_address"`
TxHexRLP string `json:"tx_hexrlp"` TxHexRLP string `json:"tx_hexrlp"`
TxNonce int `json:"tx_nonce"` TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthTxCreated) EventName() string { func (l *EthTxCreated) EventName() string {
@ -328,13 +310,12 @@ func (l *EthTxCreated) EventName() string {
} }
type EthTxReceived struct { type EthTxReceived struct {
TxHash string `json:"tx_hash"` TxHash string `json:"tx_hash"`
TxAddress string `json:"tx_address"` TxAddress string `json:"tx_address"`
TxHexRLP string `json:"tx_hexrlp"` TxHexRLP string `json:"tx_hexrlp"`
RemoteId string `json:"remote_id"` RemoteId string `json:"remote_id"`
TxNonce int `json:"tx_nonce"` TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthTxReceived) EventName() string { func (l *EthTxReceived) EventName() string {
@ -342,12 +323,11 @@ func (l *EthTxReceived) EventName() string {
} }
type EthTxBroadcasted struct { type EthTxBroadcasted struct {
TxHash string `json:"tx_hash"` TxHash string `json:"tx_hash"`
TxSender string `json:"tx_sender"` TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"` TxAddress string `json:"tx_address"`
TxNonce int `json:"tx_nonce"` TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthTxBroadcasted) EventName() string { func (l *EthTxBroadcasted) EventName() string {
@ -355,12 +335,11 @@ func (l *EthTxBroadcasted) EventName() string {
} }
type EthTxValidated struct { type EthTxValidated struct {
TxHash string `json:"tx_hash"` TxHash string `json:"tx_hash"`
TxSender string `json:"tx_sender"` TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"` TxAddress string `json:"tx_address"`
TxNonce int `json:"tx_nonce"` TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthTxValidated) EventName() string { func (l *EthTxValidated) EventName() string {
@ -368,13 +347,12 @@ func (l *EthTxValidated) EventName() string {
} }
type EthTxIsInvalid struct { type EthTxIsInvalid struct {
TxHash string `json:"tx_hash"` TxHash string `json:"tx_hash"`
TxSender string `json:"tx_sender"` TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"` TxAddress string `json:"tx_address"`
Reason string `json:"reason"` Reason string `json:"reason"`
TxNonce int `json:"tx_nonce"` TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"` LogEvent
Ts utctime8601 `json:"ts"`
} }
func (l *EthTxIsInvalid) EventName() string { func (l *EthTxIsInvalid) EventName() string {

@ -20,8 +20,6 @@ const (
var srvlog = logger.NewLogger("P2P Server") var srvlog = logger.NewLogger("P2P Server")
var jsonlogger = logger.NewJsonLogger()
// Server manages all peer connections. // Server manages all peer connections.
// //
// The fields of Server are used as configuration parameters. // The fields of Server are used as configuration parameters.

Loading…
Cancel
Save