001 002package gudusoft.gsqlparser.pp.logger; 003 004public class PPLoggerRecord 005{ 006 007 private String className; 008 private String methodName; 009 private String fileName; 010 private Throwable e; 011 private int logLevel; 012 private int stackLevel; 013 private int lineNum; 014 private String msg; 015 016 /** 017 * @param logLevel 018 * the log level 019 * @param msg 020 * the log message 021 */ 022 public PPLoggerRecord( int logLevel, String msg, Throwable e ) 023 { 024 this( logLevel, 0, msg, e ); 025 } 026 027 /** 028 * 029 * @param logLevel 030 * the log level 031 * @param stackLevel 032 * the stack level, the min level is zero 033 * @param msg 034 * the log message 035 */ 036 public PPLoggerRecord( int logLevel, int stackLevel, String msg, Throwable e ) 037 { 038 this.logLevel = logLevel; 039 this.stackLevel = stackLevel; 040 this.msg = msg; 041 this.e = e; 042 this.inferCaller( ); 043 044 } 045 046 private void inferCaller( ) 047 { 048 // Get the stack trace. 049 StackTraceElement stack[] = ( new Throwable( ) ).getStackTrace( ); 050 // First, search back to a method in the Logger class. 051 int ix = 0; 052 while ( ix < stack.length ) 053 { 054 StackTraceElement frame = stack[ix]; 055 String cname = frame.getClassName( ); 056 if ( cname.equals( gudusoft.gsqlparser.pp.logger.PPLogger.class.getName( ) ) ) 057 { 058 break; 059 } 060 ix++; 061 } 062 ix += this.stackLevel; 063 // Now search for the first frame before the "Logger" class. 064 while ( ix < stack.length ) 065 { 066 StackTraceElement frame = stack[ix]; 067 String cname = frame.getClassName( ); 068 if ( !cname.equals( gudusoft.gsqlparser.pp.logger.PPLogger.class.getName( ) ) ) 069 { 070 // We've found the relevant frame. 071 this.className = cname; 072 this.methodName = frame.getMethodName( ); 073 this.lineNum = frame.getLineNumber( ); 074 this.fileName = frame.getFileName( ); 075 return; 076 } 077 ix++; 078 } 079 } 080 081 public String getClassName( ) 082 { 083 return className; 084 } 085 086 public String getMethodName( ) 087 { 088 return methodName; 089 } 090 091 public int getStackLevel( ) 092 { 093 return stackLevel; 094 } 095 096 public String getMsg( ) 097 { 098 return msg; 099 } 100 101 public int getLogLevel( ) 102 { 103 return logLevel; 104 } 105 106 public Throwable getE( ) 107 { 108 return e; 109 } 110 111 public int getLineNum( ) 112 { 113 return lineNum; 114 } 115 116 public String getFileName( ) 117 { 118 return fileName; 119 } 120}