Пример #1
0
func main() {
	log.Send(&gol.LogMessage{"hello": "world!"})
	log.Send(gol.NewError("error", "info"))
	log.Send(gol.NewDebug("debug", "info"))

	errorLog.Send(&gol.LogMessage{"hello": "world!"})
	errorLog.Send(gol.NewEmergency("emergency", "errorLog"))
	errorLog.Send(gol.NewError("error", "errorLog"))
	errorLog.Send(gol.NewWarning("error", "errorLog"))
	errorLog.Send(gol.NewInfo("info", "errorLog"))
	errorLog.Send(gol.NewDebug("debug", "errorLog"))
}
Пример #2
0
func main() {
	// this will be written to stderr
	logger.Send(gol.NewEmergency("message", "system is down"))
	logger.Send(gol.NewAlert("message", "failed to write to disk"))
	logger.Send(gol.NewCritical("message", "high server load"))
	logger.Send(gol.NewError("message", "invalid number format"))

	// this will not be written anywhere
	logger.Send(gol.NewWarning("message", "performance close to 1s threshold"))
	logger.Send(gol.NewNotice("message", "failed to communicate with monitoring service"))
	logger.Send(gol.NewInfo("message", "requested processed in 250ms"))
	logger.Send(gol.NewDebug("debug", "var x = 10"))
}
Пример #3
0
func (s *LoggerTestSuite) TestSend() {

	in := map[string]setupLogTest{
		"error": setupLogTest{
			setUp: func(
				msg *gol.LogMessage, mf *mock.LogFilter, mfmt *mock.LogFormatter, mw *mock.Writer,
			) (logger *simple.Logger) {
				mf.Mock.On("Filter", msg).Return(false, nil)
				mfmt.Mock.On("Format", msg).Return("ERROR", nil)
				mw.Mock.On("Write", []byte("ERROR")).Return(5, nil)

				logger = simple.New(mf, mfmt, mw)

				return
			},
			message: gol.NewError(),
			output:  "ERROR",
		},
		"info": setupLogTest{
			setUp: func(
				msg *gol.LogMessage, mf *mock.LogFilter, mfmt *mock.LogFormatter, mw *mock.Writer,
			) (logger *simple.Logger) {
				mf.Mock.On("Filter", msg).Return(true, nil)

				logger = simple.New(mf, mfmt, mw)

				return
			},
			message: gol.NewInfo(),
			output:  "",
		},
	}

	for _, t := range in {
		mf := &mock.LogFilter{}
		mfmt := &mock.LogFormatter{}
		mw := &mock.Writer{}
		logger := t.setUp(t.message, mf, mfmt, mw)

		logger.Send(t.message)

		mf.AssertExpectations(s.T())
		mfmt.AssertExpectations(s.T())
		mw.AssertExpectations(s.T())
	}
}