diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-27 23:06:40 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 01:15:18 +0800 |
commit | 2f28a12cdbee3e5c48ca5f44b128e639c60f3685 (patch) | |
tree | edb2f3a023600bcff5ff668229fc9cf2c114e18c /common | |
parent | fc97c7a38dc5193ef5e32de42235b6facf609c41 (diff) | |
download | go-tangerine-2f28a12cdbee3e5c48ca5f44b128e639c60f3685.tar.gz go-tangerine-2f28a12cdbee3e5c48ca5f44b128e639c60f3685.tar.zst go-tangerine-2f28a12cdbee3e5c48ca5f44b128e639c60f3685.zip |
common, eth/downloader, log: support terminal log formatting
Diffstat (limited to 'common')
-rw-r--r-- | common/types.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/types.go b/common/types.go index d38ea7306..1585d878c 100644 --- a/common/types.go +++ b/common/types.go @@ -55,6 +55,24 @@ func (h Hash) Bytes() []byte { return h[:] } func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) } func (h Hash) Hex() string { return hexutil.Encode(h[:]) } +// TerminalString implements log.TerminalStringer, formatting a string for console +// output during logging. +func (h Hash) TerminalString() string { + return fmt.Sprintf("%x…%x", h[:3], h[29:]) +} + +// String implements the stringer interface and is used also by the logger when +// doing full logging into a file. +func (h Hash) String() string { + return h.Hex() +} + +// Format implements fmt.Formatter, forcing the byte slice to be formatted as is, +// without going through the stringer interface used for logging. +func (h Hash) Format(s fmt.State, c rune) { + fmt.Fprintf(s, "%"+string(c), h[:]) +} + // UnmarshalJSON parses a hash in its hex from to a hash. func (h *Hash) UnmarshalJSON(input []byte) error { return hexutil.UnmarshalJSON("Hash", input, h[:]) |