MCPcopy Index your code
hub / github.com/apache/tomcat / OneLineFormatter

Class OneLineFormatter

java/org/apache/juli/OneLineFormatter.java:39–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 * Date processing based on AccessLogValve.
38 */
39public class OneLineFormatter extends Formatter {
40
41 private static final Object threadMxBeanLock = new Object();
42 private static volatile ThreadMXBean threadMxBean = null;
43 private static final int THREAD_NAME_CACHE_SIZE = 10000;
44 private static final ThreadLocal<ThreadNameCache> threadNameCache =
45 ThreadLocal.withInitial(() -> new ThreadNameCache(THREAD_NAME_CACHE_SIZE));
46
47 /* Timestamp format */
48 private static final String DEFAULT_TIME_FORMAT = "dd-MMM-yyyy HH:mm:ss.SSS";
49
50 /**
51 * The size of our global date format cache
52 */
53 private static final int GLOBAL_CACHE_SIZE = 30;
54
55 /**
56 * The size of our thread local date format cache
57 */
58 private static final int LOCAL_CACHE_SIZE = 5;
59
60 /**
61 * Thread local date format cache.
62 */
63 private ThreadLocal<DateFormatCache> localDateCache;
64
65 private volatile MillisHandling millisHandling = MillisHandling.APPEND;
66
67
68 /**
69 * Constructs a OneLineFormatter with the default time format from the log manager properties.
70 */
71 public OneLineFormatter() {
72 String timeFormat = LogManager.getLogManager().getProperty(OneLineFormatter.class.getName() + ".timeFormat");
73 if (timeFormat == null) {
74 timeFormat = DEFAULT_TIME_FORMAT;
75 }
76 setTimeFormat(timeFormat);
77 }
78
79
80 /**
81 * Specify the time format to use for time stamps in log messages.
82 *
83 * @param timeFormat The format to use using the {@link java.text.SimpleDateFormat} syntax
84 */
85 public void setTimeFormat(final String timeFormat) {
86 final String cachedTimeFormat;
87
88 if (timeFormat.endsWith(".SSS")) {
89 cachedTimeFormat = timeFormat.substring(0, timeFormat.length() - 4);
90 millisHandling = MillisHandling.APPEND;
91 } else if (timeFormat.contains("SSS")) {
92 millisHandling = MillisHandling.REPLACE_SSS;
93 cachedTimeFormat = timeFormat;
94 } else if (timeFormat.contains("SS")) {
95 millisHandling = MillisHandling.REPLACE_SS;
96 cachedTimeFormat = timeFormat;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected