Skip to content

Commit

Permalink
fix panic (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: crazycs <chen.two.cs@gmail.com>
  • Loading branch information
crazycs520 authored Dec 8, 2021
1 parent e5c5906 commit 041a72e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions search_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ func parseLogItem(s string) (*pb.LogMessage, error) {
}
levelLeftBound := strings.Index(s[timeRightBound+1:], "[")
levelRightBound := strings.Index(s[timeRightBound+1:], "]")
if levelLeftBound == -1 || levelRightBound == -1 || levelLeftBound > levelRightBound {
return nil, fmt.Errorf("invalid log string: %s", s)
}
level := ParseLogLevel(s[timeRightBound+1+levelLeftBound+1 : timeRightBound+1+levelRightBound])
item := &pb.LogMessage{
Time: time,
Expand Down
8 changes: 8 additions & 0 deletions search_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`This is an invalid log blablabla][`,
`[2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
})

Expand Down Expand Up @@ -261,6 +262,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -282,6 +284,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -305,6 +308,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
},
},
Expand Down Expand Up @@ -332,6 +336,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -357,6 +362,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 7
Expand All @@ -367,6 +373,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 8
Expand All @@ -376,6 +383,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
expect: []string{
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 9
Expand Down

0 comments on commit 041a72e

Please sign in to comment.