ltsv.go 604 B

123456789101112131415161718192021222324252627
  1. package axslogparser
  2. import (
  3. "strings"
  4. "time"
  5. "github.com/Songmu/go-ltsv"
  6. "github.com/pkg/errors"
  7. )
  8. // LTSV access log parser
  9. type LTSV struct {
  10. }
  11. // Parse for Parser interface
  12. func (lv *LTSV) Parse(line string) (*Log, error) {
  13. l := &Log{}
  14. err := ltsv.Unmarshal([]byte(line), l)
  15. if err != nil {
  16. return nil, errors.Wrapf(err, "failed to parse ltsvlog (not a ltsv): %s", line)
  17. }
  18. l.Time, _ = time.Parse(clfTimeLayout, strings.Trim(l.TimeStr, "[]"))
  19. if err := l.breakdownRequest(); err != nil {
  20. return nil, errors.Wrap(err, "failed to parse ltsvlog (invalid request)")
  21. }
  22. return l, nil
  23. }