3
3
Copyright 2014-2016 Percona LLC and/or its affiliates
4
4
*/
5
5
6
- // Package slow implements a MySQL slow log parser.
6
+ // Package slowlog provides functions and data structures for working with the
7
+ // MySQL slow log.
7
8
package slowlog
8
9
9
10
import (
@@ -19,8 +20,8 @@ import (
19
20
)
20
21
21
22
var (
23
+ // ErrStarted is returned if Parser.Start is called more than once.
22
24
ErrStarted = errors .New ("parser is started" )
23
- ErrStopped = errors .New ("parser is stopped" )
24
25
)
25
26
26
27
// Options encapsulate common options for making a new LogParser.
@@ -29,7 +30,10 @@ type Options struct {
29
30
FilterAdminCommand map [string ]bool // admin commands to ignore
30
31
}
31
32
32
- // A LogParser sends events to a channel.
33
+ // A Parser parses events from a slow log. The canonical Parser is FileParser
34
+ // because the slow log is a file. The caller receives events on the Events
35
+ // channel. This channel is closed when there are no more events. Any error
36
+ // during parsing is returned by Error.
33
37
type Parser interface {
34
38
Start (Options ) error
35
39
Events () <- chan Event
@@ -47,7 +51,8 @@ var adminRe = regexp.MustCompile(`command: (.+)`)
47
51
var setRe = regexp .MustCompile (`^SET (?:last_insert_id|insert_id|timestamp)` )
48
52
var useRe = regexp .MustCompile (`^(?i)use ` )
49
53
50
- // A FileParser parses a MySQL slow log.
54
+ // FileParser represents a file-based Parser. This is the canonical Parser
55
+ // because the slow log is a file.
51
56
type FileParser struct {
52
57
file * os.File
53
58
// --
@@ -68,6 +73,7 @@ type FileParser struct {
68
73
var Debug = false
69
74
70
75
// NewFileParser returns a new FileParser that reads from the open file.
76
+ // The file is not closed.
71
77
func NewFileParser (file * os.File ) * FileParser {
72
78
p := & FileParser {
73
79
file : file ,
@@ -97,9 +103,9 @@ func (p *FileParser) Stop() {
97
103
return
98
104
}
99
105
100
- // Start starts the parser. Events are sent to the unbuffered event channel.
101
- // Parsing stops on EOF, error, or call to Stop. The event channel is closed
102
- // when parsing stops. The file is not closed.
106
+ // Start starts the parser. Events are sent to the unbuffered Events channel.
107
+ // Parsing stops on EOF, error, or call to Stop. The Events channel is closed
108
+ // when parsing stops.
103
109
func (p * FileParser ) Start (opt Options ) error {
104
110
if p .started {
105
111
return ErrStarted
@@ -122,10 +128,14 @@ func (p *FileParser) Start(opt Options) error {
122
128
return nil
123
129
}
124
130
131
+ // Events returns the channel to which events from the slow log are sent.
132
+ // The channel is closed when there are no more events. Events are not sent
133
+ // until Start is called.
125
134
func (p * FileParser ) Events () <- chan Event {
126
135
return p .eventChan
127
136
}
128
137
138
+ // Error returns an error, if any, encountered while parsing the slow log.
129
139
func (p * FileParser ) Error () error {
130
140
return p .err
131
141
}
0 commit comments