示例#1
0
文件: example.go 项目: steenzout/gol
// Format formats the log message.
func (f Custom) Format(msg *gol.LogMessage) (string, error) {
	lmsg := msg.FieldLength()
	buffer := make([]string, lmsg, lmsg)

	i := 0
	for k, v := range *msg {
		if k != fields.Severity && k != fields.Timestamp {
			buffer[i] = fmt.Sprintf("%s:'%s'", k, v)
			i += 1
		}
	}

	t, _ := msg.Timestamp()

	if severity, err := msg.Severity(); err != nil {
		return fmt.Sprintf("%s UNKNOWN %s\n", t.String(), strings.Join(buffer, " ")), nil
	} else {
		switch severity >= field_severity.Error {
		case true:
			return fmt.Sprintf("%s %s %s\n", t.String(), color.RedString("%s", severity), strings.Join(buffer, " ")), nil
		default:
			return fmt.Sprintf("%s %s %s\n", t.String(), severity, strings.Join(buffer, " ")), nil
		}
	}
}
示例#2
0
文件: text.go 项目: steenzout/gol
// Format formats the log message.
func (f Text) Format(msg *gol.LogMessage) (string, error) {
	lmsg := msg.FieldLength()
	buffer := make([]string, lmsg, lmsg)

	i := 0
	for k, v := range *msg {
		buffer[i] = fmt.Sprintf("%s=%s", k, v)
		i += 1
	}

	return fmt.Sprintf("%s\n", strings.Join(buffer, " ")), nil
}
示例#3
0
func (s *MessageTestSuite) TestFieldLength() {
	msg := gol.LogMessage{
		"key": "value",
	}
	assert.Equal(s.T(), 1, msg.FieldLength())
}