Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishapi
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishapi
Commits
663ffc5c
Commit
663ffc5c
authored
Aug 08, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encapsulate the Tag type, and have it implement the Stringer interface.
parent
90c90809
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
20 deletions
+29
-20
log.go
pkg/log/log.go
+27
-18
log_test.go
pkg/log/log_test.go
+2
-2
No files found.
pkg/log/log.go
View file @
663ffc5c
...
@@ -171,7 +171,7 @@ const (
...
@@ -171,7 +171,7 @@ const (
// above.
// above.
type
RecordType
uint8
type
RecordType
uint8
func
t
ags
()
[]
string
{
func
initT
ags
()
[]
string
{
var
tags
[]
string
var
tags
[]
string
if
uint8
(
C
.
slt_max
())
>
^
uint8
(
0
)
{
if
uint8
(
C
.
slt_max
())
>
^
uint8
(
0
)
{
panic
(
"SLT__MAX > max uint8"
)
panic
(
"SLT__MAX > max uint8"
)
...
@@ -188,18 +188,28 @@ func tags() []string {
...
@@ -188,18 +188,28 @@ func tags() []string {
}
}
var
(
var
(
// Tags is an array of strings indexed by the Tag field of a
tags
=
initTags
()
// Record, classifying the Record's contents, as in the second
// column of default varnishlog output. Examples are "ReqURL"
// for a client request URL and "BerespStatus" for the HTTP
// status of a backend response.
//
// If Tags[i] == "", then no tag exists for index i.
Tags
=
tags
()
nonprint
=
regexp
.
MustCompile
(
"[^[:print:]]"
)
nonprint
=
regexp
.
MustCompile
(
"[^[:print:]]"
)
cbMap
=
make
(
map
[
int
]
ReadCB
)
cbMap
=
make
(
map
[
int
]
ReadCB
)
)
)
// A Tag is a classifier for the contents of a Record's payload,
// corresponding to the second column of default varnishlog
// output. For a Tag t, t.String() may be "ReqURL" for a client
// request URL, "BerespStatus" for the HTTP status of a backend
// response, and so forth.
type
Tag
uint8
// String returns the Tag name that appears in the second column of
// default varnishlog output, such as "ReqHeader" for a client request
// header, or "BerespHeader" for a backend response header.
//
// If t.String() == "", then no tag exists for Tag t. No such tag is
// generated from log reads.
func
(
tag
Tag
)
String
()
string
{
return
tags
[
tag
]
}
// A Record in the Varnish log, corresponding to a line of output from
// A Record in the Varnish log, corresponding to a line of output from
// the varnishlog utility. Instances of this type are contained in the
// the varnishlog utility. Instances of this type are contained in the
// Tx objects returned by Read() operations, and form the bulk of log
// Tx objects returned by Read() operations, and form the bulk of log
...
@@ -213,12 +223,11 @@ type Record struct {
...
@@ -213,12 +223,11 @@ type Record struct {
// backend log, or neither.
// backend log, or neither.
Type
RecordType
Type
RecordType
// An index into the Tags array, classifying the contents of
// A classifier for the contents of this Record's payload. Use
// this record, as in the second column of default varnishlog
// Tag.String() to get tag names such as "ReqURL" or
// output. For a Tag t, Tags[t] may be a string such as
// "BerespHeader" that appear in the second column of default
// "ReqURL" for a client request URL, "BerespStatus" for the
// varnishlog output.
// HTTP status of a backend response, and so forth.
Tag
Tag
Tag
uint8
// The unique ID generated by Varnish for this log
// The unique ID generated by Varnish for this log
// transaction.
// transaction.
...
@@ -383,14 +392,14 @@ func publish(trans unsafe.Pointer, priv unsafe.Pointer) C.int {
...
@@ -383,14 +392,14 @@ func publish(trans unsafe.Pointer, priv unsafe.Pointer) C.int {
break
break
}
}
tag
:=
C
.
tag
(
vtx
.
c
)
tag
:=
C
.
tag
(
vtx
.
c
)
if
tag
<
0
||
int
(
tag
)
>=
len
(
T
ags
)
{
if
tag
<
0
||
int
(
tag
)
>=
len
(
t
ags
)
{
panic
(
"tag index out of range"
)
panic
(
"tag index out of range"
)
}
}
if
T
ags
[
tag
]
==
""
{
if
t
ags
[
tag
]
==
""
{
panic
(
"unknown tag"
)
panic
(
"unknown tag"
)
}
}
rec
:=
new
(
Record
)
rec
:=
new
(
Record
)
rec
.
Tag
=
uint8
(
tag
)
rec
.
Tag
=
Tag
(
tag
)
rec
.
Payload
=
C
.
GoStringN
(
C
.
cdata
(
vtx
.
c
),
C
.
len
(
vtx
.
c
))
rec
.
Payload
=
C
.
GoStringN
(
C
.
cdata
(
vtx
.
c
),
C
.
len
(
vtx
.
c
))
if
C
.
unsafe
(
tag
)
!=
0
||
C
.
binary
(
tag
)
!=
0
{
if
C
.
unsafe
(
tag
)
!=
0
||
C
.
binary
(
tag
)
!=
0
{
nonprint
.
ReplaceAllStringFunc
(
rec
.
Payload
,
nonprint
.
ReplaceAllStringFunc
(
rec
.
Payload
,
...
...
pkg/log/log_test.go
View file @
663ffc5c
...
@@ -221,8 +221,8 @@ func TestDefaultRead(t *testing.T) {
...
@@ -221,8 +221,8 @@ func TestDefaultRead(t *testing.T) {
t
.
Errorf
(
"rec vxid expected=%v got=%v"
,
t
.
Errorf
(
"rec vxid expected=%v got=%v"
,
expRec
.
vxid
,
rec
.
VXID
)
expRec
.
vxid
,
rec
.
VXID
)
}
}
if
Tags
[
rec
.
Tag
]
!=
expRec
.
tag
{
if
rec
.
Tag
.
String
()
!=
expRec
.
tag
{
t
.
Errorf
(
"rec tag expected=%v got=%
v
"
,
t
.
Errorf
(
"rec tag expected=%v got=%
s
"
,
expRec
.
tag
,
rec
.
Tag
)
expRec
.
tag
,
rec
.
Tag
)
}
}
if
rune
(
rec
.
Type
)
!=
expRec
.
rectype
{
if
rune
(
rec
.
Type
)
!=
expRec
.
rectype
{
...
...
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