Exemplo n.º 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"))
}
Exemplo n.º 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"))
}
Exemplo n.º 3
0
func main() {
	fmt.Println("Started application.")
	defer func() {
		Log.Close()
		fmt.Println("Ended application.")
	}()

	// send 10,000 messages
	for i := 0; i < 100000; i++ {
		Log.Send(gol.NewInfo("i", fmt.Sprintf("%d", i)))
	}
	fmt.Println("Ending application...")
}
Exemplo n.º 4
0
Arquivo: log.go Projeto: steenzout/gol
func init() {
	fmt.Println("init():start")
	Log = manager_simple.New(LogWorkers)

	f := filter_severity.New(field_severity.Info)
	formatter := formatters.Text{}
	logger := logger_simple.New(f, formatter, os.Stdout)
	Log.Register("main", logger)

	Log.Run()
	Log.Send(gol.NewInfo("message", "main.Log has been configured"))
	fmt.Println("init():end")
}
Exemplo n.º 5
0
func (s *MessageTestSuite) TestTimestamp() {
	var msg *gol.LogMessage

	msg = &gol.LogMessage{"key": "value"}
	v, err := msg.Timestamp()
	assert.Equal(s.T(), fmt.Errorf("Message does not contain field timestamp"), err)
	assert.Nil(s.T(), v)

	msg = gol.NewInfo("key", "value")
	v, err = msg.Timestamp()
	assert.Nil(s.T(), err)
	assert.True(s.T(), v.Before(time.Now()))
}
Exemplo n.º 6
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())
	}
}
Exemplo n.º 7
0
func main() {
	log.Send(gol.NewInfo("message", "example execution started"))
	log.Send(gol.NewInfo("message", "example execution ended"))
}