Пример #1
0
func (o *StdoutOutput) Encode(ev *message.Event) (buffer.Sizer, error) {
	var err error
	b := &bytes.Buffer{}
	if o.tmpl != nil {
		err = o.tmpl.Execute(b, ev)
	} else {
		fmt.Fprintf(b, "[%s] %v: ", ev.Tag, ev.Time)
		err = json.NewEncoder(b).Encode(ev.Record)
	}
	if err != nil {
		return nil, err
	}
	return buffer.BytesItem(bytes.TrimRight(b.Bytes(), "\n")), nil
}
Пример #2
0
func (p *OutFile) Encode(ev *message.Event) (buffer.Sizer, error) {
	var err error
	b := new(bytes.Buffer)
	if p.tmpl != nil {
		err = p.tmpl.Execute(b, ev)
		b.Write([]byte{'\n'})
	} else {
		fmt.Fprintf(b, "[%s] %v: ", ev.Tag, ev.Time)
		err = json.NewEncoder(b).Encode(ev.Record)
	}
	if err != nil {
		return nil, err
	}
	return buffer.BytesItem(b.Bytes()), nil
}
Пример #3
0
func (o *ForwardOutput) Encode(ev *message.Event) (buffer.Sizer, error) {
	var v []interface{}
	if o.conf.Compatible == CompatibleDisable {
		v = []interface{}{ev.Tag, ev.Time, ev.Record}
	} else {
		v = []interface{}{ev.Tag, ev.Time.Unix(), ev.Record}
	}
	b, err := encode(v)
	if err != nil {
		return nil, err
	}
	if o.ackEnabled {
		// temporary invalid msgpack data, it will be corrected before sending
		b[0] = 0x94
	}
	return buffer.BytesItem(b), nil
}
Пример #4
0
func (o *ElasticsearchOutput) Encode(ev *message.Event) (buffer.Sizer, error) {
	index := o.conf.IndexName

	if o.conf.LogstashFormat {
		if _, ok := ev.Record["@timestamp"]; !ok {
			ev.Record["@timestamp"] = ev.Time.Format("2006-01-02T15:04:05.000-07:00")
		}
		index = ev.Time.In(o.utc).Format(o.conf.LogstashPrefix + "-" + o.conf.LogstashDateFormat)
	}
	if o.conf.TagKey != "" {
		ev.Record[o.conf.TagKey] = ev.Tag
	}

	action := map[string]string{
		"_index": index,
		"_type":  o.conf.TypeName,
	}
	if o.conf.IDKey != "" {
		if v, ok := ev.Record[o.conf.IDKey].(string); ok {
			action["_id"] = v
		}
	}
	if o.conf.ParentKey != "" {
		if v, ok := ev.Record[o.conf.ParentKey].(string); ok {
			action["_parent"] = v
		}
	}

	b1, err := json.Marshal(map[string]interface{}{"index": action})
	if err != nil {
		return nil, err
	}
	b2, err := json.Marshal(ev.Record)
	if err != nil {
		return nil, err
	}
	b := append(b1, '\n')
	b = append(b, b2...)
	b = append(b, '\n')
	return buffer.BytesItem(b), nil
}