All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.docshare.log.Log Maven / Gradle / Ivy

Go to download

An efficient, fast, convenient, easy to learn, easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can run independently, and it can also be applied to traditional Java Web projects. It is an efficient, fast, convenient, easy to learn and easy to use MVC framework and ORM framework. It is seamless compatible with JSTL and supports FreeMarker. It can be run on its own, or it can be applied to traditional Java Web projects

There is a newer version: 2023.06.19
Show newest version
package org.docshare.log;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSON;


public class Log {
	public static boolean showClass = false;
	public static String getCaller() {  
	    StackTraceElement[] stack = (new Throwable()).getStackTrace(); 
	    for(int i=0;i void e(T i) {
		if(!Level.ERROR.isGreaterOrEqual(level)){
			return ;
		}
		String s = i.toString();
		if(i instanceof Throwable){
			s = getErrMsg((Throwable) i);
		}
		
		log.error(W(s));
		
	}
	public static  void e(String f , String...args){
		if(!Level.ERROR.isGreaterOrEqual(level)){
			return ;
		}
		StringBuilder sBuffer =new StringBuilder();
		for(String t:args){
			sBuffer.append(t);
		}
		e(sBuffer.toString());
	}

	public static  void d(T str) { 
		if(!Level.DEBUG.isGreaterOrEqual(level)){
			return ;
		}
		log.debug(W(str.toString()));
	}
	public static  void d(String ...arr){
		if(!Level.DEBUG.isGreaterOrEqual(level)){
			return ;
		}
		StringBuilder sBuffer =new StringBuilder();
		for(String t:arr){
			sBuffer.append(t);
		}
		log.debug(W(sBuffer.toString()));
	}
	public static String getErrMsg(Throwable e){
		ByteArrayOutputStream buf = new java.io.ByteArrayOutputStream();
		PrintWriter pw = new java.io.PrintWriter(buf, true); 
		e.printStackTrace(pw);
		pw.flush();
		pw.close();
		String  expMessage = buf.toString();
		
		return expMessage;
	}
	
	@SuppressWarnings("rawtypes")
	public static void map(Map m){
		StringBuilder sb = new StringBuilder();
		for(Object k:m.keySet()){
			sb.append(',').append(k).append('=').append(m.get(k));
		}
		sb.append(']');
		sb.setCharAt(0, '[');
		sb.insert(0, "MAP");
		String s= sb.toString();
		Log.i(s);
	}

	public static void w(String m) {
		if(!Level.WARN.isGreaterOrEqual(level)){
			return ;
		}
		log.warn(W(m));
	}

	public static void i(String s, Object...args) {
		if(!Level.INFO.isGreaterOrEqual(level)){
			return ;
		}
		String str = String.format(s, args);
		log.info(str);
	}

	public static void v(Object obj) {
		if(!Level.TRACE.isGreaterOrEqual(level)){
			return ;
		}
		log.trace(W(obj.toString()));
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy