func (sinkManager *SinkManager) SendSyslogErrorToLoggregator(errorMsg, appId string) { sinkManager.logger.Warnf(errorMsg) logMessage, err := logmessage.GenerateMessage(logmessage.LogMessage_ERR, errorMsg, appId, "LGR") if err == nil { sinkManager.errorChannel <- logMessage } else { sinkManager.logger.Warnf("Error marshalling message: %v", err) } }
func (messageRouter *messageRouter) sendLoggregatorErrorMessage(errorMsg, appId string) { messageRouter.logger.Warnf(errorMsg) logMessage, err := logmessage.GenerateMessage(logmessage.LogMessage_ERR, errorMsg, appId, "LGR") if err == nil { messageRouter.errorChannel <- logMessage } else { messageRouter.logger.Warnf("Error marshalling message: %v", err) } }
func (s *SyslogSink) Run() { s.logger.Infof("Syslog Sink %s: Running.", s.drainUrl) defer s.logger.Errorf("Syslog Sink %s: Stopped. This should never happen", s.drainUrl) backoffStrategy := newExponentialRetryStrategy() numberOfTries := 0 buffer := runTruncatingBuffer(s, 100, s.Logger()) for { s.logger.Debugf("Syslog Sink %s: Starting loop. Current backoff: %v", s.drainUrl, backoffStrategy(numberOfTries)) select { case <-s.disconnectChannel: return case <-time.After(backoffStrategy(numberOfTries)): } if !s.syslogWriter.IsConnected() { s.logger.Debugf("Syslog Sink %s: Not connected. Trying to connect.", s.drainUrl) err := s.syslogWriter.Connect() if err != nil { errorMsg := fmt.Sprintf("Syslog Sink %s: Error when dialing out. Backing off for %v. Err: %v", s.drainUrl, backoffStrategy(numberOfTries+1), err) numberOfTries++ s.logger.Warnf(errorMsg) logMessage, err := logmessage.GenerateMessage(logmessage.LogMessage_ERR, errorMsg, s.appId, "LGR") if err == nil { s.errorChannel <- logMessage } else { s.logger.Warnf("Error marshalling message: %v", err) } continue } s.logger.Infof("Syslog Sink %s: successfully connected.", s.drainUrl) s.syslogWriter.SetConnected(true) numberOfTries = 0 defer s.syslogWriter.Close() } s.logger.Debugf("Syslog Sink %s: Waiting for activity\n", s.drainUrl) message, ok := <-buffer.GetOutputChannel() if !ok { s.logger.Debugf("Syslog Sink %s: Closed listener channel detected. Closing.\n", s.drainUrl) return } s.logger.Debugf("Syslog Sink %s: Got %d bytes. Sending data\n", s.drainUrl, message.GetRawMessageLength()) var err error switch message.GetLogMessage().GetMessageType() { case logmessage.LogMessage_OUT: _, err = s.syslogWriter.WriteStdout(message.GetLogMessage().GetMessage(), message.GetLogMessage().GetSourceName(), *message.GetLogMessage().Timestamp) case logmessage.LogMessage_ERR: _, err = s.syslogWriter.WriteStderr(message.GetLogMessage().GetMessage(), message.GetLogMessage().GetSourceName(), *message.GetLogMessage().Timestamp) } if err != nil { s.logger.Debugf("Syslog Sink %s: Error when trying to send data to sink. Backing off. Err: %v\n", s.drainUrl, err) numberOfTries++ s.syslogWriter.SetConnected(false) } else { s.logger.Debugf("Syslog Sink %s: Successfully sent data\n", s.drainUrl) numberOfTries = 0 atomic.AddUint64(s.sentMessageCount, 1) atomic.AddUint64(s.sentByteCount, uint64(message.GetRawMessageLength())) } } }