1 /*
2 (C) Copyright IBM Corp. 2006, 2009
3
4 THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
5 ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
6 CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
7
8 You can obtain a current copy of the Eclipse Public License from
9 http://www.opensource.org/licenses/eclipse-1.0.php
10
11 @author : Alexander Wolf-Reber, IBM, a.wolf-reber@de.ibm.com
12 *
13 * Change History
14 * Flag Date Prog Description
15 *-------------------------------------------------------------------------------
16 * 1565892 2006-11-15 lupusalex Make SBLIM client JSR48 compliant
17 * 1745282 2007-06-29 ebak Uniform time stamps for log files
18 * 2003590 2008-06-30 blaschke-oss Change licensing from CPL to EPL
19 * 2524131 2009-01-21 raman_arora Upgrade client to JDK 1.5 (Phase 1)
20 */
21
22 package org.metricshub.wbem.sblim.cimclient.internal.logging;
23
24 /*-
25 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
26 * WBEM Java Client
27 * ჻჻჻჻჻჻
28 * Copyright 2023 - 2025 MetricsHub
29 * ჻჻჻჻჻჻
30 * Licensed under the Apache License, Version 2.0 (the "License");
31 * you may not use this file except in compliance with the License.
32 * You may obtain a copy of the License at
33 *
34 * http://www.apache.org/licenses/LICENSE-2.0
35 *
36 * Unless required by applicable law or agreed to in writing, software
37 * distributed under the License is distributed on an "AS IS" BASIS,
38 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
39 * See the License for the specific language governing permissions and
40 * limitations under the License.
41 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
42 */
43
44 import java.io.PrintWriter;
45 import java.io.StringWriter;
46 import java.util.logging.Formatter;
47 import java.util.logging.LogRecord;
48
49 /**
50 * Class TraceFormatter implements the formatting algorithm for our console log.
51 *
52 */
53 public class TraceFormatter extends Formatter {
54 private final String iLineSeparator = System.getProperty("line.separator");
55
56 /**
57 * Ctor.
58 */
59 public TraceFormatter() {
60 super();
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
67 */
68 @Override
69 public String format(LogRecord pRecord) {
70 StringBuffer buffer = new StringBuffer();
71 buffer.append(TimeStamp.format(pRecord.getMillis()));
72 buffer.append(" >");
73 buffer.append(String.valueOf(pRecord.getThreadID()));
74 buffer.append("< ");
75 buffer.append(pRecord.getSourceMethodName());
76 buffer.append(this.iLineSeparator);
77 buffer.append(pRecord.getLevel().getName());
78 buffer.append(": ");
79 buffer.append(pRecord.getMessage());
80 buffer.append(this.iLineSeparator);
81 if (pRecord.getThrown() != null) {
82 buffer.append("---> ");
83 StringWriter stringWriter = new StringWriter();
84 PrintWriter printWriter = new PrintWriter(stringWriter);
85 pRecord.getThrown().printStackTrace(printWriter);
86 printWriter.close();
87 buffer.append(stringWriter.toString());
88 buffer.append(this.iLineSeparator);
89 }
90 return buffer.toString();
91 }
92 }