good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
f89dd627
Unverified
Commit
f89dd627
authored
Feb 23, 2017
by
Péter Szilágyi
Browse files
Options
Downloads
Patches
Plain Diff
internal, log: support debug log prints, displaying log origins
parent
1ca20a26
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/debug/flags.go
+11
-3
11 additions, 3 deletions
internal/debug/flags.go
log/format.go
+50
-4
50 additions, 4 deletions
log/format.go
with
61 additions
and
7 deletions
internal/debug/flags.go
+
11
−
3
View file @
f89dd627
...
@@ -30,12 +30,12 @@ import (
...
@@ -30,12 +30,12 @@ import (
var
(
var
(
verbosityFlag
=
cli
.
IntFlag
{
verbosityFlag
=
cli
.
IntFlag
{
Name
:
"verbosity"
,
Name
:
"verbosity"
,
Usage
:
"Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=
core, 5=
debug,
6
=detail"
,
Usage
:
"Logging verbosity: 0=silent, 1=error, 2=warn, 3=info, 4=debug,
5
=detail"
,
Value
:
3
,
Value
:
3
,
}
}
vmoduleFlag
=
cli
.
StringFlag
{
vmoduleFlag
=
cli
.
StringFlag
{
Name
:
"vmodule"
,
Name
:
"vmodule"
,
Usage
:
"Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=
6
,p2p=
5
)"
,
Usage
:
"Per-module verbosity: comma-separated list of <pattern>=<level> (e.g. eth/*=
5
,p2p=
4
)"
,
Value
:
""
,
Value
:
""
,
}
}
backtraceAtFlag
=
cli
.
StringFlag
{
backtraceAtFlag
=
cli
.
StringFlag
{
...
@@ -43,6 +43,10 @@ var (
...
@@ -43,6 +43,10 @@ var (
Usage
:
"Request a stack trace at a specific logging statement (e.g.
\"
block.go:271
\"
)"
,
Usage
:
"Request a stack trace at a specific logging statement (e.g.
\"
block.go:271
\"
)"
,
Value
:
""
,
Value
:
""
,
}
}
debugFlag
=
cli
.
BoolFlag
{
Name
:
"debug"
,
Usage
:
"Prepends log messages with call-site location (file and line number)"
,
}
pprofFlag
=
cli
.
BoolFlag
{
pprofFlag
=
cli
.
BoolFlag
{
Name
:
"pprof"
,
Name
:
"pprof"
,
Usage
:
"Enable the pprof HTTP server"
,
Usage
:
"Enable the pprof HTTP server"
,
...
@@ -78,17 +82,21 @@ var (
...
@@ -78,17 +82,21 @@ var (
// Flags holds all command-line flags required for debugging.
// Flags holds all command-line flags required for debugging.
var
Flags
=
[]
cli
.
Flag
{
var
Flags
=
[]
cli
.
Flag
{
verbosityFlag
,
vmoduleFlag
,
backtraceAtFlag
,
verbosityFlag
,
vmoduleFlag
,
backtraceAtFlag
,
debugFlag
,
pprofFlag
,
pprofAddrFlag
,
pprofPortFlag
,
pprofFlag
,
pprofAddrFlag
,
pprofPortFlag
,
memprofilerateFlag
,
blockprofilerateFlag
,
cpuprofileFlag
,
traceFlag
,
memprofilerateFlag
,
blockprofilerateFlag
,
cpuprofileFlag
,
traceFlag
,
}
}
// glogger is the glog handler used by Geth, allowing the debug APIs to modify
// verbosity levels, vmodules and backtrace locations.
var
glogger
=
log
.
NewGlogHandler
(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
TerminalFormat
()))
var
glogger
=
log
.
NewGlogHandler
(
log
.
StreamHandler
(
os
.
Stderr
,
log
.
TerminalFormat
()))
// Setup initializes profiling and logging based on the CLI flags.
// Setup initializes profiling and logging based on the CLI flags.
// It should be called as early as possible in the program.
// It should be called as early as possible in the program.
func
Setup
(
ctx
*
cli
.
Context
)
error
{
func
Setup
(
ctx
*
cli
.
Context
)
error
{
// logging
// logging
log
.
PrintOrigins
(
ctx
.
GlobalBool
(
debugFlag
.
Name
))
glogger
.
Verbosity
(
log
.
Lvl
(
ctx
.
GlobalInt
(
verbosityFlag
.
Name
)))
glogger
.
Verbosity
(
log
.
Lvl
(
ctx
.
GlobalInt
(
verbosityFlag
.
Name
)))
glogger
.
Vmodule
(
ctx
.
GlobalString
(
vmoduleFlag
.
Name
))
glogger
.
Vmodule
(
ctx
.
GlobalString
(
vmoduleFlag
.
Name
))
glogger
.
BacktraceAt
(
ctx
.
GlobalString
(
backtraceAtFlag
.
Name
))
glogger
.
BacktraceAt
(
ctx
.
GlobalString
(
backtraceAtFlag
.
Name
))
...
...
This diff is collapsed.
Click to expand it.
log/format.go
+
50
−
4
View file @
f89dd627
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"strconv"
"strconv"
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"time"
"time"
)
)
...
@@ -18,6 +19,30 @@ const (
...
@@ -18,6 +19,30 @@ const (
termMsgJust
=
40
termMsgJust
=
40
)
)
// locationTrims are trimmed for display to avoid unwieldy log lines.
var
locationTrims
=
[]
string
{
"github.com/ethereum/go-ethereum/"
,
"github.com/ethereum/ethash/"
,
}
// PrintOrigins sets or unsets log location (file:line) printing for terminal
// format output.
func
PrintOrigins
(
print
bool
)
{
if
print
{
atomic
.
StoreUint32
(
&
locationEnabled
,
1
)
}
else
{
atomic
.
StoreUint32
(
&
locationEnabled
,
0
)
}
}
// locationEnabled is an atomic flag controlling whether the terminal formatter
// should append the log locations too when printing entries.
var
locationEnabled
uint32
// locationLength is the maxmimum path length encountered, which all logs are
// padded to to aid in alignment.
var
locationLength
uint32
type
Format
interface
{
type
Format
interface
{
Format
(
r
*
Record
)
[]
byte
Format
(
r
*
Record
)
[]
byte
}
}
...
@@ -64,12 +89,33 @@ func TerminalFormat() Format {
...
@@ -64,12 +89,33 @@ func TerminalFormat() Format {
b
:=
&
bytes
.
Buffer
{}
b
:=
&
bytes
.
Buffer
{}
lvl
:=
strings
.
ToUpper
(
r
.
Lvl
.
String
())
lvl
:=
strings
.
ToUpper
(
r
.
Lvl
.
String
())
if
atomic
.
LoadUint32
(
&
locationEnabled
)
!=
0
{
// Log origin printing was requested, format the location path and line number
location
:=
fmt
.
Sprintf
(
"%+v"
,
r
.
Call
)
for
_
,
prefix
:=
range
locationTrims
{
location
=
strings
.
TrimPrefix
(
location
,
prefix
)
}
// Maintain the maximum location length for fancyer alignment
align
:=
int
(
atomic
.
LoadUint32
(
&
locationLength
))
if
align
<
len
(
location
)
{
align
=
len
(
location
)
atomic
.
StoreUint32
(
&
locationLength
,
uint32
(
align
))
}
padding
:=
strings
.
Repeat
(
" "
,
align
-
len
(
location
))
// Assemble and print the log heading
if
color
>
0
{
fmt
.
Fprintf
(
b
,
"
\x1b
[%dm%s
\x1b
[0m[%s|%s]%s %s "
,
color
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
location
,
padding
,
r
.
Msg
)
}
else
{
fmt
.
Fprintf
(
b
,
"[%s] [%s|%s]%s %s "
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
location
,
padding
,
r
.
Msg
)
}
}
else
{
if
color
>
0
{
if
color
>
0
{
fmt
.
Fprintf
(
b
,
"
\x1b
[%dm%s
\x1b
[0m[%s] %s "
,
color
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
r
.
Msg
)
fmt
.
Fprintf
(
b
,
"
\x1b
[%dm%s
\x1b
[0m[%s] %s "
,
color
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
r
.
Msg
)
}
else
{
}
else
{
fmt
.
Fprintf
(
b
,
"[%s] [%s] %s "
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
r
.
Msg
)
fmt
.
Fprintf
(
b
,
"[%s] [%s] %s "
,
lvl
,
r
.
Time
.
Format
(
termTimeFormat
),
r
.
Msg
)
}
}
}
// try to justify the log output for short messages
// try to justify the log output for short messages
if
len
(
r
.
Ctx
)
>
0
&&
len
(
r
.
Msg
)
<
termMsgJust
{
if
len
(
r
.
Ctx
)
>
0
&&
len
(
r
.
Msg
)
<
termMsgJust
{
b
.
Write
(
bytes
.
Repeat
([]
byte
{
' '
},
termMsgJust
-
len
(
r
.
Msg
)))
b
.
Write
(
bytes
.
Repeat
([]
byte
{
' '
},
termMsgJust
-
len
(
r
.
Msg
)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment