Permalink
Browse files

fix parsing keys without values

  • Loading branch information...
Ryan R. Smith (ace hacker)
Ryan R. Smith (ace hacker) committed Feb 24, 2012
1 parent 0102bcb commit 48b5d1a0d07395cfb7f3de2ec0c7fc880f6460e8
Showing with 12 additions and 17 deletions.
  1. +5 −1 CHANGELOG
  2. +3 −2 wcld.go
  3. +4 −14 wcld_test.go
View
@@ -1,4 +1,8 @@
-v0.0.2 2012-02-21 Ryan Smith <ryan@heroku.com>
+v0.0.4 2012-02-24 Ryan Smith <ryan@heroku.com>
+
+* convert data that looks like: k= into this: k=""
+
+v0.0.3 2012-02-21 Ryan Smith <ryan@heroku.com>
* correct escaping issue
* rely on syslog regex for time parsing
View
@@ -83,10 +83,11 @@ func toHstore(logLine string) string {
if hasSig != nil {
for i, elt := range words {
- if strings.Contains(elt, "=") {
+ if kvSig.MatchString(elt) {
kvs += elt
+ } else if m, _ := regexp.MatchString(`\w+=`, elt); m == true {
+ kvs += elt + `""`
} else {
- elt = strings.Replace(elt, `"`, `'`, -1)
kvs += `"` + elt + `"` + "=true"
}
if i != max {
View
@@ -5,9 +5,8 @@ import (
)
func TestToHstore(t *testing.T) {
- actual := toHstore(`150 <13>1 2012-02-14T00:44:30+00:00 d.39c761b5-2e3a-4f93-9e68-2549c85650e2 app web.4 - - test name=ryan age=25 height-feet=6 height-inches=5 weight_lbs=210 _ssn=123 fav_quote="oh hai"`)
- expected := `"test"=>true, name=>ryan, age=>25, height-feet=>6, height-inches=>5, weight_lbs=>210, _ssn=>123, fav_quote=>"oh hai"`
-
+ actual := toHstore(`150 <13>1 2012-02-14T00:44:30+00:00 d.39c761b5-2e3a-4f93-9e68-2549c85650e2 app web.4 - - test name=ryan age=25 height-feet=6 height-inches=5 weight_lbs=210 _ssn=123 description= fav_quote="oh hai"`)
+ expected := `"test"=>true, name=>ryan, age=>25, height-feet=>6, height-inches=>5, weight_lbs=>210, _ssn=>123, description=>"", fav_quote=>"oh hai"`
if actual != expected {
t.Errorf("\n e(%v) \n a(%v)", expected, actual)
@@ -42,9 +41,9 @@ func TestToHstoreOnSQLLine(t *testing.T) {
}
func TestParseSysLog(t *testing.T) {
- match := syslogData.FindStringSubmatch(`150 <13>1 2012-02-14T00:44:30+00:00 d.39c761b5-2e3a-4f93-9e68-2549c85650e2 app web.4 - - INFO: provider=3 #api_prepare_body key=value time="2012-01-01 00:00:00"`)
+ match := syslogData.FindStringSubmatch(`150 <13>1 2012-02-14T00:44:30+00:00 d.39c761b5-2e3a-4f93-9e68-2549c85650e2 app web.4 - - info=true provider=3 #api_prepare_body key=value time="2012-01-01 00:00:00"`)
actual := match[10]
- expected := `INFO: provider=3 #api_prepare_body key=value time="2012-01-01 00:00:00"`
+ expected := `info=true provider=3 #api_prepare_body key=value time="2012-01-01 00:00:00"`
if actual != expected {
t.Errorf("\n e(%v) \n a(%v)", expected, actual)
@@ -59,13 +58,4 @@ func TestParseTime(t *testing.T) {
if actual != expected {
t.Errorf("\n e(%v) \n a(%v)", expected, actual)
}
-
- match := syslogData.FindStringSubmatch(`189 <13>1 2012-02-21T21:29:42+00:00 d.cbebea67-08d1-4152-a3e9-b721deaeed72 app slugc.288 - - slugc utils bash command='du --exclude gems --exclude slugs -s /app/tmp/repo.git', timeout_secs=600`)
- actual := match[3]
- expected := "2012-02-14T00:44:30+00:00"
-
- if actual != expected {
- t.Errorf("\n e(%v) \n a(%v)", expected, actual)
- }
-
}

0 comments on commit 48b5d1a

Please sign in to comment.