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.sentrysoftware.wbem.sblim.cimclient.internal.logging; 23 24 /*- 25 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 26 * WBEM Java Client 27 * ჻჻჻჻჻჻ 28 * Copyright (C) 2023 Sentry Software 29 * ჻჻჻჻჻჻ 30 * This program is free software: you can redistribute it and/or modify 31 * it under the terms of the GNU Lesser General Public License as 32 * published by the Free Software Foundation, either version 3 of the 33 * License, or (at your option) any later version. 34 * 35 * This program is distributed in the hope that it will be useful, 36 * but WITHOUT ANY WARRANTY; without even the implied warranty of 37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 38 * GNU General Lesser Public License for more details. 39 * 40 * You should have received a copy of the GNU General Lesser Public 41 * License along with this program. If not, see 42 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 43 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 44 */ 45 46 import java.io.PrintWriter; 47 import java.io.StringWriter; 48 import java.util.logging.Formatter; 49 import java.util.logging.LogRecord; 50 51 /** 52 * Class TraceFormatter implements the formatting algorithm for our console log. 53 * 54 */ 55 public class TraceFormatter extends Formatter { 56 57 private final String iLineSeparator = System.getProperty("line.separator"); 58 59 /** 60 * Ctor. 61 */ 62 public TraceFormatter() { 63 super(); 64 } 65 66 /* 67 * (non-Javadoc) 68 * 69 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord) 70 */ 71 @Override 72 public String format(LogRecord pRecord) { 73 StringBuffer buffer = new StringBuffer(); 74 buffer.append(TimeStamp.format(pRecord.getMillis())); 75 buffer.append(" >"); 76 buffer.append(String.valueOf(pRecord.getThreadID())); 77 buffer.append("< "); 78 buffer.append(pRecord.getSourceMethodName()); 79 buffer.append(this.iLineSeparator); 80 buffer.append(pRecord.getLevel().getName()); 81 buffer.append(": "); 82 buffer.append(pRecord.getMessage()); 83 buffer.append(this.iLineSeparator); 84 if (pRecord.getThrown() != null) { 85 buffer.append("---> "); 86 StringWriter stringWriter = new StringWriter(); 87 PrintWriter printWriter = new PrintWriter(stringWriter); 88 pRecord.getThrown().printStackTrace(printWriter); 89 printWriter.close(); 90 buffer.append(stringWriter.toString()); 91 buffer.append(this.iLineSeparator); 92 } 93 return buffer.toString(); 94 } 95 }