瀏覽代碼

stacktrace2string

janiii 15 年之前
父節點
當前提交
97a9c63f68

+ 5 - 10
L2_GameServer/java/com/l2jserver/gameserver/model/quest/Quest.java

@@ -14,8 +14,6 @@
  */
 package com.l2jserver.gameserver.model.quest;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -25,6 +23,9 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
 import com.l2jserver.Config;
 import com.l2jserver.L2DatabaseFactory;
 import com.l2jserver.gameserver.ThreadPoolManager;
@@ -47,9 +48,7 @@ import com.l2jserver.gameserver.scripting.ManagedScript;
 import com.l2jserver.gameserver.scripting.ScriptManager;
 import com.l2jserver.gameserver.templates.chars.L2NpcTemplate;
 import com.l2jserver.util.Rnd;
-
-import javolution.util.FastList;
-import javolution.util.FastMap;
+import com.l2jserver.util.Util;
 
 /**
  * @author Luis Arias
@@ -763,11 +762,7 @@ public class Quest extends ManagedScript
 		_log.log(Level.WARNING, this.getScriptFile().getAbsolutePath(), t);
 		if (player != null && player.getAccessLevel().isGm())
 		{
-			StringWriter sw = new StringWriter();
-			PrintWriter pw = new PrintWriter(sw);
-			t.printStackTrace(pw);
-			pw.close();
-			String res = "<html><body><title>Script error</title>" + sw.toString() + "</body></html>";
+			String res = "<html><body><title>Script error</title>" + Util.getStackTrace(t) + "</body></html>";
 			return showResult(player, res);
 		}
 		return false;

+ 2 - 26
L2_GameServer/java/com/l2jserver/log/ConsoleLogFormatter.java

@@ -14,12 +14,11 @@
  */
 package com.l2jserver.log;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.util.logging.Formatter;
 import java.util.logging.LogRecord;
 
 import com.l2jserver.util.StringUtil;
+import com.l2jserver.util.Util;
 
 /**
  * This class ...
@@ -49,36 +48,13 @@ public class ConsoleLogFormatter extends Formatter
 		
 		if (record.getThrown() != null)
 		{
-			StringWriter sw = null;
-			PrintWriter pw = null;
 			try
 			{
-				sw = new StringWriter();
-				pw = new PrintWriter(sw);
-				record.getThrown().printStackTrace(pw);
-				StringUtil.append(output, sw.toString(), CRLF);
+				StringUtil.append(output, Util.getStackTrace(record.getThrown()), CRLF);
 			}
 			catch (Exception ex)
 			{
 			}
-			finally
-			{
-				try
-				{
-					pw.close();
-				}
-				catch (Exception e)
-				{
-				}
-				
-				try
-				{
-					sw.close();
-				}
-				catch (Exception e)
-				{
-				}
-			}
 		}
 		
 		return output.toString();

+ 8 - 0
L2_GameServer/java/com/l2jserver/util/Util.java

@@ -21,6 +21,8 @@
  */
 package com.l2jserver.util;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 
@@ -150,4 +152,10 @@ public class Util
 		return array;
 	}
 	
+	public static String getStackTrace(Throwable t)
+	{
+		StringWriter sw = new StringWriter();
+		t.printStackTrace(new PrintWriter(sw));
+		return sw.toString();
+	}
 }