27 package sun.util.logging; |
27 package sun.util.logging; |
28 |
28 |
29 import java.lang.reflect.Field; |
29 import java.lang.reflect.Field; |
30 import java.security.AccessController; |
30 import java.security.AccessController; |
31 import java.security.PrivilegedAction; |
31 import java.security.PrivilegedAction; |
|
32 import java.util.Date; |
32 |
33 |
33 /** |
34 /** |
34 * Internal API to support JRE implementation to detect if the java.util.logging |
35 * Internal API to support JRE implementation to detect if the java.util.logging |
35 * support is available but with no dependency on the java.util.logging |
36 * support is available but with no dependency on the java.util.logging |
36 * classes. This LoggingSupport class provides several static methods to |
37 * classes. This LoggingSupport class provides several static methods to |
136 |
137 |
137 public static String getLevelName(Object level) { |
138 public static String getLevelName(Object level) { |
138 ensureAvailable(); |
139 ensureAvailable(); |
139 return proxy.getLevelName(level); |
140 return proxy.getLevelName(level); |
140 } |
141 } |
|
142 |
|
143 private static final String DEFAULT_FORMAT = |
|
144 "%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%6$s%n"; |
|
145 |
|
146 private static final String FORMAT_PROP_KEY = "java.util.logging.SimpleFormatter.format"; |
|
147 public static String getSimpleFormat() { |
|
148 return getSimpleFormat(true); |
|
149 } |
|
150 |
|
151 // useProxy if true will cause initialization of |
|
152 // java.util.logging and read its configuration |
|
153 static String getSimpleFormat(boolean useProxy) { |
|
154 String format = |
|
155 AccessController.doPrivileged( |
|
156 new PrivilegedAction<String>() { |
|
157 public String run() { |
|
158 return System.getProperty(FORMAT_PROP_KEY); |
|
159 } |
|
160 }); |
|
161 |
|
162 if (useProxy && proxy != null && format == null) { |
|
163 format = proxy.getProperty(FORMAT_PROP_KEY); |
|
164 } |
|
165 |
|
166 if (format != null) { |
|
167 try { |
|
168 // validate the user-defined format string |
|
169 String.format(format, new Date(), "", "", "", "", ""); |
|
170 } catch (IllegalArgumentException e) { |
|
171 // illegal syntax; fall back to the default format |
|
172 format = DEFAULT_FORMAT; |
|
173 } |
|
174 } else { |
|
175 format = DEFAULT_FORMAT; |
|
176 } |
|
177 return format; |
|
178 } |
|
179 |
141 } |
180 } |