// <29>Dec 4 11:02:35 pdns[2030]: func parse_3164(data []byte) (syslog5424.Message, error) { part := FieldsFuncN(string(data), 10, get_3164tokenizer()) switch len(part) { case 0, 1, 2, 3: return syslog5424.EmptyMessage(), errors.New("wrong format 3164 : " + string(data)) case 4: prio, err := strconv.Atoi(part[0]) if err != nil { return syslog5424.EmptyMessage(), errors.New("Wrong Priority :" + string(part[0])) } return syslog5424.CreateMessage(part[2], syslog5424.Priority(prio), part[3]).Stamp(part[1]), nil default: prio, err := strconv.Atoi(part[0]) if err != nil { return syslog5424.EmptyMessage(), errors.New("Wrong Priority :" + string(part[0])) } return syslog5424.CreateMessage(part[2], syslog5424.Priority(prio), part[4]).Stamp(part[1]).ProcID(part[3]), nil } }
// statefull parser for linux printk() message buffer // // BUG(nath): may need some generic API func ParseMessage_KLog(boot_ts time.Time, data string) (syslog5424.Message, error) { log.SetFlags(log.Ltime | log.Lshortfile) part := FieldsFuncN(data, 4, get_klog_tokenizer()) if len(part) < 4 { log.Println(data) for pi := range part { log.Println(part[pi]) } } switch len(part) { case 2: prio, err := strconv.Atoi(part[0]) if err != nil { return syslog5424.EmptyMessage(), errors.New("Wrong Priority :" + string(part[0])) } return syslog5424.CreateMessage("-", syslog5424.Priority(prio), part[2]), nil case 3: // (kern) 0 * 8 + 6 (info) return syslog5424.CreateMessage("-", syslog5424.Priority(6), part[2]).Delta(boot_ts, part[0], part[1]), nil case 4: prio, err := strconv.Atoi(part[0]) if err != nil { return syslog5424.EmptyMessage(), errors.New("Wrong Priority :" + string(part[0])) } return syslog5424.CreateMessage("-", syslog5424.Priority(prio), part[3]).Delta(boot_ts, part[1], part[2]), nil default: // (kern) 0 * 8 + 6 (info) return syslog5424.CreateMessage("-", syslog5424.Priority(6), data), nil } }