2016-05-07 17:42:01 +00:00
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
2016-02-13 00:20:04 +00:00
2016-02-19 21:08:25 +00:00
package logging
2016-02-10 20:09:07 +00:00
import (
2016-07-06 16:02:00 +00:00
"bytes"
2016-02-19 23:15:59 +00:00
"log"
"os"
2016-02-10 20:09:07 +00:00
"testing"
2016-09-04 21:03:36 +00:00
syslog "github.com/RackSec/srslog"
2016-02-10 20:09:07 +00:00
)
func TestLogParser_Priority ( t * testing . T ) {
2017-07-21 19:14:54 +00:00
t . Parallel ( )
2016-02-10 20:09:07 +00:00
line := [ ] byte ( "<30>2016-02-10T10:16:43-08:00 d-thinkpad docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf" )
2016-02-19 23:15:59 +00:00
d := NewDockerLogParser ( log . New ( os . Stdout , "" , log . LstdFlags ) )
2016-02-10 22:40:26 +00:00
p , _ , err := d . parsePriority ( line )
2016-02-10 20:09:07 +00:00
if err != nil {
t . Fatalf ( "got an err: %v" , err )
}
2016-02-11 02:47:46 +00:00
if p . Severity != syslog . LOG_INFO {
t . Fatalf ( "expected serverity: %v, got: %v" , syslog . LOG_INFO , p . Severity )
2016-02-10 20:09:07 +00:00
}
2016-02-10 22:40:26 +00:00
idx := d . logContentIndex ( line )
2016-07-06 16:02:00 +00:00
expected := bytes . Index ( line , [ ] byte ( "1:C 10 Feb 18:16:43.391" ) )
2016-02-10 22:40:26 +00:00
if idx != expected {
t . Fatalf ( "expected idx: %v, got: %v" , expected , idx )
}
2016-02-10 20:09:07 +00:00
}
2016-07-06 15:57:06 +00:00
func TestLogParser_Priority_UnixFormatter ( t * testing . T ) {
2017-07-21 19:14:54 +00:00
t . Parallel ( )
2016-07-06 15:57:06 +00:00
line := [ ] byte ( "<30>Feb 6, 10:16:43 docker/e2a1e3ebd3a3[22950]: 1:C 10 Feb 18:16:43.391 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf" )
d := NewDockerLogParser ( log . New ( os . Stdout , "" , log . LstdFlags ) )
p , _ , err := d . parsePriority ( line )
if err != nil {
t . Fatalf ( "got an err: %v" , err )
}
if p . Severity != syslog . LOG_INFO {
t . Fatalf ( "expected serverity: %v, got: %v" , syslog . LOG_INFO , p . Severity )
}
idx := d . logContentIndex ( line )
2016-07-06 16:02:00 +00:00
expected := bytes . Index ( line , [ ] byte ( "1:C 10 Feb 18:16:43.391" ) )
2016-07-06 15:57:06 +00:00
if idx != expected {
t . Fatalf ( "expected idx: %v, got: %v" , expected , idx )
}
}