diff --git a/eth/api_debug.go b/eth/api_debug.go index dc9f568146..9c93de9c43 100644 --- a/eth/api_debug.go +++ b/eth/api_debug.go @@ -443,3 +443,7 @@ func (api *DebugAPI) GetTrieFlushInterval() (string, error) { } return api.eth.blockchain.GetTrieFlushInterval().String(), nil } + +func (api *DebugAPI) FieldPaddings() (string, error) { + return string(log.FieldPaddings()), nil +} diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index b86b5909d2..630ed5b371 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -501,6 +501,11 @@ web3._extend({ call: 'debug_getTrieFlushInterval', params: 0 }), + new web3._extend.Method({ + name: 'fieldPaddings', + call: 'debug_fieldPaddings', + params: 0 + }), ], properties: [] }); diff --git a/log/format.go b/log/format.go index 1adf79c17e..909ca1f939 100644 --- a/log/format.go +++ b/log/format.go @@ -62,6 +62,10 @@ type Format interface { Format(r *Record) []byte } +func init() { + json.Unmarshal([]byte("{\n \"ETH\": 2,\n \"LES\": 1,\n \"accounts\": 2,\n \"age\": 9,\n \"backend\": 5,\n \"blocks\": 1,\n \"cap\": 10,\n \"clean\": 9,\n \"dangling\": 1,\n \"dbversion\": 5,\n \"dirty\": 9,\n \"duration\": 10,\n \"elapsed\": 11,\n \"err\": 31,\n \"fees\": 7,\n \"gas\": 5,\n \"gcnodes\": 1,\n \"gcsize\": 5,\n \"gctime\": 2,\n \"hash\": 14,\n \"id\": 18,\n \"ip\": 9,\n \"limit\": 9,\n \"livenodes\": 1,\n \"livesize\": 5,\n \"mgas\": 5,\n \"mgasps\": 6,\n \"network\": 4,\n \"nodes\": 2,\n \"nonce\": 1,\n \"number\": 2,\n \"reason\": 8,\n \"reqid\": 2,\n \"root\": 14,\n \"scheme\": 4,\n \"seq\": 17,\n \"size\": 7,\n \"slots\": 1,\n \"snapdiffs\": 7,\n \"storage\": 7,\n \"tcp\": 1,\n \"td\": 1,\n \"threshold\": 1,\n \"time\": 11,\n \"total\": 2,\n \"triedirty\": 7,\n \"txs\": 1,\n \"udp\": 1,\n \"url\": 13,\n \"value\": 3,\n \"withdrawals\": 1\n}"), fieldPadding) +} + // FormatFunc returns a new Format object which uses // the given function to perform record formatting. func FormatFunc(f func(*Record) []byte) Format { @@ -187,9 +191,9 @@ func logfmt(buf *bytes.Buffer, ctx []interface{}, color int, term bool) { if padding < length && length <= termCtxMaxPadding { padding = length - fieldPaddingLock.Lock() - fieldPadding[k] = padding - fieldPaddingLock.Unlock() + //fieldPaddingLock.Lock() + //fieldPadding[k] = padding + //fieldPaddingLock.Unlock() } if color > 0 { fmt.Fprintf(buf, "\x1b[%dm%s\x1b[0m=", color, k) @@ -211,6 +215,13 @@ func JSONFormat() Format { return JSONFormatEx(false, true) } +func FieldPaddings() []byte { + fieldPaddingLock.RLock() + output, _ := json.MarshalIndent(fieldPadding, "", " ") + fieldPaddingLock.RUnlock() + return output +} + // JSONFormatOrderedEx formats log records as JSON arrays. If pretty is true, // records will be pretty-printed. If lineSeparated is true, records // will be logged with a new line between each record.