diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 02:49:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 02:49:17 +0800 |
commit | dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384 (patch) | |
tree | edb2f3a023600bcff5ff668229fc9cf2c114e18c /common | |
parent | fc97c7a38dc5193ef5e32de42235b6facf609c41 (diff) | |
parent | 2f28a12cdbee3e5c48ca5f44b128e639c60f3685 (diff) | |
download | dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar.gz dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar.bz2 dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar.lz dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar.xz dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.tar.zst dexon-dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384.zip |
Merge pull request #3718 from karalabe/terminal-format-hash
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[:]) |