MCPcopy Create free account
hub / github.com/apache/tomcat / format

Method format

java/org/apache/juli/JdkLoggerFormatter.java:68–134  ·  view source on GitHub ↗
(LogRecord record)

Source from the content-addressed store, hash-verified

66 public static final int LOG_LEVEL_FATAL = 1000;
67
68 @Override
69 public String format(LogRecord record) {
70 Throwable t = record.getThrown();
71 int level = record.getLevel().intValue();
72 String name = record.getLoggerName();
73 long time = record.getMillis();
74 String message = formatMessage(record);
75
76 if (name == null) {
77 name = "";
78 }
79 if (name.indexOf('.') >= 0) {
80 name = name.substring(name.lastIndexOf('.') + 1);
81 }
82
83 // Use a string buffer for better performance
84 StringBuilder buf = new StringBuilder();
85
86 buf.append(time);
87
88 // Append a readable representation of the log level.
89 switch (level) {
90 case LOG_LEVEL_TRACE:
91 buf.append(" T ");
92 break;
93 case LOG_LEVEL_DEBUG:
94 buf.append(" D ");
95 break;
96 case LOG_LEVEL_INFO:
97 buf.append(" I ");
98 break;
99 case LOG_LEVEL_WARN:
100 buf.append(" W ");
101 break;
102 case LOG_LEVEL_ERROR:
103 buf.append(" E ");
104 break;
105 // case : buf.append(" F "); break;
106 default:
107 buf.append(" ");
108 }
109
110 // Append the name of the log instance if so configured
111 buf.append(name);
112 buf.append(' ');
113
114 // pad to 20 chars
115 buf.append(" ".repeat(Math.max(0, 20 - (name.length() + 1))));
116
117 // Append the message
118 buf.append(LogUtil.escape(message));
119
120 // Append stack trace if not null
121 if (t != null) {
122 buf.append(System.lineSeparator());
123
124 java.io.StringWriter sw = new java.io.StringWriter(1024);
125 java.io.PrintWriter pw = new java.io.PrintWriter(sw);

Callers

nothing calls this directly

Calls 10

escapeMethod · 0.95
getLevelMethod · 0.80
getLoggerNameMethod · 0.80
lengthMethod · 0.80
printStackTraceMethod · 0.65
closeMethod · 0.65
toStringMethod · 0.65
indexOfMethod · 0.45
appendMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected