|
1 | 1 | /*
|
2 | 2 | * Copyright 1999-2018 Alibaba Group Holding Ltd.
|
3 | 3 | *
|
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); |
5 |
| - * you may not use this file except in compliance with the License. |
6 |
| - * You may obtain a copy of the License at |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
7 | 6 | *
|
8 |
| - * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
9 | 8 | *
|
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, |
12 |
| - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 |
| - * See the License for the specific language governing permissions and |
14 |
| - * limitations under the License. |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
15 | 12 | */
|
16 | 13 | package com.alibaba.csp.sentinel.log;
|
17 | 14 |
|
|
28 | 25 | */
|
29 | 26 | class CspFormatter extends Formatter {
|
30 | 27 |
|
31 |
| - private final ThreadLocal<SimpleDateFormat> dateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { |
32 |
| - @Override |
33 |
| - public SimpleDateFormat initialValue() { |
34 |
| - return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
35 |
| - } |
36 |
| - }; |
| 28 | + private final ThreadLocal<SimpleDateFormat> dateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { |
| 29 | + @Override |
| 30 | + public SimpleDateFormat initialValue() { |
| 31 | + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| 32 | + } |
| 33 | + }; |
37 | 34 |
|
38 |
| - @Override |
39 |
| - public String format(LogRecord record) { |
40 |
| - final DateFormat df = dateFormatThreadLocal.get(); |
41 |
| - StringBuilder builder = new StringBuilder(1000); |
42 |
| - builder.append(df.format(new Date(record.getMillis()))).append(" "); |
43 |
| - builder.append(formatMessage(record)); |
| 35 | + @Override |
| 36 | + public String format(LogRecord record) { |
| 37 | + final DateFormat df = dateFormatThreadLocal.get(); |
| 38 | + StringBuilder builder = new StringBuilder(1000); |
| 39 | + builder.append(df.format(new Date(record.getMillis()))).append(" "); |
| 40 | + builder.append(formatMessage(record)); |
44 | 41 |
|
45 |
| - String throwable = ""; |
46 |
| - if (record.getThrown() != null) { |
47 |
| - StringWriter sw = new StringWriter(); |
48 |
| - PrintWriter pw = new PrintWriter(sw); |
49 |
| - pw.println(); |
50 |
| - record.getThrown().printStackTrace(pw); |
51 |
| - pw.close(); |
52 |
| - throwable = sw.toString(); |
53 |
| - } |
54 |
| - builder.append(throwable); |
55 |
| - if ("".equals(throwable)) { |
56 |
| - builder.append("\n"); |
57 |
| - } |
58 |
| - return builder.toString(); |
59 |
| - } |
| 42 | + String throwable = ""; |
| 43 | + if (record.getThrown() != null) { |
| 44 | + StringWriter sw = new StringWriter(); |
| 45 | + PrintWriter pw = new PrintWriter(sw); |
| 46 | + pw.println(); |
| 47 | + record.getThrown().printStackTrace(pw); |
| 48 | + pw.close(); |
| 49 | + throwable = sw.toString(); |
| 50 | + } |
| 51 | + builder.append(throwable); |
| 52 | + if ("".equals(throwable)) { |
| 53 | + builder.append("\n"); |
| 54 | + } |
| 55 | + return builder.toString(); |
| 56 | + } |
60 | 57 | }
|
0 commit comments