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

Method addTimestamp

java/org/apache/juli/OneLineFormatter.java:186–226  ·  view source on GitHub ↗

Adds a formatted timestamp to the given buffer. @param buf The string builder to append to @param timestamp The timestamp in milliseconds

(StringBuilder buf, long timestamp)

Source from the content-addressed store, hash-verified

184 * @param timestamp The timestamp in milliseconds
185 */
186 protected void addTimestamp(StringBuilder buf, long timestamp) {
187 String cachedTimeStamp = localDateCache.get().getFormat(timestamp);
188 if (millisHandling == MillisHandling.NONE) {
189 buf.append(cachedTimeStamp);
190 } else if (millisHandling == MillisHandling.APPEND) {
191 buf.append(cachedTimeStamp);
192 long frac = timestamp % 1000;
193 buf.append('.');
194 if (frac < 100) {
195 if (frac < 10) {
196 buf.append('0');
197 buf.append('0');
198 } else {
199 buf.append('0');
200 }
201 }
202 buf.append(frac);
203 } else {
204 // Some version of replace
205 long frac = timestamp % 1000;
206 // Formatted string may vary in length so the insert point may vary
207 int insertStart = cachedTimeStamp.indexOf(DateFormatCache.MSEC_PATTERN);
208 buf.append(cachedTimeStamp.subSequence(0, insertStart));
209 if (frac < 100 && millisHandling == MillisHandling.REPLACE_SSS) {
210 buf.append('0');
211 if (frac < 10) {
212 buf.append('0');
213 }
214 } else if (frac < 10 && millisHandling == MillisHandling.REPLACE_SS) {
215 buf.append('0');
216 }
217 buf.append(frac);
218 if (millisHandling == MillisHandling.REPLACE_SSS) {
219 buf.append(cachedTimeStamp.substring(insertStart + 3));
220 } else if (millisHandling == MillisHandling.REPLACE_SS) {
221 buf.append(cachedTimeStamp.substring(insertStart + 2));
222 } else {
223 buf.append(cachedTimeStamp.substring(insertStart + 1));
224 }
225 }
226 }
227
228
229 /**

Callers 3

testMillisHandlingMethod · 0.95
formatMethod · 0.95
formatMethod · 0.80

Calls 5

subSequenceMethod · 0.80
getMethod · 0.65
getFormatMethod · 0.45
appendMethod · 0.45
indexOfMethod · 0.45

Tested by 1

testMillisHandlingMethod · 0.76