老大工具包补充
parent
e9bd4fd92a
commit
a11b0b9cf0
|
@ -57,7 +57,16 @@ public class GCONST {
|
|||
private static Properties wsactionProp = null;
|
||||
private static Properties esbactionProp = null;
|
||||
private static Properties sapactionProp = null;
|
||||
/**
|
||||
* @author youHong.ai
|
||||
* 添加文件地址
|
||||
*/
|
||||
private static String systemFilePath = "";
|
||||
/**
|
||||
* @author youHong.ai
|
||||
* 添加日志地址
|
||||
*/
|
||||
private static String logPath = "";
|
||||
private static Properties coremailProp = null;
|
||||
public static String PROP_UTF8 = "UTF-8";
|
||||
public static String XML_UTF8 = "UTF-8";
|
||||
|
@ -177,12 +186,21 @@ public class GCONST {
|
|||
return propertyPath;
|
||||
}
|
||||
|
||||
public static String setLogPath() {
|
||||
return ROOT_PATH + "log" + File.separatorChar;
|
||||
public static void setLogPath(String _logPath) {
|
||||
logPath = _logPath;
|
||||
(new BaseBean()).writeLog("systemFilePath:" + getMyGrandpaStackTrace() + " value=" + _logPath);
|
||||
}
|
||||
|
||||
public static String getLogPath() {
|
||||
return ROOT_PATH + "log" + File.separatorChar;
|
||||
if("".equals(logPath)){
|
||||
return ROOT_PATH + "log" + File.separatorChar;
|
||||
}else{
|
||||
if(logPath.endsWith(String.valueOf(File.separatorChar))){
|
||||
return logPath;
|
||||
}else {
|
||||
return logPath + File.separatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getPrintMoudlePath() {
|
||||
|
|
|
@ -0,0 +1,98 @@
|
|||
package weaver.zwl.common;
|
||||
|
||||
|
||||
import weaver.common.StringUtil;
|
||||
import weaver.conn.RecordSetTrans;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.User;
|
||||
import weaver.interfaces.workflow.action.Action;
|
||||
import weaver.soa.workflow.request.RequestInfo;
|
||||
import weaver.workflow.request.RequestManager;
|
||||
|
||||
/**
|
||||
* 自定义Action实现类,添加通用参数
|
||||
* @author bleach
|
||||
* @date 2019-10-09
|
||||
* @verion 1.0
|
||||
*/
|
||||
public abstract class CusBaseAction extends ToolUtil implements Action {
|
||||
//当前类名称
|
||||
private String className = this.getClass().getName();
|
||||
|
||||
|
||||
protected RequestInfo requestInfo;//流程请求信息实体类
|
||||
protected RecordSetTrans rsts = null;//流程操作事务数据集
|
||||
protected String tablename;//当前流程表单名称
|
||||
protected String requestId;//流程请求ID
|
||||
protected String workflowId;//流程类型ID
|
||||
protected User user = null;//当前用户
|
||||
protected int creater = -1;//流程创建人ID
|
||||
protected RequestManager reqManager = null;
|
||||
protected String[] baseArray = new String[3];
|
||||
|
||||
protected abstract String handle();//Action 具体操作
|
||||
|
||||
/**
|
||||
* 实现父类方法
|
||||
*
|
||||
* @param requestInfo
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public String execute(RequestInfo requestInfo) {
|
||||
this.requestInfo = requestInfo;
|
||||
|
||||
this.rsts = requestInfo.getRsTrans();
|
||||
if (this.rsts == null) {
|
||||
rsts = new RecordSetTrans();
|
||||
}
|
||||
this.initParam();
|
||||
return handle();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化常用参数
|
||||
*/
|
||||
private void initParam() {
|
||||
this.requestId = StringUtil.vString(requestInfo.getRequestid());
|
||||
this.workflowId = StringUtil.vString(requestInfo.getWorkflowid());
|
||||
this.reqManager = requestInfo.getRequestManager();
|
||||
this.user = reqManager.getUser();
|
||||
this.creater = reqManager.getCreater();
|
||||
|
||||
this.tablename = requestInfo.getRequestManager().getBillTableName();
|
||||
|
||||
//通过系统请求管理类获取表单名称失败,再次查询
|
||||
if ("".equals(this.tablename)) {
|
||||
tablename = getBillTableNameByWorkflowId(this.workflowId);
|
||||
}
|
||||
|
||||
//获取流程基础数据
|
||||
String select_base_sql = "select * from workflow_requestbase where requestid = ?";
|
||||
try {
|
||||
if (rsts == null) {
|
||||
rsts = new RecordSetTrans();
|
||||
}
|
||||
|
||||
String request_name = "";
|
||||
String request_mark = "";
|
||||
|
||||
if (rsts.executeQuery(select_base_sql, requestId)) {
|
||||
while (rsts.next()) {
|
||||
request_name = Util.null2String(rsts.getString("requestname"));
|
||||
request_mark = Util.null2String(rsts.getString("requestmark"));
|
||||
}
|
||||
}
|
||||
|
||||
baseArray[0] = this.requestId;
|
||||
baseArray[1] = request_name;
|
||||
baseArray[2] = request_mark;
|
||||
|
||||
this.writeNewDebuggerLog(className, "main_requestname:[" + request_name + "],main_requestmark:[" + request_mark + "],workflowid:[" + workflowId + "],requestid:[" + requestId + "],tablename:[" + tablename + "]");
|
||||
} catch (Exception e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
this.writeNewDebuggerLog(className, "get workflow dataset error:[" + e1.getMessage() + "/" + e1.toString() + "]");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,501 @@
|
|||
package weaver.zwl.common;
|
||||
|
||||
import weaver.conn.ConnStatementDataSource;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.GCONST;
|
||||
import weaver.general.TimeUtil;
|
||||
import weaver.general.Util;
|
||||
import weaver.zwl.common.logging.Logger;
|
||||
import weaver.zwl.common.logging.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 常用工具方法-公用类
|
||||
* @author bleach
|
||||
* @date 2018-01-18
|
||||
* @version 2.0 Modify By Weilin.Zhu 添加日志级别 2018-12-05
|
||||
* @version 3.0 Modify By Weilin.Zhu 修改日志输出方式,使用log4j 2020-03-10
|
||||
*/
|
||||
public class ToolUtil extends BaseBean {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger("cus");
|
||||
|
||||
/**
|
||||
* 是否开启调试模式
|
||||
*/
|
||||
boolean isDebug = true;
|
||||
|
||||
/**
|
||||
* 日志层级 (0:调试[Debugger] 1:警告[Warning] 2:错误[Error]
|
||||
*/
|
||||
private int logLevel = 2;
|
||||
|
||||
private RecordSet rs = new RecordSet();
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*/
|
||||
public ToolUtil() {
|
||||
// TODO Auto-generated constructor stub
|
||||
logger = LoggerFactory.getLogger("cus");
|
||||
//是否开启日志模式
|
||||
String isopen = getSystemParamValue("Debug_Mode");
|
||||
|
||||
//输出日志级别
|
||||
logLevel = Util.getIntValue(getSystemParamValue("Logger_Level"),-1);
|
||||
|
||||
if("1".equals(isopen)){
|
||||
isDebug = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据流程类型ID获取其对应的表单名称
|
||||
* @param workflowid 流程类型ID
|
||||
* @return 字符串
|
||||
*/
|
||||
public String getBillTableNameByWorkflowId(String workflowid){
|
||||
String tablename = "";
|
||||
|
||||
if(!"".equals(workflowid)){
|
||||
String select_data = "select tablename from workflow_bill where id in (select formid from workflow_base where id = ?)";
|
||||
|
||||
if(rs.executeQuery(select_data, workflowid)){
|
||||
if(rs.next()){
|
||||
tablename = Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tablename;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询满足模糊查询的所有标识集合
|
||||
* @param likestr 模糊条件
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> getSystemParamValueMap(String likestr){
|
||||
return getSystemParamList(likestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询系统中所有参数配置
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> getAllSystemParamValue(){
|
||||
return getSystemParamList("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取参数集合
|
||||
* @param likestr 模糊查询的条件
|
||||
* @return 集合
|
||||
*/
|
||||
private Map<String,String> getSystemParamList(String likestr){
|
||||
Map<String,String> param_map = new HashMap<String, String>();
|
||||
|
||||
String select_sql = "select uuid,paramvalue from uf_systemconfig";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(!"".equals(likestr)){
|
||||
select_sql += " where uuid like '%" + likestr + "%'";
|
||||
}
|
||||
|
||||
if(rs.execute(select_sql)){
|
||||
while(rs.next()){
|
||||
String uuid = Util.null2String(rs.getString(1));
|
||||
String paramvalue = Util.null2String(rs.getString(2));
|
||||
|
||||
param_map.put(uuid, paramvalue);
|
||||
}
|
||||
}
|
||||
|
||||
return param_map;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统参数设置值
|
||||
* @param uuid 参数标识
|
||||
* @return 返回配置值
|
||||
*/
|
||||
public String getSystemParamValue(String uuid){
|
||||
String paramvalue = "";
|
||||
|
||||
if(!"".equals(uuid)){
|
||||
String select_sql = "select paramvalue from uf_systemconfig where uuid = ?";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
rs.executeQuery(select_sql,uuid);
|
||||
if(rs.next()){
|
||||
paramvalue = Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
|
||||
return paramvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用数据库值,根据规则转换,获取其最终结果
|
||||
* @param cus_sql 自定义转换的SQL
|
||||
* @param value 参数值
|
||||
* @return 配置值
|
||||
*/
|
||||
public String getValueByChangeRule(String cus_sql,String value){
|
||||
|
||||
return getValueByChangeRule(cus_sql,value,"");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用数据库值,根据规则转换,获取其最终结果
|
||||
* @param cus_sql 自定义转换的SQL
|
||||
* @param value 参数值
|
||||
* @param requestid 流程请求ID
|
||||
* @return
|
||||
*/
|
||||
public String getValueByChangeRule(String cus_sql,String value,String requestid){
|
||||
|
||||
return getValueByChangeRule(cus_sql,value,requestid,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用数据库值,根据规则转换,获取其最终结果
|
||||
* @param cus_sql 自定义转换的SQL
|
||||
* @param value 参数值
|
||||
* @param requestid 流程请求ID
|
||||
* @param detailKeyvalue 明细表主键值
|
||||
* @return
|
||||
*/
|
||||
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue){
|
||||
return getValueByChangeRule(cus_sql,value,requestid,detailKeyvalue,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用数据库值,根据规则转换,获取其最终结果
|
||||
* @param cus_sql 自定义转换的SQL
|
||||
* @param value 参数值
|
||||
* @param requestid 流程请求ID
|
||||
* @param detailKeyvalue 明细表主键值
|
||||
* @pram datasourceid 外部数据源ID
|
||||
* @return
|
||||
*/
|
||||
public String getValueByChangeRule(String cus_sql,String value,String requestid,int detailKeyvalue,String datasourceid){
|
||||
String endValue = "";
|
||||
|
||||
cus_sql = cus_sql.replace(" ", " ");
|
||||
|
||||
cus_sql = cus_sql.replace("{?dt.id}", String.valueOf(detailKeyvalue));
|
||||
|
||||
//参数进行替换
|
||||
String sqlString = cus_sql.replace("{?requestid}", requestid);
|
||||
|
||||
sqlString = sqlString.replace("?", value);
|
||||
|
||||
sqlString = ToDBC(sqlString);
|
||||
try {
|
||||
if(datasourceid != null && !"".equals(datasourceid)){
|
||||
ConnStatementDataSource csds = new ConnStatementDataSource(datasourceid);
|
||||
|
||||
csds.setStatementSql(sqlString);
|
||||
|
||||
csds.executeQuery();
|
||||
|
||||
if(csds.next()){
|
||||
endValue = Util.null2String(csds.getString(1));
|
||||
}
|
||||
|
||||
csds.close();
|
||||
}else{
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
if(rs.executeQuery(sqlString)){
|
||||
rs.next();
|
||||
|
||||
endValue = Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return endValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用数据库值,根据规则转换,获取其最终结果
|
||||
* @param cus_sql 自定义转换的SQL
|
||||
* @param value 参数值
|
||||
* @return
|
||||
*/
|
||||
public String getValueByChangeRule_SingleParam(String cus_sql,String value){
|
||||
String endValue = "";
|
||||
|
||||
cus_sql = cus_sql.replace(" ", " ");
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(rs.executeQuery(cus_sql,value)){
|
||||
rs.next();
|
||||
|
||||
endValue = Util.null2String(rs.getString(1));
|
||||
}
|
||||
|
||||
return endValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全角转半角
|
||||
* @param input
|
||||
* @return
|
||||
*/
|
||||
public String ToDBC(String input) {
|
||||
char c[] = input.toCharArray();
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (c[i] == '\u3000') {
|
||||
c[i] = ' ';
|
||||
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
|
||||
c[i] = (char) (c[i] - 65248);
|
||||
}
|
||||
}
|
||||
String returnString = new String(c);
|
||||
return returnString;
|
||||
}
|
||||
/**
|
||||
* 根据字段ID获取其对应的字段名称
|
||||
* @param fieldid
|
||||
* @return
|
||||
*/
|
||||
public String getFieldNameByFieldid(int fieldid){
|
||||
if(fieldid > 0){
|
||||
return getFieldNameByFieldid(String.valueOf(fieldid));
|
||||
}else{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据字段ID获取其对应的字段名称
|
||||
* @param fieldid
|
||||
* @return
|
||||
*/
|
||||
public String getFieldNameByFieldid(String fieldid){
|
||||
String fieldname = "";
|
||||
|
||||
if(!"".equals(fieldid)){
|
||||
|
||||
if(fieldid.startsWith(",")){
|
||||
fieldid = fieldid.substring(1);
|
||||
}
|
||||
|
||||
if(fieldid.endsWith(",")){
|
||||
fieldid =fieldid.substring(0,fieldid.length() - 1);
|
||||
}
|
||||
|
||||
String select_sql = "select fieldname from workflow_billfield where id in (" + fieldid + ")";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(rs.execute(select_sql)){
|
||||
while(rs.next()){
|
||||
|
||||
fieldname += "," + Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(fieldname.startsWith(",")){
|
||||
fieldname = fieldname.substring(1);
|
||||
}
|
||||
|
||||
return fieldname;
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出调试日志
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeDebuggerLog(String logstr){
|
||||
if(logLevel >= 0){
|
||||
logger.info(logstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出调试日志
|
||||
* @param className 类名称
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeDebuggerLog(String className,String logstr){
|
||||
if(logLevel >= 0){
|
||||
logger.info(logstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出警告日志
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeWarningLog(String logstr){
|
||||
if(logLevel >= 1){
|
||||
logger.warn(logstr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 输出警告日志
|
||||
* @param className 类名称
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeWarningLog(String className,String logstr){
|
||||
if(logLevel >= 1){
|
||||
logger.warn(logstr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出错误日志
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeErrorLog(String logstr){
|
||||
logger.error(logstr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 输出错误日志
|
||||
* @param className 类名称
|
||||
* @param logstr 日志信息
|
||||
*/
|
||||
public void writeErrorLog(String className,String logstr){
|
||||
logger.error(logstr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 日志输出
|
||||
* @param logstr
|
||||
*/
|
||||
public void writeDebugLog(Object logstr){
|
||||
logger.info(logstr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志输出
|
||||
* @param logstr
|
||||
*/
|
||||
public void writeNewDebuggerLog(Object o,Object logstr){
|
||||
logger.info(logstr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入同步的日志文件
|
||||
* @param o
|
||||
* @param s
|
||||
* @deprecated 该写入文件的日志输出方式删除
|
||||
*/
|
||||
protected void writeNewLog(String o,String s){
|
||||
try {
|
||||
String filename = "cus_" + TimeUtil.getCurrentDateString() + "_ecology.log";
|
||||
|
||||
|
||||
String folder = GCONST.getRootPath() + "log" + File.separatorChar + "cus";
|
||||
|
||||
//this.writeDebugLog("folder:[" + folder + "]");
|
||||
|
||||
File f = new File(folder);
|
||||
|
||||
// 创建文件夹
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
|
||||
f = new File(folder + File.separatorChar + filename);
|
||||
//文件不存在,则直接创建
|
||||
if(!f.exists()){
|
||||
f.createNewFile();
|
||||
}
|
||||
|
||||
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, true)));
|
||||
|
||||
out.write("[" + o + "][" + TimeUtil.getCurrentTimeString() + "]:"+ s + "\r\n");
|
||||
|
||||
//关闭写入流
|
||||
out.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
writeDebugLog("创建日志文件存在异常:[" + e.getMessage() + "/" + e.toString() + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据建模模块ID获取其对应的表单名称
|
||||
* @param modeid 模块ID
|
||||
* @return 建模表单名称
|
||||
*/
|
||||
public String getTableNameByModeID(int modeid){
|
||||
String modeTableName = "";
|
||||
|
||||
if(modeid > 0){
|
||||
String select_sql = "select tablename from modeinfo m left join workflow_bill wb on m.formid = wb.id " +
|
||||
"left join ModeFormExtend me on me.formid = wb.id where m.id = ?";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(rs.executeQuery(select_sql,modeid)){
|
||||
if(rs.next()){
|
||||
modeTableName = Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return modeTableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据流程请求ID获取其对应的表单名称
|
||||
* @param requestid
|
||||
* @return
|
||||
*/
|
||||
public String getTableNameByRequestID(int requestid) {
|
||||
String billTableName = "";
|
||||
if(requestid > 0) {
|
||||
String select_sql = "select wbi.tablename from workflow_requestbase wr inner join workflow_base wb on wr.workflowid = wb.id "
|
||||
+ "inner join workflow_bill wbi on wbi.id = wb.formid where wr.requestid = ?";
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
|
||||
if(rs.executeQuery(select_sql,requestid)){
|
||||
if(rs.next()){
|
||||
billTableName = Util.null2String(rs.getString(1));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return billTableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isDebug
|
||||
*/
|
||||
public boolean isDebug() {
|
||||
return isDebug;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package weaver.zwl.common.logging;
|
||||
|
||||
/**
|
||||
* 写日志(log4j)
|
||||
* @date 2020-03-10
|
||||
* @version 1.0
|
||||
*/
|
||||
public class Log4JLogger implements Logger {
|
||||
|
||||
private org.apache.log4j.Logger log;
|
||||
//类名
|
||||
private String classname;
|
||||
|
||||
@Override
|
||||
public String getClassname() {
|
||||
return classname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClassname(String classname) {
|
||||
this.classname = classname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return log.isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInfoEnabled() {
|
||||
return log.isInfoEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.debug(classname+"."+method+"() - "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug(Object message, Throwable exception) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.debug(classname+"."+method+"() - "+message, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.info(classname+"."+method+"() - "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void info(Object message, Throwable exception) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.info(classname+"."+method+"() - "+message, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.warn(classname+"."+method+"() - "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(Object message, Throwable exception) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.warn(classname+"."+method+"() - "+message, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.error(classname+"."+method+"() - "+message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(Object message, Throwable exception) {
|
||||
String method = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
log.error(classname+"."+method+"() - "+message, exception);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(String name) {
|
||||
if("".equals(name)) {
|
||||
name = "cuslog";
|
||||
}
|
||||
log = org.apache.log4j.Logger.getLogger(name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
package weaver.zwl.common.logging;
|
||||
|
||||
/**
|
||||
* 日志接口(写)
|
||||
*
|
||||
* @author zwl
|
||||
* @date 2020-03-10
|
||||
*/
|
||||
public interface Logger {
|
||||
|
||||
public boolean isDebugEnabled();
|
||||
|
||||
/**
|
||||
* 打印debug日志
|
||||
* @param message 消息
|
||||
*/
|
||||
public void debug(Object message);
|
||||
|
||||
/**
|
||||
* 打印debug日志
|
||||
* @param message 消息
|
||||
* @param exception 异常
|
||||
*/
|
||||
public void debug(Object message, Throwable exception);
|
||||
|
||||
public boolean isInfoEnabled();
|
||||
|
||||
/**
|
||||
* 打印info日志
|
||||
* @param message 消息
|
||||
*/
|
||||
public void info(Object message);
|
||||
|
||||
|
||||
/**
|
||||
* 打印info日志
|
||||
* @param message 消息
|
||||
* @param exception 异常
|
||||
*/
|
||||
public void info(Object message, Throwable exception);
|
||||
|
||||
/**
|
||||
* 打印warn日志
|
||||
* @param message 消息
|
||||
*/
|
||||
public void warn(Object message);
|
||||
|
||||
/**
|
||||
* 打印warn日志
|
||||
* @param message 消息
|
||||
* @param exception 异常
|
||||
*/
|
||||
public void warn(Object message, Throwable exception);
|
||||
|
||||
/**
|
||||
* 打印error日志
|
||||
* @param message
|
||||
*/
|
||||
public void error(Object message);
|
||||
|
||||
/**
|
||||
* 打印error日志
|
||||
* @param message 消息
|
||||
* @param exception 异常
|
||||
*/
|
||||
public void error(Object message, Throwable exception);
|
||||
|
||||
public String getClassname();
|
||||
|
||||
public void setClassname(String classname);
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*
|
||||
* @param name logger名称
|
||||
*/
|
||||
public void init(String name);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package weaver.zwl.common.logging;
|
||||
|
||||
|
||||
/**
|
||||
* 日志工厂类
|
||||
*
|
||||
* @author zwl
|
||||
* @date 2020-03-10
|
||||
* @version 1.0
|
||||
*/
|
||||
public class LoggerFactory {
|
||||
private static final String loggerName = "cus";
|
||||
|
||||
public static Logger getLogger(String LogName, String clazz) {
|
||||
if("".equals(LogName)) {
|
||||
LogName = loggerName;
|
||||
}
|
||||
Logger logger = new Log4JLogger();
|
||||
logger.setClassname(clazz);
|
||||
logger.init(LogName);
|
||||
return logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类的logger对象
|
||||
* @param clazz
|
||||
* @return
|
||||
*/
|
||||
public static Logger getLogger(Class<?> clazz) {
|
||||
return getLogger(loggerName,clazz.getCanonicalName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定类的logger对象
|
||||
* @param className
|
||||
* @return
|
||||
*/
|
||||
public static Logger getLogger(String className) {
|
||||
return getLogger(loggerName,className);
|
||||
}
|
||||
/**
|
||||
* 获取未指定指定类的logger对象
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public static Logger getLogger() {
|
||||
String className = Thread.currentThread().getStackTrace()[2].getClassName();
|
||||
return getLogger(loggerName, className);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ public class BaseTest {
|
|||
GCONST.setServerName("ecology");
|
||||
GCONST.setRootPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/src/main/resources/");
|
||||
GCONST.setSystemFilePath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/file");
|
||||
GCONST.setLogPath("/Users/aoey.oct.22/company/Fan_wei/code/idea/ecology9-project/log");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue