blob: efc4a9898edf0a4e165e32642827bab15e472669 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/*
* $Id$
*
*/
package com.yahoo.logserver.formatter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import com.yahoo.log.LogMessage;
/**
* Creates human-readable text representation of log message.
*
* @author Bjorn Borud
*/
public class TextFormatter implements LogFormatter {
static final SimpleDateFormat dateFormat;
static {
dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
public String format(LogMessage msg) {
StringBuffer sbuf = new StringBuffer(150);
sbuf.append(dateFormat.format(new Date(msg.getTime())))
.append(" ")
.append(msg.getHost())
.append(" ")
.append(msg.getThreadProcess())
.append(" ")
.append(msg.getService())
.append(" ")
.append(msg.getComponent())
.append(" ")
.append(msg.getLevel().toString())
.append(" ")
.append(msg.getPayload())
.append("\n");
return sbuf.toString();
}
public String description() {
return "Format log-message as human readable text";
}
}
|