|
| 1 | +// Copyright 2023 The go-ethereum Authors |
| 2 | +// This file is part of go-ethereum. |
| 3 | +// |
| 4 | +// go-ethereum is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// go-ethereum is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +package main |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "github.com/ethereum/go-ethereum/common" |
| 22 | + "github.com/ethereum/go-ethereum/log" |
| 23 | + "github.com/holiman/uint256" |
| 24 | + "github.com/urfave/cli/v2" |
| 25 | + "math" |
| 26 | + "math/big" |
| 27 | + "time" |
| 28 | +) |
| 29 | + |
| 30 | +// logTest is an entry point which spits out some logs. This is used by testing |
| 31 | +// to verify expected outputs |
| 32 | +func logTest(ctx *cli.Context) error { |
| 33 | + |
| 34 | + { // big.Int |
| 35 | + ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999" |
| 36 | + bb, _ := new(big.Int).SetString("-111222333444555678999", 10) // "-111,222,333,444,555,678,999" |
| 37 | + bc, _ := new(big.Int).SetString("11122233344455567899900", 10) // "11,122,233,344,455,567,899,900" |
| 38 | + bd, _ := new(big.Int).SetString("-11122233344455567899900", 10) // "-11,122,233,344,455,567,899,900" |
| 39 | + log.Info("big.Int", "111,222,333,444,555,678,999", ba) |
| 40 | + log.Info("-big.Int", "-111,222,333,444,555,678,999", bb) |
| 41 | + log.Info("big.Int", "11,122,233,344,455,567,899,900", bc) |
| 42 | + log.Info("-big.Int", "-11,122,233,344,455,567,899,900", bd) |
| 43 | + } |
| 44 | + { //uint256 |
| 45 | + ua, _ := uint256.FromDecimal("111222333444555678999") |
| 46 | + ub, _ := uint256.FromDecimal("11122233344455567899900") |
| 47 | + log.Info("uint256", "111,222,333,444,555,678,999", ua) |
| 48 | + log.Info("uint256", "11,122,233,344,455,567,899,900", ub) |
| 49 | + } |
| 50 | + { // int64 |
| 51 | + log.Info("int64", "1,000,000", int64(1000000)) |
| 52 | + log.Info("int64", "-1,000,000", int64(-1000000)) |
| 53 | + log.Info("int64", "9,223,372,036,854,775,807", math.MaxInt64) |
| 54 | + log.Info("int64", "-9,223,372,036,854,775,808", math.MinInt64) |
| 55 | + } |
| 56 | + { // uint64 |
| 57 | + log.Info("uint64", "1,000,000", uint64(1000000)) |
| 58 | + log.Info("uint64", "18,446,744,073,709,551,615", uint64(math.MaxUint64)) |
| 59 | + } |
| 60 | + { // Special characters |
| 61 | + log.Info("Special chars in value", "key", "special \r\n\t chars") |
| 62 | + log.Info("Special chars in key", "special \n\t chars", "value") |
| 63 | + |
| 64 | + log.Info("nospace", "nospace", "nospace") |
| 65 | + log.Info("with space", "with nospace", "with nospace") |
| 66 | + |
| 67 | + log.Info("Bash escapes in value", "key", "\u001b[1G\u001b[K\u001b[1A") |
| 68 | + log.Info("Bash escapes in key", "\u001b[1G\u001b[K\u001b[1A", "value") |
| 69 | + |
| 70 | + log.Info("Bash escapes in message \u001b[1G\u001b[K\u001b[1A end", "key", "value") |
| 71 | + |
| 72 | + colored := fmt.Sprintf("\u001B[%dmColored\u001B[0m[", 35) |
| 73 | + log.Info(colored, colored, colored) |
| 74 | + } |
| 75 | + { // Custom Stringer() - type |
| 76 | + log.Info("Custom Stringer value", "2562047h47m16.854s", common.PrettyDuration(time.Duration(9223372036854775807))) |
| 77 | + } |
| 78 | + { // Lazy eval |
| 79 | + log.Info("Lazy evaluation of value", "key", log.Lazy{Fn: func() interface{} { return "lazy value" }}) |
| 80 | + } |
| 81 | + return nil |
| 82 | +} |
0 commit comments