Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
commit
f2c3c58303
|
@ -48,6 +48,7 @@ src/test/resources/font
|
|||
src/main/resources/WEB-INF/vm/outFile
|
||||
target/
|
||||
*.back
|
||||
!/src/main/youhong_ai_jitu_src/selfdev/util/log
|
||||
# 老项目代码
|
||||
#/lib/jitulib/
|
||||
#/lib/classbean
|
||||
|
|
|
@ -323,6 +323,16 @@ public class HttpUtils {
|
|||
return baseRequest(httpConnection, httpGet);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2>删除方法调用</h2>
|
||||
*
|
||||
* @param url 地址
|
||||
* @param params 参数
|
||||
* @param headers 请求头
|
||||
* @return 请求结果
|
||||
* @throws IOException 异常
|
||||
*/
|
||||
|
||||
public ResponeVo apiDelete(String url, Map<String, Object> params, Map<String, String> headers) throws IOException {
|
||||
Map<String, Object> paramsMap = paramsHandle(params);
|
||||
String getUrl = urlHandle(url, paramsMap);
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package selfdev.util.log;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import weaver.general.BaseBean;
|
||||
import weaver.general.GCONST;
|
||||
|
||||
/**
|
||||
* 日志工具类
|
||||
* @author KangMD
|
||||
* 1、2019-01-29 add by KangMD
|
||||
*/
|
||||
|
||||
public class LogTool {
|
||||
private BufferedWriter logPrint;
|
||||
private String logFile = "";
|
||||
private String logPath="";
|
||||
private boolean systemlog=false;//是否写系统日记
|
||||
static SimpleDateFormat newDf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
static SimpleDateFormat df =new SimpleDateFormat("yyyy-MM-dd");
|
||||
static BaseBean log=new BaseBean();
|
||||
public LogTool(){
|
||||
//if(logFile == null || logFile.trim().equals("") || !logFile.equals(getLogFile())){
|
||||
// newLog();
|
||||
//}
|
||||
}
|
||||
public LogTool(String logPath,boolean systemlog){
|
||||
this.logPath=logPath;
|
||||
this.systemlog=systemlog;
|
||||
}
|
||||
private String getLogFile(){
|
||||
//获取当前系统路径
|
||||
String sysPath=GCONST.getRootPath();
|
||||
if(sysPath==null){
|
||||
sysPath=System.getProperty("user.dir");
|
||||
}
|
||||
if(!"".equals(logPath)){
|
||||
if(logPath.endsWith("/")){
|
||||
sysPath += logPath+df.format(new Date())+".log";
|
||||
}else{
|
||||
sysPath += logPath+"/"+df.format(new Date())+".log";
|
||||
}
|
||||
}else {
|
||||
sysPath += "/log/dev/"+df.format(new Date())+".log";
|
||||
}
|
||||
return sysPath;
|
||||
}
|
||||
|
||||
private void newLog(){
|
||||
logFile = getLogFile();
|
||||
try{
|
||||
//logPrint = new PrintWriter(new FileWriter(logFile, true), true);
|
||||
logPrint = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (logFile,true),"UTF-8"));
|
||||
}catch(IOException e){
|
||||
try{
|
||||
File file=new File(logFile);
|
||||
if(!file.getParentFile().exists()) {
|
||||
//如果目标文件所在的目录不存在,则创建父目录
|
||||
if(file.getParentFile().mkdirs()){
|
||||
file.createNewFile();
|
||||
}
|
||||
}
|
||||
//logPrint = new PrintWriter(new FileWriter(logFile, true), true);
|
||||
logPrint = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (logFile,true),"UTF-8"));
|
||||
}catch(IOException ex){
|
||||
log.writeLog("Log记录出错了",ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeLog(Object msg) {
|
||||
if(systemlog){
|
||||
log.writeLog(msg);
|
||||
}
|
||||
newLog();
|
||||
try {
|
||||
logPrint.write(newDf.format(new Date()) + ": " + msg);
|
||||
logPrint.newLine();//每次换行
|
||||
logPrint.flush();
|
||||
logPrint.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeLog(String msg,Throwable e) {
|
||||
if(systemlog){
|
||||
log.writeLog(msg,e);
|
||||
}
|
||||
newLog();
|
||||
try {
|
||||
logPrint.write(newDf.format(new Date()) + ": " + msg);
|
||||
logPrint.newLine();//每次换行
|
||||
//e.printStackTrace(logPrint);
|
||||
logPrint.flush();
|
||||
logPrint.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue