|
From: <de...@us...> - 2012-10-25 12:27:16
|
Revision: 7809
http://fudaa.svn.sourceforge.net/fudaa/?rev=7809&view=rev
Author: deniger
Date: 2012-10-25 12:27:10 +0000 (Thu, 25 Oct 2012)
Log Message:
-----------
Modified Paths:
--------------
trunk/framework/ctulu-fu/src/main/java/com/memoire/fu/FuLog.java
Modified: trunk/framework/ctulu-fu/src/main/java/com/memoire/fu/FuLog.java
===================================================================
--- trunk/framework/ctulu-fu/src/main/java/com/memoire/fu/FuLog.java 2012-10-25 11:32:46 UTC (rev 7808)
+++ trunk/framework/ctulu-fu/src/main/java/com/memoire/fu/FuLog.java 2012-10-25 12:27:10 UTC (rev 7809)
@@ -8,7 +8,6 @@
* @license GNU General Public License 2 (GPL2)
* @copyright 1998-2005 Guillaume Desnoix
*/
-
package com.memoire.fu;
// import java.lang.ref.*;
@@ -26,17 +25,17 @@
import java.util.logging.Level;
public final class FuLog {
+
private static final int SW = 80; // screen width
-
// private and final are temporary
/*
- private static final int NOTHING=0;
- private static final int DEBUG =1;
- private static final int TRACE =2;
- private static final int WARNING=3;
- private static final int ERROR =4;
- private static final int FAILURE=5;
- */
+ private static final int NOTHING=0;
+ private static final int DEBUG =1;
+ private static final int TRACE =2;
+ private static final int WARNING=3;
+ private static final int ERROR =4;
+ private static final int FAILURE=5;
+ */
public final static int ALL = 0;
public final static int DEBUG = 1;
public final static int TRACE = 2;
@@ -44,16 +43,15 @@
public final static int ERROR = 4;
public final static int FAILURE = 5;
public final static int NOTHING = 6;
-
- static final String[] LEVELS = { " ", "DEBUG", "TRACE", "WARNG", "ERROR", "FAILR" };
-
+ static final String[] LEVELS = {" ", "DEBUG", "TRACE", "WARNG", "ERROR", "FAILR"};
private static final int level_ = getLogLevel();
static final boolean date_ = getLogOption("date", false);
static final boolean time_ = getLogOption("time", false);
static final boolean location_ = getLogOption("location", false);
- static final boolean cut_ = false/** getLogOption("cut" ,false) */
- ;
-
+ static final boolean cut_ = false/**
+ * getLogOption("cut" ,false)
+ */
+ ;
private static boolean useJavaUtilLogging = false;
public static boolean isUseJavaUtilLogging() {
@@ -63,7 +61,6 @@
public static void setUseJavaUtilLogging(boolean useJavaUtilLogging) {
FuLog.useJavaUtilLogging = useJavaUtilLogging;
}
-
public static PrintStream LOGSTREAM;
private static final Thread THREAD;
static final Vector QUEUE; //LinkedList
@@ -104,10 +101,12 @@
public static final void printStackTrace() {
String r = getStackTrace();
int p = r.indexOf("com.memoire.fu.FuLog.printStackTrace");
- if (p >= 0)
+ if (p >= 0) {
p = r.indexOf('\n', p);
- if (p >= 0)
+ }
+ if (p >= 0) {
r = r.substring(p + 1);
+ }
r = FuLib.replace(r, " at ", " ");
r = FuLib.replace(r, "\tat ", " ");
System.err.println("STK: ==== STACK TRACE ====");
@@ -131,12 +130,11 @@
}
/*
- public static final void trace(String _msg,Throwable _th)
- {
- log(TRACE,_msg,_th);
- }
- */
-
+ public static final void trace(String _msg,Throwable _th)
+ {
+ log(TRACE,_msg,_th);
+ }
+ */
public static final void warning(String _msg) {
log(WARNING, _msg, null);
}
@@ -162,12 +160,11 @@
}
/*
- public static final void failure(String _msg)
- {
- log(FAILURE,_msg,null);
- }
- */
-
+ public static final void failure(String _msg)
+ {
+ log(FAILURE,_msg,null);
+ }
+ */
public static final void failure(String _msg, Throwable _th) {
log(FAILURE, _msg, _th);
}
@@ -176,8 +173,9 @@
PrintStream r = null;
try {
String log = System.getProperty("fulog.file");
- if (log == null)
+ if (log == null) {
log = System.getProperty("user.home") + File.separator + ".jdistro" + File.separator + "log";
+ }
r = new PrintStream(new FileOutputStream(log), false);
} catch (IOException ex) {
}
@@ -187,30 +185,39 @@
private static final int getLogLevel() {
int r = DEBUG;
String level = System.getProperty("fulog.level");
- if ("all".equals(level))
+ if ("all".equals(level)) {
r = ALL;
- if ("debug".equals(level))
+ }
+ if ("debug".equals(level)) {
r = DEBUG;
- if ("trace".equals(level))
+ }
+ if ("trace".equals(level)) {
r = TRACE;
- if ("warning".equals(level))
+ }
+ if ("warning".equals(level)) {
r = WARNING;
- if ("error".equals(level))
+ }
+ if ("error".equals(level)) {
r = ERROR;
- if ("failure".equals(level))
+ }
+ if ("failure".equals(level)) {
r = FAILURE;
- if ("nothing".equals(level))
+ }
+ if ("nothing".equals(level)) {
r = NOTHING;
+ }
return r;
}
private static final boolean getLogOption(String _key, boolean _default) {
boolean r = _default;
String o = System.getProperty("fulog." + _key);
- if ("true".equals(o) || "yes".equals(o))
+ if ("true".equals(o) || "yes".equals(o)) {
r = true;
- if ("false".equals(o) || "no".equals(o))
+ }
+ if ("false".equals(o) || "no".equals(o)) {
r = false;
+ }
return r;
}
@@ -268,8 +275,9 @@
sb.append(s);
}
- if ((r.msg_ != null) && (r.msg_.length() > 0) && (r.msg_.charAt(0) != ' '))
+ if ((r.msg_ != null) && (r.msg_.length() > 0) && (r.msg_.charAt(0) != ' ')) {
sb.append(' ');
+ }
String msg = (header ? r.msg_.substring(4) : r.msg_);
if (cut_) {
@@ -287,9 +295,11 @@
}
}
- if (cut_)
- for (int i = SW - 2; i < sb.length(); i += SW - 2)
+ if (cut_) {
+ for (int i = SW - 2; i < sb.length(); i += SW - 2) {
sb.insert(i, "\n ");
+ }
+ }
String st = null;
@@ -302,16 +312,20 @@
if (i >= 0) {
loc = st.substring(i);
i = loc.indexOf('\n');
- if (i >= 0)
+ if (i >= 0) {
loc = loc.substring(i + 1);
+ }
}
i = loc.indexOf('(');
- if (i >= 0)
+ if (i >= 0) {
loc = loc.substring(i + 1);
+ }
i = loc.indexOf(')');
- if (i >= 0)
+ if (i >= 0) {
loc = loc.substring(0, i);
- else loc = "unknown";
+ } else {
+ loc = "unknown";
+ }
if (cut_) {
int l = sb.length();
@@ -327,40 +341,49 @@
sb.append(' ');
l++;
}
- } else sb.append(' ');
+ } else {
+ sb.append(' ');
+ }
sb.append(loc);
}
}
System.err.println(sb.toString());
- if (LOGSTREAM != null)
+ if (LOGSTREAM != null) {
LOGSTREAM.println(sb.toString());
+ }
if ((r.th_ != null) && (r.recLevel_ >= ERROR)) {
- if (st == null)
+ if (st == null) {
st = getStackTrace(r.th_);
+ }
String[] s = FuLib.split(st, '\n', false, true);
for (int j = 0; j < s.length; j++) {
sb.setLength(0);
sb.append(" ");
sb.append(s[j]);
- if (cut_)
- for (int i = SW - 2; i < sb.length(); i += SW - 2)
+ if (cut_) {
+ for (int i = SW - 2; i < sb.length(); i += SW - 2) {
sb.insert(i, "\n ");
+ }
+ }
System.err.println(sb.toString());
- if (LOGSTREAM != null)
+ if (LOGSTREAM != null) {
LOGSTREAM.println(sb.toString());
+ }
}
}
System.err.flush();
- if (LOGSTREAM != null)
+ if (LOGSTREAM != null) {
LOGSTREAM.flush();
+ }
- if (r.recLevel_ >= FAILURE)
+ if (r.recLevel_ >= FAILURE) {
System.exit(-127);
+ }
}
}
}, "Fu Logger");
@@ -372,6 +395,7 @@
}
private static final class Record {
+
int recLevel_;
String msg_;
Throwable th_;
@@ -384,7 +408,6 @@
recTime_ = System.currentTimeMillis();
}
}
-
private static final Logger LOGGER = Logger.getLogger(FuLog.class.getName());
private static Level getLevel(int _level) {
@@ -433,16 +456,19 @@
}
}
- if ((msg == null) && (th != null))
+ if ((msg == null) && (th != null)) {
msg = th.getClass().getName();
+ }
- if (th instanceof InvocationTargetException)
+ if (th instanceof InvocationTargetException) {
th = ((InvocationTargetException) th).getTargetException();
-
- synchronized (QUEUE) {
- QUEUE.addElement(new Record(_level, msg, th)); //add
- QUEUE.notifyAll();
}
+ if (QUEUE != null) {
+ synchronized (QUEUE) {
+ QUEUE.addElement(new Record(_level, msg, th)); //add
+ QUEUE.notifyAll();
+ }
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|