Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
8a9a73c9
Unverified
Commit
8a9a73c9
authored
2 years ago
by
Péter Szilágyi
Committed by
GitHub
2 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log: add special casing of uint256 into the logger (#26936)
parent
2ed8013f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
2 deletions
+66
-2
go.mod
go.mod
+1
-1
go.sum
go.sum
+4
-0
format.go
log/format.go
+41
-1
format_test.go
log/format_test.go
+20
-0
No files found.
go.mod
View file @
8a9a73c9
...
...
@@ -36,7 +36,7 @@ require (
github.com/graph-gophers/graphql-go v1.3.0
github.com/hashicorp/go-bexpr v0.1.10
github.com/holiman/bloomfilter/v2 v2.0.3
github.com/holiman/uint256 v1.2.
0
github.com/holiman/uint256 v1.2.
2-0.20230321075855-87b91420868c
github.com/huin/goupnp v1.0.3
github.com/influxdata/influxdb v1.8.3
github.com/influxdata/influxdb-client-go/v2 v2.4.0
...
...
This diff is collapsed.
Click to expand it.
go.sum
View file @
8a9a73c9
...
...
@@ -297,6 +297,10 @@ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZ
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.1 h1:XRtyuda/zw2l+Bq/38n5XUoEF72aSOu/77Thd9pPp2o=
github.com/holiman/uint256 v1.2.1/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8=
github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y=
...
...
This diff is collapsed.
Click to expand it.
log/format.go
View file @
8a9a73c9
...
...
@@ -12,6 +12,8 @@ import (
"sync/atomic"
"time"
"unicode/utf8"
"github.com/holiman/uint256"
)
const
(
...
...
@@ -339,12 +341,20 @@ func formatLogfmtValue(value interface{}, term bool) string {
return
v
.
Format
(
timeFormat
)
case
*
big
.
Int
:
// Big ints get consumed by the Stringer clause so we need to handle
// Big ints get consumed by the Stringer clause
,
so we need to handle
// them earlier on.
if
v
==
nil
{
return
"<nil>"
}
return
formatLogfmtBigInt
(
v
)
case
*
uint256
.
Int
:
// Uint256s get consumed by the Stringer clause, so we need to handle
// them earlier on.
if
v
==
nil
{
return
"<nil>"
}
return
formatLogfmtUint256
(
v
)
}
if
term
{
if
s
,
ok
:=
value
.
(
TerminalStringer
);
ok
{
...
...
@@ -469,6 +479,36 @@ func formatLogfmtBigInt(n *big.Int) string {
return
string
(
buf
[
i
+
1
:
])
}
// formatLogfmtUint256 formats n with thousand separators.
func
formatLogfmtUint256
(
n
*
uint256
.
Int
)
string
{
if
n
.
IsUint64
()
{
return
FormatLogfmtUint64
(
n
.
Uint64
())
}
var
(
text
=
n
.
Dec
()
buf
=
make
([]
byte
,
len
(
text
)
+
len
(
text
)
/
3
)
comma
=
0
i
=
len
(
buf
)
-
1
)
for
j
:=
len
(
text
)
-
1
;
j
>=
0
;
j
,
i
=
j
-
1
,
i
-
1
{
c
:=
text
[
j
]
switch
{
case
c
==
'-'
:
buf
[
i
]
=
c
case
comma
==
3
:
buf
[
i
]
=
','
i
--
comma
=
0
fallthrough
default
:
buf
[
i
]
=
c
comma
++
}
}
return
string
(
buf
[
i
+
1
:
])
}
// escapeString checks if the provided string needs escaping/quoting, and
// calls strconv.Quote if needed
func
escapeString
(
s
string
)
string
{
...
...
This diff is collapsed.
Click to expand it.
log/format_test.go
View file @
8a9a73c9
...
...
@@ -7,6 +7,8 @@ import (
"math/rand"
"strings"
"testing"
"github.com/holiman/uint256"
)
func
TestPrettyInt64
(
t
*
testing
.
T
)
{
...
...
@@ -80,6 +82,24 @@ func TestPrettyBigInt(t *testing.T) {
}
}
func
TestPrettyUint256
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
int
string
s
string
}{
{
"111222333444555678999"
,
"111,222,333,444,555,678,999"
},
{
"11122233344455567899900"
,
"11,122,233,344,455,567,899,900"
},
}
for
_
,
tt
:=
range
tests
{
v
:=
new
(
uint256
.
Int
)
v
.
SetFromDecimal
(
tt
.
int
)
if
have
:=
formatLogfmtUint256
(
v
);
have
!=
tt
.
s
{
t
.
Errorf
(
"invalid output %s, want %s"
,
have
,
tt
.
s
)
}
}
}
var
sink
string
func
BenchmarkPrettyInt64Logfmt
(
b
*
testing
.
B
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment