Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
exchain
nebula
Commits
d87c88d5
Unverified
Commit
d87c88d5
authored
Jun 04, 2024
by
zhiqiangxu
Committed by
GitHub
Jun 04, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add `log.pid` to enable showing pid in log (#10722)
* show pid in log * add Pid to cli config
parent
c4226bf4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
cli.go
op-service/log/cli.go
+14
-1
No files found.
op-service/log/cli.go
View file @
d87c88d5
...
...
@@ -20,6 +20,7 @@ const (
LevelFlagName
=
"log.level"
FormatFlagName
=
"log.format"
ColorFlagName
=
"log.color"
PidFlagName
=
"log.pid"
)
func
CLIFlags
(
envPrefix
string
)
[]
cli
.
Flag
{
...
...
@@ -51,6 +52,12 @@ func CLIFlagsWithCategory(envPrefix string, category string) []cli.Flag {
EnvVars
:
opservice
.
PrefixEnvVar
(
envPrefix
,
"LOG_COLOR"
),
Category
:
category
,
},
&
cli
.
BoolFlag
{
Name
:
PidFlagName
,
Usage
:
"Show pid in the log"
,
EnvVars
:
opservice
.
PrefixEnvVar
(
envPrefix
,
"LOG_PID"
),
Category
:
category
,
},
}
}
...
...
@@ -187,6 +194,7 @@ type CLIConfig struct {
Level
slog
.
Level
Color
bool
Format
FormatType
Pid
bool
}
// AppOut returns an io.Writer to write app output to, like logs.
...
...
@@ -208,7 +216,11 @@ func NewLogHandler(wr io.Writer, cfg CLIConfig) slog.Handler {
// The log handler of the logger is a LvlSetter, i.e. the log level can be changed as needed.
func
NewLogger
(
wr
io
.
Writer
,
cfg
CLIConfig
)
log
.
Logger
{
h
:=
NewLogHandler
(
wr
,
cfg
)
return
log
.
NewLogger
(
h
)
l
:=
log
.
NewLogger
(
h
)
if
cfg
.
Pid
{
l
=
l
.
With
(
"pid"
,
os
.
Getpid
())
}
return
l
}
// SetGlobalLogHandler sets the log handles as the handler of the global default logger.
...
...
@@ -237,5 +249,6 @@ func ReadCLIConfig(ctx *cli.Context) CLIConfig {
if
ctx
.
IsSet
(
ColorFlagName
)
{
cfg
.
Color
=
ctx
.
Bool
(
ColorFlagName
)
}
cfg
.
Pid
=
ctx
.
Bool
(
PidFlagName
)
return
cfg
}
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