Exemplo n.º 1
0
func (s *LoggerTestSuite) TestSend() {
	udpserver := MockUDPServer{t: s.T()}
	udpserver.Mock.On("receivedMessage", mock.Anything).Return(nil)

	syncch := make(chan bool, 1)
	readch := make(chan bool, 1)
	msgch := make(chan string, 1)
	go udpserver.Run(syncch, readch, msgch)
	<-syncch

	var lvl severity.Type
	for lvl = severity.Emergency; lvl <= severity.Debug; lvl++ {
		s.logger.Send(gol.NewMessage(lvl, "message", "unknown"))
		readch <- true // read message sent
		assert.True(s.T(), strings.Contains(<-msgch, lvl.String()))
	}

	// invalid severity will be sent with the default logger severity level
	s.logger.Send(gol.NewMessage(severity.Debug+1, "invalid", "severity"))
	readch <- true // read message sent
	assert.True(s.T(), strings.Contains(<-msgch, "severity=UNKNOWN"))
	readch <- false // end concurrent go routine
}
Exemplo n.º 2
0
// SetSeverity sets the value of the logger message severity level field.
func (msg LogMessage) SetSeverity(lvl field_severity.Type) (err error) {
	if err = lvl.Validate(); err == nil {
		msg[fields.Severity] = lvl
	}
	return
}