Format applies the template on the provided event.
(evt *Event)
| 24 | |
| 25 | // Format applies the template on the provided event. |
| 26 | func (f *Formatter) Format(evt *Event) []byte { |
| 27 | if evt == nil { |
| 28 | return []byte{} |
| 29 | } |
| 30 | values := map[string]interface{}{ |
| 31 | ts: evt.Timestamp.String(), |
| 32 | pid: strconv.FormatUint(uint64(evt.PID), 10), |
| 33 | tid: strconv.FormatUint(uint64(evt.Tid), 10), |
| 34 | seq: strconv.FormatUint(evt.Seq, 10), |
| 35 | cpu: strconv.FormatUint(uint64(evt.CPU), 10), |
| 36 | typ: evt.Name, |
| 37 | cat: evt.Category, |
| 38 | desc: evt.Description, |
| 39 | host: evt.Host, |
| 40 | meta: evt.Metadata.String(), |
| 41 | parameters: evt.Params.String(), |
| 42 | } |
| 43 | |
| 44 | // add process metadata |
| 45 | ps := evt.PS |
| 46 | if ps != nil { |
| 47 | values[proc] = ps.Name |
| 48 | values[ppid] = strconv.FormatUint(uint64(ps.Ppid), 10) |
| 49 | values[cwd] = ps.Cwd |
| 50 | values[exe] = ps.Exe |
| 51 | values[cmd] = ps.Cmdline |
| 52 | values[sid] = ps.SID |
| 53 | parent := ps.Parent |
| 54 | if parent != nil { |
| 55 | values[pproc] = parent.Name |
| 56 | values[pexe] = parent.Exe |
| 57 | values[pcmd] = parent.Cmdline |
| 58 | } |
| 59 | if ps.PE != nil { |
| 60 | values[pe] = ps.PE.String() |
| 61 | } |
| 62 | } |
| 63 | // add callstack summary |
| 64 | if !evt.Callstack.IsEmpty() { |
| 65 | values[cstack] = evt.Callstack.String() |
| 66 | } |
| 67 | |
| 68 | if f.expandParamsDot { |
| 69 | // expand all parameters into the map, so we can ask |
| 70 | // for specific parameter names in the template |
| 71 | for _, par := range evt.Params { |
| 72 | values[".Params."+caser.String(par.Name)] = par.String() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | return f.t.ExecuteString(values) |
| 77 | } |