001 package railo.commons.io.log.sl4j; 002 003 004 import org.slf4j.Marker; 005 import org.slf4j.helpers.MarkerIgnoringBase; 006 import org.slf4j.spi.LocationAwareLogger; 007 008 import railo.commons.io.log.Log; 009 import railo.commons.io.log.LogAndSource; 010 import railo.commons.lang.ExceptionUtil; 011 import railo.runtime.op.Caster; 012 013 public final class LoggerAdapterImpl extends MarkerIgnoringBase implements LocationAwareLogger { 014 015 private static final long serialVersionUID = 3875268250734654111L; 016 017 private LogAndSource logger; 018 private String _name; 019 020 public LoggerAdapterImpl(LogAndSource logger, String name){ 021 this.logger=logger; 022 this._name=name; 023 } 024 025 public void debug(String msg) {log(Log.LEVEL_DEBUG,msg);} 026 public void error(String msg) {log(Log.LEVEL_ERROR,msg);} 027 public void info(String msg) {log(Log.LEVEL_INFO,msg);} 028 public void trace(String msg) {} 029 public void warn(String msg) {log(Log.LEVEL_WARN,msg);} 030 031 public void debug(String format, Object arg) {log(Log.LEVEL_DEBUG,format,arg);} 032 public void error(String format, Object arg) {log(Log.LEVEL_ERROR,format,arg);} 033 public void info(String format, Object arg) {log(Log.LEVEL_INFO,format,arg);} 034 public void trace(String format, Object arg) {} 035 public void warn(String format, Object arg) {log(Log.LEVEL_WARN,format,arg);} 036 037 public void debug(String format, Object arg1, Object arg2) {log(Log.LEVEL_DEBUG,format,arg1,arg2);} 038 public void error(String format, Object arg1, Object arg2) {log(Log.LEVEL_DEBUG,format,arg1,arg2);} 039 public void info(String format, Object arg1, Object arg2) {log(Log.LEVEL_DEBUG,format,arg1,arg2);} 040 public void trace(String format, Object arg1, Object arg2) {} 041 public void warn(String format, Object arg1, Object arg2) {log(Log.LEVEL_DEBUG,format,arg1,arg2);} 042 043 public void debug(String format, Object[] args) {log(Log.LEVEL_DEBUG,format,args);} 044 public void error(String format, Object[] args) {log(Log.LEVEL_DEBUG,format,args);} 045 public void info(String format, Object[] args) {log(Log.LEVEL_DEBUG,format,args);} 046 public void trace(String format, Object[] args) {} 047 public void warn(String format, Object[] args) {log(Log.LEVEL_DEBUG,format,args);} 048 049 public void debug(String msg, Throwable t) {log(Log.LEVEL_DEBUG,msg,t);} 050 public void error(String msg, Throwable t) {log(Log.LEVEL_DEBUG,msg,t);} 051 public void info(String msg, Throwable t) {log(Log.LEVEL_DEBUG,msg,t);} 052 public void trace(String msg, Throwable t) {} 053 public void warn(String msg, Throwable t) {log(Log.LEVEL_DEBUG,msg,t);} 054 055 private void log(int level, String msg) { 056 logger.log(level, _name, msg); 057 } 058 private void log(int level, String msg, Throwable t) { 059 log(level, msg+"\n"+ExceptionUtil.getStacktrace(t,true)); 060 } 061 062 private void log(int level, String format, Object arg) { 063 log(level, Caster.toString(arg,"")); 064 } 065 private void log(int level, String format, Object arg1, Object arg2) { 066 log(level, Caster.toString(arg1,"")+"\n"+Caster.toString(arg2,"")); 067 } 068 private void log(int level, String format, Object[] args) { 069 StringBuilder sb=new StringBuilder(); 070 for(int i=0;i<args.length;i++){ 071 sb.append(Caster.toString(args[i],"")); 072 sb.append("\n"); 073 } 074 log(level, sb.toString().trim()); 075 } 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 public boolean isDebugEnabled() { 093 return logger.getLogLevel()<=Log.LEVEL_DEBUG; 094 } 095 096 public boolean isErrorEnabled() { 097 return logger.getLogLevel()<=Log.LEVEL_ERROR; 098 } 099 100 public boolean isInfoEnabled() { 101 return logger.getLogLevel()<=Log.LEVEL_INFO; 102 } 103 104 public boolean isTraceEnabled() { 105 return false; 106 } 107 108 public boolean isWarnEnabled() { 109 return logger.getLogLevel()<=Log.LEVEL_WARN; 110 } 111 112 113 114 115 116 117 118 119 120 121 122 public void log(Marker marker, String arg1, int arg2, String arg3,Throwable arg4) { 123 // log(level, Caster.toString(arg1,"")+"\n"+Caster.toString(arg2,"")+"\n"+Caster.toString(arg3,"")); 124 } 125 126 public void log(Marker arg0, String arg1, int arg2, String arg3, 127 Object[] arg4, Throwable arg5) { 128 // TODO Auto-generated method stub 129 130 } 131 132 }