Exemplo n.º 1
0
func TestFormatterTagged(t *testing.T) {
	assert := assert.New(t)

	formatter := new(StandardSinkFormatter)
	formatter.SetFormat("[%time%] [%severity%] - %message% (%tags%)")
	var msg core.LogMessage = core.CreateTaggedLogMessage("DEBUG", "test", []string{"A", "B"})

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

	assert.EqualValues(expected, output)
}
Exemplo n.º 2
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)
}
Exemplo n.º 3
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)
}
Exemplo n.º 4
0
func (this *StandardSinkFilter) shouldTags(msg core.LogMessage) bool {
	if this.filter.Tags != nil && len(this.filter.Tags) > 0 {
		msgTags := msg.Tags()
		for _, filterTag := range this.filter.Tags {
			for _, messageTag := range msgTags {
				if filterTag == messageTag {
					return true
				}
			}
		}
		return false
	}
	return true
}
Exemplo n.º 5
0
func (this *StandardSinkFormatter) GetFormattedMessage(msg core.LogMessage) string {
	var b bytes.Buffer
	this.compiledTemplate.Execute(
		&b,
		map[string]interface{}{
			"time":     msg.Time().Format(this.timeFormat),
			"severity": msg.Severity(),
			"message":  strings.Replace(msg.Message(), "\n", "\n\t", -1),
			"tags":     strings.Join(msg.Tags(), ","),
		},
	)
	return b.String()
}
Exemplo n.º 6
0
func (this *StandardSinkFilter) shouldSeverity(msg core.LogMessage) bool {
	var result bool
	switch this.filter.Severity.CmpOp {
	case core.FILTER_CMP_NONE:
		result = true
	case core.FILTER_CMP_GE:
		result = this.severityComparator.ge(msg.Severity(), this.filter.Severity.Level)
	case core.FILTER_CMP_EQ:
		result = this.severityComparator.eq(msg.Severity(), this.filter.Severity.Level)
	case core.FILTER_CMP_LT:
		result = this.severityComparator.lt(msg.Severity(), this.filter.Severity.Level)
	case core.FILTER_CMP_GT:
		result = this.severityComparator.gt(msg.Severity(), this.filter.Severity.Level)
	}
	return result
}