logoperation.jsp
2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.FileReader" %>
<%@ page import="java.io.FileNotFoundException" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.io.RandomAccessFile" %>
<!--
qc:271653日志监测
-->
<%!
public String readLastLine(File file, String charset,int limitLineCount){
if (!file.exists() || file.isDirectory() || !file.canRead()) {
return null;
}
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "r");
long len = raf.length();
if (len == 0L) {
return "";
} else {
long pos = len - 1;
int linecount=1;
while (pos > 0) {
pos--;
raf.seek(pos);
if (raf.readByte() == '\n') {
if(linecount == limitLineCount) {
break;
}
linecount++;
}
}
if (pos == 0) {
raf.seek(0);
}
byte[] bytes = new byte[(int) (len - pos)];
raf.read(bytes);
if (charset == null) {
return new String(bytes);
} else {
return new String(bytes, charset);
}
}
} catch (Exception e) {
} finally {
if (raf != null) {
try {
raf.close();
} catch (Exception e2) {
}
}
}
return null;
}
%>
<%
if(!HrmUserVarify.checkUserRight("tail:log",user)) {
response.sendRedirect("/notice/noright.jsp") ;
return ;
}
int lines = Integer.parseInt(request.getParameter("lines"));
String module = request.getParameter("module");
String seldate = request.getParameter("seldate");
String strs="";
String basePath = request.getRealPath("/");//取得当前目录的路径
String path = (basePath+"/log/"+module+ ("".equals(seldate)?"":"_"+seldate+".log")).replace("\\","/").replace("\\\\","/").replace("//","/");
String charset="gbk";
File f = new File(path);
if (f.exists())
{
strs="<b>"+readLastLine(f, charset, lines).replace("\n", "</b></td></tr><tr><td colspan=\"4\"><b>") ;
out.println( strs);
} else
{
//文件不存在
out.println( SystemEnv.getHtmlLabelName(18493,user.getLanguage())+path+SystemEnv.getHtmlLabelName(23084,user.getLanguage()) );
}
%>