@@ -37,19 +37,21 @@ func (s *SumoLogicAppender) Start() {
3737 logging .Info .Println ("Starting Appender Worker" )
3838 for {
3939 time .Sleep (300 * time .Millisecond )
40- if s .nozzleQueue .GetCount () != 0 { //if queue is not empty, AppendLogs
41- s .AppendLogs ()
40+ // while queue is not empty && s.eventsBatchSize not completed, queue.POP (appendLogs)
41+ for s .nozzleQueue .GetCount () != 0 && s .logEventsInCurrentBuffer <= s .eventsBatchSize {
42+ s .AppendLogs () //this method POP an event from queue
43+ timer = time .Now () //reset timer
44+ if s .logEventsInCurrentBuffer == s .eventsBatchSize { //if buffer is full, send logs to sumo
45+ logging .Trace .Println ("Batch Size complete" )
46+ s .SendToSumo (s .logStringToSend )
47+ break
48+ } else if time .Since (timer ).Seconds () >= 10 { // else if timer is up, send existing logs to sumo
49+ logging .Trace .Println ("Sending current batch of logs after timer exceeded limit" )
50+ s .SendToSumo (s .logStringToSend )
51+ timer = time .Now () //reset timer
52+ break
53+ }
4254 }
43- if s .logEventsInCurrentBuffer >= s .eventsBatchSize { //if buffer is full, send logs to sumo
44- logging .Trace .Println ("Batch Size complete" )
45- s .SendToSumo (s .logStringToSend )
46-
47- } else if time .Since (timer ).Seconds () >= 10 { // else if timer is up, send existing logs to sumo
48- logging .Trace .Println ("Sending current batch of logs after timer exceeded limit" )
49- s .SendToSumo (s .logStringToSend )
50- timer = time .Now () //reset timer
51- }
52-
5355 }
5456}
5557
@@ -69,7 +71,6 @@ func StringBuilder(event *events.Event) string {
6971
7072func (s * SumoLogicAppender ) AppendLogs () {
7173 // the appender calls for the next message in the queue and parse it to a string
72- //timer := time.NewTimer(60 * time.Second)
7374 s .logStringToSend .Write ([]byte (StringBuilder (s .nozzleQueue .Pop ())))
7475 s .logEventsInCurrentBuffer ++
7576}
0 commit comments