Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
1c16ecd0
Unverified
Commit
1c16ecd0
authored
6 years ago
by
Sean Young
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #743 from silasdavis/file-logging-instruction
Add file and json logging instructions.
parents
d0122f97
2eb748a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
logging/config/presets/instructions.go
+64
-28
64 additions, 28 deletions
logging/config/presets/instructions.go
logging/config/presets/instructions_test.go
+10
-0
10 additions, 0 deletions
logging/config/presets/instructions_test.go
with
74 additions
and
28 deletions
logging/config/presets/instructions.go
+
64
−
28
View file @
1c16ecd0
...
...
@@ -13,13 +13,14 @@ import (
// Returning the new subroot from which to apply any further Presets.
// When chained together in a pre-order instructions can be composed to form an entire Sink tree.
type
Instruction
struct
{
name
string
desc
string
name
string
desc
string
nargs
int
// The builder for the Instruction is a function that may modify the stack or ops string. Typically
// by mutating the sink at the top of the stack and may move the cursor or by pushing child sinks
// to the stack. The builder may also return a modified ops slice whereby it may insert Instruction calls
// acting as a macro or consume ops as arguments.
builder
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
builder
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
}
func
(
i
Instruction
)
Name
()
string
{
...
...
@@ -37,88 +38,113 @@ const (
Stderr
=
"stderr"
Stdout
=
"stdout"
Terminal
=
"terminal"
JSON
=
"json"
Up
=
"up"
Down
=
"down"
File
=
"file"
)
var
instructions
=
[]
Instruction
{
{
name
:
Up
,
desc
:
"Ascend the sink tree by travelling up the stack to the previous sink recorded on the stack"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
return
pop
(
stack
),
ops
,
nil
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
return
pop
(
stack
),
nil
},
},
{
name
:
Down
,
desc
:
"Descend the sink tree by inserting a sink as a child to the current sink and adding it to the stack"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
return
push
(
stack
,
config
.
Sink
()),
ops
,
nil
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
return
push
(
stack
,
config
.
Sink
()),
nil
},
},
{
name
:
Minimal
,
desc
:
"A generally less chatty log output, follow with output options"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
return
push
(
stack
,
config
.
Sink
()
.
SetTransform
(
config
.
PruneTransform
(
structure
.
TraceKey
,
structure
.
RunId
)),
config
.
Sink
()
.
SetTransform
(
config
.
FilterTransform
(
config
.
IncludeWhenAllMatch
,
structure
.
ChannelKey
,
structure
.
InfoChannelName
)),
config
.
Sink
()
.
SetTransform
(
config
.
FilterTransform
(
config
.
ExcludeWhenAnyMatches
,
structure
.
ComponentKey
,
"Tendermint"
,
"module"
,
"p2p"
,
"module"
,
"mempool"
))),
ops
,
nil
config
.
Sink
()
.
SetTransform
(
config
.
PruneTransform
(
structure
.
TraceKey
,
structure
.
RunId
)),
config
.
Sink
()
.
SetTransform
(
config
.
FilterTransform
(
config
.
IncludeWhenAllMatch
,
structure
.
ChannelKey
,
structure
.
InfoChannelName
)),
config
.
Sink
()
.
SetTransform
(
config
.
FilterTransform
(
config
.
ExcludeWhenAnyMatches
,
structure
.
ComponentKey
,
"Tendermint"
,
"module"
,
"p2p"
,
"module"
,
"mempool"
))),
nil
},
},
{
name
:
IncludeAny
,
desc
:
"Establish an 'include when any predicate matches' filter transform at this this sink"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureFilter
(
sink
)
sink
.
Transform
.
FilterConfig
.
FilterMode
=
config
.
IncludeWhenAnyMatches
return
stack
,
ops
,
nil
return
stack
,
nil
},
},
{
name
:
Info
,
desc
:
"Add a filter predicate to match the Info logging channel"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureFilter
(
sink
)
sink
.
Transform
.
FilterConfig
.
AddPredicate
(
structure
.
ChannelKey
,
structure
.
InfoChannelName
)
return
stack
,
ops
,
nil
return
stack
,
nil
},
},
{
name
:
Stdout
,
desc
:
"Use Stdout output for this sink"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureOutput
(
sink
)
sink
.
Output
.
OutputType
=
config
.
Stdout
return
stack
,
ops
,
nil
return
stack
,
nil
},
},
{
name
:
Stderr
,
desc
:
"Use Stderr output for this sink"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureOutput
(
sink
)
sink
.
Output
.
OutputType
=
config
.
Stderr
return
stack
,
ops
,
nil
return
stack
,
nil
},
},
{
name
:
Terminal
,
desc
:
"Use the the terminal output format for this sink"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
op
s
[]
string
)
([]
*
config
.
SinkConfig
,
[]
string
,
error
)
{
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
arg
s
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureOutput
(
sink
)
sink
.
Output
.
Format
=
loggers
.
TerminalFormat
return
stack
,
ops
,
nil
return
stack
,
nil
},
},
{
name
:
JSON
,
desc
:
"Use the the terminal output format for this sink"
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
args
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureOutput
(
sink
)
sink
.
Output
.
Format
=
loggers
.
JSONFormat
return
stack
,
nil
},
},
{
name
:
File
,
desc
:
"Use the the terminal output format for this sink"
,
nargs
:
1
,
builder
:
func
(
stack
[]
*
config
.
SinkConfig
,
args
[]
string
)
([]
*
config
.
SinkConfig
,
error
)
{
sink
:=
peek
(
stack
)
ensureOutput
(
sink
)
sink
.
Output
.
OutputType
=
config
.
File
sink
.
Output
.
FileConfig
=
&
config
.
FileConfig
{
Path
:
args
[
0
],
}
return
stack
,
nil
},
},
}
...
...
@@ -149,16 +175,26 @@ func Describe(name string) string {
func
BuildSinkConfig
(
ops
...
string
)
(
*
config
.
SinkConfig
,
error
)
{
stack
:=
[]
*
config
.
SinkConfig
{
config
.
Sink
()}
var
err
error
pos
:=
0
for
len
(
ops
)
>
0
{
// Keep applying instructions until their are no ops left
preset
,
ok
:=
instructionsMap
[
ops
[
0
]]
instruction
,
ok
:=
instructionsMap
[
ops
[
0
]]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"could not find logging preset '%s'"
,
ops
[
0
])
}
stack
,
ops
,
err
=
preset
.
builder
(
stack
,
ops
[
1
:
])
// pop instruction name
ops
=
ops
[
1
:
]
if
len
(
ops
)
<
instruction
.
nargs
{
return
nil
,
fmt
.
Errorf
(
"did not have enough arguments for instruction %s at position %v "
+
"(requires %v arguments)"
,
instruction
.
name
,
pos
,
instruction
.
nargs
)
}
stack
,
err
=
instruction
.
builder
(
stack
,
ops
[
:
instruction
.
nargs
])
if
err
!=
nil
{
return
nil
,
err
}
// pop instruction args
ops
=
ops
[
instruction
.
nargs
:
]
pos
++
}
return
stack
[
0
],
nil
}
...
...
This diff is collapsed.
Click to expand it.
logging/config/presets/instructions_test.go
+
10
−
0
View file @
1c16ecd0
...
...
@@ -39,3 +39,13 @@ func TestMinimalPreset(t *testing.T) {
//fmt.Println(config.TOMLString(expectedSink), "\n", config.TOMLString(builtSink))
assert
.
Equal
(
t
,
config
.
TOMLString
(
expectedSink
),
config
.
TOMLString
(
builtSink
))
}
func
TestFileOutput
(
t
*
testing
.
T
)
{
path
:=
"foo.log"
builtSink
,
err
:=
BuildSinkConfig
(
Down
,
File
,
path
,
JSON
)
require
.
NoError
(
t
,
err
)
expectedSink
:=
config
.
Sink
()
.
AddSinks
(
config
.
Sink
()
.
SetOutput
(
config
.
FileOutput
(
path
)
.
SetFormat
(
loggers
.
JSONFormat
)))
//fmt.Println(config.TOMLString(expectedSink), "\n", config.TOMLString(builtSink))
assert
.
Equal
(
t
,
config
.
TOMLString
(
expectedSink
),
config
.
TOMLString
(
builtSink
))
}
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