Beispiel #1
0
func TestFormatterNewLines(t *testing.T) {
	assert := assert.New(t)

	formatter := new(StandardSinkFormatter)
	formatter.SetFormat("[%time%] [%severity%] - %message%")
	var msg core.LogMessage = core.CreateBasicLogMessage("DEBUG", "test\ntest")

	output := formatter.GetFormattedMessage(msg)
	expected := fmt.Sprintf("[%s] [%s] - %s", msg.Time().Format(time.RFC3339), "DEBUG", "test\n\ttest")

	assert.EqualValues(expected, output)
}
Beispiel #2
0
func TestFormatterSpecialDateFormat(t *testing.T) {
	assert := assert.New(t)

	formatter := new(StandardSinkFormatter)
	formatter.SetFormat("[%time(2006-02-01 15:03:04.000)%] [%severity%] - %message%")
	var msg core.LogMessage = core.CreateBasicLogMessage("DEBUG", "test")

	output := formatter.GetFormattedMessage(msg)
	expected := fmt.Sprintf("[%s] [%s] - %s", msg.Time().Format("2006-02-01 15:03:04.000"), "DEBUG", "test")

	assert.EqualValues(expected, output)
}
Beispiel #3
0
func TestFilterSeverity(t *testing.T) {
	assert := assert.New(t)

	filter := StandardSinkFilter{
		severityComparator: MakeStringSeverityComparator([]string{"TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL"}),
		filter: core.Filter{
			Severity: core.FilterSeverity{
				CmpOp: core.FILTER_CMP_GE,
				Level: "INFO",
			},
			Tags:        nil,
			TagsExclude: false,
		},
	}
	assert.False(filter.ShouldOutput(core.CreateBasicLogMessage("TRACE", "")))
	assert.False(filter.ShouldOutput(core.CreateBasicLogMessage("DEBUG", "")))
	assert.True(filter.ShouldOutput(core.CreateBasicLogMessage("INFO", "")))
	assert.True(filter.ShouldOutput(core.CreateBasicLogMessage("WARNING", "")))
	assert.True(filter.ShouldOutput(core.CreateBasicLogMessage("ERROR", "")))
	assert.True(filter.ShouldOutput(core.CreateBasicLogMessage("FATAL", "")))
}
Beispiel #4
0
func (this SimpleLogSource) Fatal(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("FATAL", message))
}
Beispiel #5
0
func (this SimpleLogSource) Error(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("ERROR", message))
}
Beispiel #6
0
func (this SimpleLogSource) Warning(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("WARNING", message))
}
Beispiel #7
0
func (this SimpleLogSource) Info(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("INFO", message))
}
Beispiel #8
0
func (this SimpleLogSource) Debug(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("DEBUG", message))
}
Beispiel #9
0
func (this SimpleLogSource) Trace(message string) {
	this.dispatcher.Log(core.CreateBasicLogMessage("TRACE", message))
}