github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/models/logs.go (about) 1 // Copyright 2023 iLogtail Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package models 16 17 import "github.com/alibaba/ilogtail/pkg/util" 18 19 type LogContents KeyValues[interface{}] 20 21 type Log struct { 22 Name string 23 Level string 24 SpanID string 25 TraceID string 26 Tags Tags 27 Timestamp uint64 28 ObservedTimestamp uint64 29 Offset uint64 30 RawSize uint64 31 Contents LogContents 32 } 33 34 func (m *Log) GetName() string { 35 if m != nil { 36 return m.Name 37 } 38 return "" 39 } 40 41 func (m *Log) SetName(name string) { 42 if m != nil { 43 m.Name = name 44 } 45 } 46 47 func (m *Log) GetTags() Tags { 48 if m != nil { 49 return m.Tags 50 } 51 return NilStringValues 52 } 53 54 func (m *Log) GetType() EventType { 55 return EventTypeLogging 56 } 57 58 func (m *Log) GetTimestamp() uint64 { 59 if m != nil { 60 return m.Timestamp 61 } 62 return 0 63 } 64 65 func (m *Log) GetObservedTimestamp() uint64 { 66 if m != nil { 67 return m.ObservedTimestamp 68 } 69 return 0 70 } 71 72 func (m *Log) SetObservedTimestamp(observedTimestamp uint64) { 73 if m != nil { 74 m.ObservedTimestamp = observedTimestamp 75 } 76 } 77 78 func (m *Log) GetOffset() uint64 { 79 if m != nil { 80 return m.Offset 81 } 82 return 0 83 } 84 85 func (m *Log) SetOffset(offset uint64) { 86 if m != nil { 87 m.Offset = offset 88 } 89 } 90 91 func (m *Log) GetRawSize() uint64 { 92 if m != nil { 93 return m.RawSize 94 } 95 return 0 96 } 97 98 func (m *Log) SetRawSize(rawSize uint64) { 99 if m != nil { 100 m.RawSize = rawSize 101 } 102 } 103 104 func (m *Log) GetLevel() string { 105 if m != nil { 106 return m.Level 107 } 108 return "" 109 } 110 111 func (m *Log) SetLevel(level string) { 112 if m != nil { 113 m.Level = level 114 } 115 } 116 117 func (m *Log) GetSpanID() string { 118 if m != nil { 119 return m.SpanID 120 } 121 return "" 122 } 123 124 func (m *Log) SetSpanID(spanID string) { 125 if m != nil { 126 m.SpanID = spanID 127 } 128 } 129 130 func (m *Log) GetTraceID() string { 131 if m != nil { 132 return m.TraceID 133 } 134 return "" 135 } 136 137 func (m *Log) SetTraceID(traceID string) { 138 if m != nil { 139 m.TraceID = traceID 140 } 141 } 142 143 func (m *Log) GetBody() []byte { 144 if m != nil && m.Contents != nil { 145 v := m.Contents.Get(BodyKey) 146 if body, ok := v.([]byte); ok { 147 return body 148 } 149 if body, ok := v.(string); ok { 150 return util.ZeroCopyStringToBytes(body) 151 } 152 } 153 return nil 154 } 155 156 func (m *Log) SetBody(body []byte) { 157 if m != nil { 158 if m.Contents == nil { 159 m.Contents = NewLogContents() 160 } 161 if body != nil { 162 m.Contents.Add(BodyKey, body) 163 } 164 } 165 } 166 167 func (m *Log) SetIndices(indices LogContents) { 168 if m != nil { 169 m.Contents = indices 170 } 171 } 172 173 func (m *Log) GetIndices() LogContents { 174 if m != nil { 175 return m.Contents 176 } 177 return NilInterfaceValues 178 } 179 180 func (m *Log) GetSize() int64 { 181 return int64(len(m.GetBody())) 182 } 183 184 func (m *Log) Clone() PipelineEvent { 185 if m != nil { 186 return &Log{ 187 Name: m.Name, 188 Level: m.Level, 189 SpanID: m.SpanID, 190 TraceID: m.TraceID, 191 Tags: m.Tags, 192 Timestamp: m.Timestamp, 193 ObservedTimestamp: m.ObservedTimestamp, 194 Contents: m.Contents, 195 Offset: m.Offset, 196 } 197 } 198 return nil 199 }