1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package com.sun.star.script.framework.log; 23 24 import java.io.ByteArrayOutputStream; 25 import java.io.PrintStream; 26 27 public class LogUtils { 28 29 private static boolean m_bDebugEnabled = false; 30 31 static 32 { 33 String debugFlag = 34 System.getProperties().getProperty("ScriptJavaRuntimeDebug"); 35 36 if (debugFlag != null && debugFlag.length() > 0) 37 { 38 m_bDebugEnabled = debugFlag.equalsIgnoreCase("true"); 39 } 40 } 41 42 // Ensure that instances of this class cannot be created LogUtils()43 private LogUtils() { 44 } 45 46 /** 47 * Print Debug Output 48 * 49 * @param msg message to be displayed 50 */ DEBUG(String msg)51 public static void DEBUG(String msg) 52 { 53 if (m_bDebugEnabled) 54 { 55 System.out.println(msg); 56 } 57 } 58 getTrace( Exception e )59 public static String getTrace( Exception e ) 60 { 61 ByteArrayOutputStream baos = null; 62 PrintStream ps = null; 63 String result = ""; 64 try 65 { 66 baos = new ByteArrayOutputStream( ); 67 ps = new PrintStream( baos ); 68 e.printStackTrace( ps ); 69 } 70 finally 71 { 72 try 73 { 74 if ( baos != null ) 75 { 76 baos.close(); 77 } 78 if ( ps != null ) 79 { 80 ps.close(); 81 } 82 } 83 catch ( Exception excp ) 84 { 85 } 86 } 87 return result; 88 } 89 } 90