本文整理汇总了Golang中github.com/chatoooo/logoon/core.LogMessage.Time方法的典型用法代码示例。如果您正苦于以下问题:Golang LogMessage.Time方法的具体用法?Golang LogMessage.Time怎么用?Golang LogMessage.Time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/chatoooo/logoon/core.LogMessage
的用法示例。
在下文中一共展示了LogMessage.Time方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestFormatterTagged
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)
}
示例2: TestFormatterSpecialDateFormat
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)
}
示例3: TestFormatterNewLines
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)
}
示例4: GetFormattedMessage
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()
}