Beispiel #1
0
func (s *FilterTestSuite) TestFilter() {
	f := filter.New(field.Type(field.Emergency))
	cases := []gol.NewLogMessageFunc{
		gol.NewAlert, gol.NewCritical, gol.NewError, gol.NewWarning, gol.NewNotice, gol.NewInfo, gol.NewDebug,
	}

	assert.False(s.T(), f.Filter(gol.NewEmergency()))
	for _, newFunc := range cases {
		assert.True(s.T(), f.Filter(newFunc()))
	}

	f = filter.New(field.Type(field.Debug))
	cases = []gol.NewLogMessageFunc{
		gol.NewEmergency, gol.NewAlert, gol.NewCritical, gol.NewError, gol.NewWarning, gol.NewNotice, gol.NewInfo,
	}

	for _, newFunc := range cases {
		assert.False(s.T(), f.Filter(newFunc()))
	}
	assert.False(s.T(), f.Filter(gol.NewDebug()))
}
Beispiel #2
0
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")
}
Beispiel #3
0
func (s *FilterTestSuite) TestFilterNoSeverityField() {
	f := filter.New(field.Type(field.Debug))
	assert.True(s.T(), f.Filter(&gol.LogMessage{}))
}
Beispiel #4
0
//

package main

import (
	"os"

	"github.com/mediaFORGE/gol"
	field "github.com/mediaFORGE/gol/fields/severity"
	filter "github.com/mediaFORGE/gol/filters/severity"
	"github.com/mediaFORGE/gol/formatters"
	"github.com/mediaFORGE/gol/loggers/simple"
)

var txtFmt = &formatters.Text{}
var errorLog gol.Logger = simple.New(filter.New(field.Error), txtFmt, os.Stderr)

func main() {
	// this will be written to stderr
	errorLog.Send(gol.NewEmergency("message", "system is down"))
	errorLog.Send(gol.NewAlert("message", "failed to write to disk"))
	errorLog.Send(gol.NewCritical("message", "high server load"))
	errorLog.Send(gol.NewError("message", "invalid number format"))

	// this will not be written anywhere
	errorLog.Send(gol.NewWarning("message", "performance close to 1s threshold"))
	errorLog.Send(gol.NewNotice("message", "failed to communicate with monitoring service"))
	errorLog.Send(gol.NewInfo("message", "requested processed in 250ms"))
	errorLog.Send(gol.NewDebug("debug", "var x = 10"))
}