[Jrevproxy-cvs] jRevProxy/src/cx/noe/jrevproxy/logging DataLogger.java,2.10,2.11 ILog.java,2.3,2.4
Status: Alpha
Brought to you by:
fnoe
|
From: <fn...@us...> - 2003-12-26 19:14:22
|
Update of /cvsroot/jrevproxy/jRevProxy/src/cx/noe/jrevproxy/logging
In directory sc8-pr-cvs1:/tmp/cvs-serv1441/src/cx/noe/jrevproxy/logging
Modified Files:
DataLogger.java ILog.java
Log Message:
merge with storem branch; updated suffixstring in datalogger
Index: DataLogger.java
===================================================================
RCS file: /cvsroot/jrevproxy/jRevProxy/src/cx/noe/jrevproxy/logging/DataLogger.java,v
retrieving revision 2.10
retrieving revision 2.11
diff -C2 -d -r2.10 -r2.11
*** DataLogger.java 29 May 2003 13:56:54 -0000 2.10
--- DataLogger.java 26 Dec 2003 19:14:19 -0000 2.11
***************
*** 29,33 ****
* DataLogger
*
! * @author <a href="mailto:fre...@no...">Frederik Noe</a>
* @version <tt>$Revision$</tt>
*/
--- 29,33 ----
* DataLogger
*
! * @author <a href="mailto:fre...@no...">Frederik Noe</a>
* @version <tt>$Revision$</tt>
*/
***************
*** 40,44 ****
private int level = INFO;
private boolean debug = false;
!
/**
* Creates a DataLogger instance
--- 40,47 ----
private int level = INFO;
private boolean debug = false;
! private final int PREFIXLENGTH = 7;
!
! private final String[] prefixStr = {"DUMP","DEBUG","METHOD","INFO"};
!
/**
* Creates a DataLogger instance
***************
*** 49,52 ****
--- 52,56 ----
*/
public DataLogger(String logpath) throws IllegalArgumentException {
+ // tdob, maybe we should look if the path is existing or creatable
if(logpath == null || logpath.length() == 0)
throw new IllegalArgumentException("A logpath cannot be null or empty");
***************
*** 108,112 ****
try {
PrintWriter ostream = new PrintWriter(getFileOutputStream());
! ostream.write("["+prefix+"] "+data+"\r\n");
ostream.close();
}
--- 112,130 ----
try {
PrintWriter ostream = new PrintWriter(getFileOutputStream());
!
! Throwable e = new Throwable();
! StackTraceElement[] stackElements = e.getStackTrace();
!
! // Find the method in the stack which isn't part of the logging
! int stackrecord = 0;
! while(stackElements[stackrecord].getMethodName().equalsIgnoreCase("log")) {
! if(stackElements.length-1 == stackrecord)
! break;
! stackrecord++;
! }
!
! String classname = "["+unmungeSimpleClassName(extractSimpleClassName(stackElements[stackrecord].getClassName()))+"."+stackElements[stackrecord].getMethodName()+"] ";
!
! ostream.write("["+prefix+"] "+ prefixStr[level] + getSuffixStr(level) + classname + data +"\r\n");
ostream.close();
}
***************
*** 118,121 ****
--- 136,152 ----
}
}
+
+ private String getSuffixStr(int level) {
+ int length = prefixStr[level].length();
+ StringBuffer buf = new StringBuffer("");
+ if(length < PREFIXLENGTH) {
+ for(int i = length; i< PREFIXLENGTH; i++) {
+ buf.append(' ');
+ }
+ }
+ else
+ buf.append(' ');
+ return buf.toString();
+ }
/**
***************
*** 156,159 ****
return (OutputStream) new FileOutputStream(getLogFileName(),true);
}
!
}
--- 187,253 ----
return (OutputStream) new FileOutputStream(getLogFileName(),true);
}
!
! public static String extractPackageName (String fullClassName)
! {
! if ((null == fullClassName) || ("".equals (fullClassName)))
! return "";
!
! // The package name is everything preceding the last dot.
! // Is there a dot in the name?
! int lastDot = fullClassName.lastIndexOf ('.');
!
! // Note that by fiat, I declare that any class name that has been
! // passed in which starts with a dot doesn't have a package name.
! if (0 >= lastDot)
! return "";
!
! // Otherwise, extract the package name.
! return fullClassName.substring (0, lastDot);
! }
!
! public static String extractSimpleClassName (String fullClassName)
! {
! if ((null == fullClassName) || ("".equals (fullClassName)))
! return "";
!
! // The simple class name is everything after the last dot.
! // If there's no dot then the whole thing is the class name.
! int lastDot = fullClassName.lastIndexOf ('.');
! if (0 > lastDot)
! return fullClassName;
!
! // Otherwise, extract the class name.
! return fullClassName.substring (++lastDot);
! }
!
! public static String extractDirectClassName (String simpleClassName)
! {
! if ((null == simpleClassName) || ("".equals (simpleClassName)))
! return "";
!
! // The direct class name is everything after the last '$', if there
! // are any '$'s in the simple class name. Otherwise, it's just
! // the simple class name.
! int lastSign = simpleClassName.lastIndexOf ('$');
! if (0 > lastSign)
! return simpleClassName;
!
! // Otherwise, extract the last class name.
! // Note that if you have a multiply-nested class, that this
! // will only extract the very last one. Extracting the stack of
! // nestings is left as an exercise for the reader.
! return simpleClassName.substring (++lastSign);
! }
!
! public static String unmungeSimpleClassName (String simpleClassName)
! {
! if ((null == simpleClassName) || ("".equals (simpleClassName)))
! return "";
!
! // Nested classes are set apart from top-level classes by using
! // the dollar sign '$' instead of a period '.' as the separator
! // between them and the top-level class that they sit
! // underneath. Let's undo that.
! return simpleClassName.replace ('$', '.');
! }
}
Index: ILog.java
===================================================================
RCS file: /cvsroot/jrevproxy/jRevProxy/src/cx/noe/jrevproxy/logging/ILog.java,v
retrieving revision 2.3
retrieving revision 2.4
diff -C2 -d -r2.3 -r2.4
*** ILog.java 27 Mar 2003 15:49:32 -0000 2.3
--- ILog.java 26 Dec 2003 19:14:19 -0000 2.4
***************
*** 22,31 ****
/**
- *
* ILog
*
! * @author <a href=mailto:fre...@no...> Frederik Noë</a>
* @version <tt>$Revision$</tt>
- *
*/
public interface ILog {
--- 22,29 ----
/**
* ILog
*
! * @author <a href="mailto:fre...@no...">Frederik Noe</a>
* @version <tt>$Revision$</tt>
*/
public interface ILog {
***************
*** 33,38 ****
public void log(Throwable e);
! public final int DEBUG = 0;
! public final int METHOD = 1;
! public final int INFO = 2;
}
--- 31,37 ----
public void log(Throwable e);
! public final int DUMP = 0;
! public final int DEBUG = 1;
! public final int METHOD = 2;
! public final int INFO = 3;
}
|