@@ -48,9 +48,25 @@ type chainData struct {
4848 timeout time.Duration // option
4949
5050 lastUpdated time.Time
51- wait time.Duration
51+ wait time.Duration // option
52+
53+ groupKey string
54+ groupValues []string
5255}
5356
57+ // type marshalZerologTexts []text
58+ // type text string
59+
60+ // func (uu marshalZerologTexts) MarshalZerologArray(a *zerolog.Array) {
61+ // for _, u := range uu {
62+ // a.Object(u)
63+ // }
64+ // }
65+
66+ // func (u text) MarshalZerologObject(e *zerolog.Event) {
67+ // e.Str("", string(u))
68+ // }
69+
5470func (c * chainData ) needLogged () bool {
5571 now := time .Now ()
5672 return c .count >= c .maxRelativeBatch || // reached max batch counts
@@ -125,7 +141,7 @@ func (b *chainedBatcher) Batch(e *event, opts ...BatchOption) {
125141 if k == len (e .batchKeysA )- 1 {
126142 value , _ := node .nexts [v ]
127143 if value .data == nil {
128- value .data = rawChainData (e . event )
144+ value .data = rawChainData (e )
129145
130146 if len (e .logger .opts ) > 0 {
131147 value .data .applyOpts (e .logger .opts ... )
@@ -136,21 +152,29 @@ func (b *chainedBatcher) Batch(e *event, opts ...BatchOption) {
136152
137153 value .data .count ++
138154 value .data .lastUpdated = time .Now ()
155+
156+ if len (e .group .key ) > 0 {
157+ value .data .groupValues = append (value .data .groupValues , e .group .value )
158+ }
159+
139160 node .nexts [v ] = value
140161 }
141162
142163 node = node .nexts [v ]
143164 }
144165}
145166
146- func rawChainData (event * zerolog. Event ) * chainData {
167+ func rawChainData (event * event ) * chainData {
147168 return & chainData {
148- event : event ,
169+ event : event . event ,
149170 count : 0 ,
150171 start : time .Now (),
151172 timeout : 10 * time .Second ,
152173 maxRelativeBatch : 20 ,
153174 wait : 5 * time .Second ,
175+ // lastUpdated: time.Now(),
176+ groupKey : event .group .key ,
177+ // groupValues: make([]string, 0),
154178 }
155179}
156180
@@ -180,6 +204,11 @@ func (b *chainedBatcher) logging() {
180204// and remove that element out of logger
181205func batchOut (b * chainedBatcher , c * chainData , i int ) {
182206 c .event .Int ("__repeat" , c .count )
207+
208+ if len (c .groupValues ) > 0 {
209+ c .event .Strs (c .groupKey , c .groupValues )
210+ }
211+
183212 c .event .Send ()
184213
185214 b .logged [i ].clean ()
0 commit comments