Move standard fields to LogEvent

This commit is contained in:
Taylor Gerring 2015-02-11 18:49:00 +01:00
parent 3d6fd601c5
commit db24fb792c
4 changed files with 151 additions and 173 deletions

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

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

@ -11,16 +11,21 @@ func (utctime8601) MarshalJSON() ([]byte, error) {
return []byte(`"` + time.Now().UTC().Format(time.RFC3339Nano)[:26] + `Z"`), nil
}
type LogEvent interface {
type JsonLog interface {
EventName() string
}
type LogEvent struct {
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
// Level string `json:"level"`
}
type LogStarting struct {
ClientString string `json:"version_string"`
Guid string `json:"guid"`
Coinbase string `json:"coinbase"`
ProtocolVersion int `json:"eth_version"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *LogStarting) EventName() string {
@ -30,9 +35,8 @@ func (l *LogStarting) EventName() string {
type P2PConnecting struct {
RemoteId string `json:"remote_id"`
RemoteEndpoint string `json:"remote_endpoint"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PConnecting) EventName() string {
@ -40,10 +44,9 @@ func (l *P2PConnecting) EventName() string {
}
type P2PConnected struct {
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
RemoteId string `json:"remote_id"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PConnected) EventName() string {
@ -53,9 +56,8 @@ func (l *P2PConnected) EventName() string {
type P2PHandshaked struct {
RemoteCapabilities []string `json:"remote_capabilities"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts string `json:"ts"`
LogEvent
}
func (l *P2PHandshaked) EventName() string {
@ -63,10 +65,9 @@ func (l *P2PHandshaked) EventName() string {
}
type P2PDisconnected struct {
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
RemoteId string `json:"remote_id"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnected) EventName() string {
@ -76,9 +77,8 @@ func (l *P2PDisconnected) EventName() string {
type P2PDisconnecting struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnecting) EventName() string {
@ -88,9 +88,8 @@ func (l *P2PDisconnecting) EventName() string {
type P2PDisconnectingBadHandshake struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnectingBadHandshake) EventName() string {
@ -100,9 +99,8 @@ func (l *P2PDisconnectingBadHandshake) EventName() string {
type P2PDisconnectingBadProtocol struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnectingBadProtocol) EventName() string {
@ -112,9 +110,8 @@ func (l *P2PDisconnectingBadProtocol) EventName() string {
type P2PDisconnectingReputation struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnectingReputation) EventName() string {
@ -124,9 +121,8 @@ func (l *P2PDisconnectingReputation) EventName() string {
type P2PDisconnectingDHT struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PDisconnectingDHT) EventName() string {
@ -136,9 +132,8 @@ func (l *P2PDisconnectingDHT) EventName() string {
type P2PEthDisconnectingBadBlock struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PEthDisconnectingBadBlock) EventName() string {
@ -148,9 +143,8 @@ func (l *P2PEthDisconnectingBadBlock) EventName() string {
type P2PEthDisconnectingBadTx struct {
Reason string `json:"reason"`
RemoteId string `json:"remote_id"`
Guid string `json:"guid"`
NumConnections int `json:"num_connections"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *P2PEthDisconnectingBadTx) EventName() string {
@ -163,9 +157,8 @@ type EthNewBlockMined struct {
BlockHash string `json:"block_hash"`
BlockHexRlp string `json:"block_hexrlp"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockMined) EventName() string {
@ -177,9 +170,8 @@ type EthNewBlockBroadcasted struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockBroadcasted) EventName() string {
@ -191,9 +183,8 @@ type EthNewBlockReceived struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockReceived) EventName() string {
@ -205,9 +196,8 @@ type EthNewBlockIsKnown struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockIsKnown) EventName() string {
@ -219,9 +209,8 @@ type EthNewBlockIsNew struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockIsNew) EventName() string {
@ -233,9 +222,8 @@ type EthNewBlockMissingParent struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockMissingParent) EventName() string {
@ -247,9 +235,8 @@ type EthNewBlockIsInvalid struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockIsInvalid) EventName() string {
@ -261,9 +248,8 @@ type EthNewBlockChainIsOlder struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockChainIsOlder) EventName() string {
@ -275,9 +261,8 @@ type EthNewBlockChainIsCanonical struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockChainIsCanonical) EventName() string {
@ -289,9 +274,8 @@ type EthNewBlockChainNotCanonical struct {
HeadHash string `json:"head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockChainNotCanonical) EventName() string {
@ -304,9 +288,8 @@ type EthNewBlockChainSwitched struct {
OldHeadHash string `json:"old_head_hash"`
BlockHash string `json:"block_hash"`
BlockDifficulty int `json:"block_difficulty"`
Guid string `json:"guid"`
BlockPrevHash string `json:"block_prev_hash"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthNewBlockChainSwitched) EventName() string {
@ -319,8 +302,7 @@ type EthTxCreated struct {
TxAddress string `json:"tx_address"`
TxHexRLP string `json:"tx_hexrlp"`
TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthTxCreated) EventName() string {
@ -333,8 +315,7 @@ type EthTxReceived struct {
TxHexRLP string `json:"tx_hexrlp"`
RemoteId string `json:"remote_id"`
TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthTxReceived) EventName() string {
@ -346,8 +327,7 @@ type EthTxBroadcasted struct {
TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"`
TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthTxBroadcasted) EventName() string {
@ -359,8 +339,7 @@ type EthTxValidated struct {
TxSender string `json:"tx_sender"`
TxAddress string `json:"tx_address"`
TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthTxValidated) EventName() string {
@ -373,8 +352,7 @@ type EthTxIsInvalid struct {
TxAddress string `json:"tx_address"`
Reason string `json:"reason"`
TxNonce int `json:"tx_nonce"`
Guid string `json:"guid"`
Ts utctime8601 `json:"ts"`
LogEvent
}
func (l *EthTxIsInvalid) EventName() string {

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