Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
熊鹏飞
/
xxljob220
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0c4491a1
authored
Jun 08, 2016
by
xueli.xue
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
日志逻辑优化
parent
63edb6d8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
35 deletions
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
View file @
0c4491a1
...
@@ -4,9 +4,10 @@ import java.io.BufferedReader;
...
@@ -4,9 +4,10 @@ import java.io.BufferedReader;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.InputStreamReader
;
import
java.io.LineNumberReader
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
...
@@ -133,48 +134,89 @@ public class XxlJobFileAppender extends AppenderSkeleton {
...
@@ -133,48 +134,89 @@ public class XxlJobFileAppender extends AppenderSkeleton {
String
logFileName
=
trigger_log_id
.
concat
(
".log"
);
String
logFileName
=
trigger_log_id
.
concat
(
".log"
);
File
logFile
=
new
File
(
filePathDateDir
,
logFileName
);
File
logFile
=
new
File
(
filePathDateDir
,
logFileName
);
if
(!
logFile
.
exists
())
{
if
(!
logFile
.
exists
())
{
try
{
return
null
;
logFile
.
createNewFile
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
}
String
logData
=
readLines
(
logFile
);
return
logData
;
}
/**
* read log data
* @param logFile
* @return
*/
public
static
String
readLines
(
File
logFile
){
BufferedReader
reader
=
null
;
try
{
try
{
InputStream
ins
=
null
;
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
logFile
),
"utf-8"
));
BufferedReader
reader
=
null
;
if
(
reader
!=
null
)
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
ins
=
new
FileInputStream
(
logFile
);
String
line
=
null
;
reader
=
new
BufferedReader
(
new
InputStreamReader
(
ins
,
"utf-8"
));
while
((
line
=
reader
.
readLine
())
!=
null
)
{
if
(
reader
!=
null
)
{
sb
.
append
(
line
).
append
(
"\n"
);
String
content
=
null
;
StringBuilder
sb
=
new
StringBuilder
();
while
((
content
=
reader
.
readLine
())
!=
null
)
{
sb
.
append
(
content
).
append
(
"\n"
);
}
return
sb
.
toString
();
}
}
}
finally
{
return
sb
.
toString
();
if
(
ins
!=
null
)
{
}
try
{
}
catch
(
IOException
e
)
{
ins
.
close
();
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
}
finally
{
e
.
printStackTrace
();
if
(
reader
!=
null
)
{
}
try
{
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
reader
!=
null
)
{
}
try
{
}
reader
.
close
();
return
null
;
}
catch
(
IOException
e
)
{
}
e
.
printStackTrace
();
}
/**
* read data from line num
* @param sourceFile
* @param fromLineNum
* @return
* @throws Exception
*/
public
static
String
readLinesFrom
(
File
logFile
,
int
fromLineNum
)
{
LineNumberReader
reader
=
null
;
try
{
reader
=
new
LineNumberReader
(
new
FileReader
(
logFile
));
// sBuffer
StringBuffer
sBuffer
=
new
StringBuffer
();
String
line
=
null
;
int
maxLineNum
=
0
;
while
((
line
=
reader
.
readLine
())!=
null
)
{
maxLineNum
++;
if
(
reader
.
getLineNumber
()
>=
fromLineNum
)
{
sBuffer
.
append
(
line
).
append
(
"\n"
);
}
}
}
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"maxLineNum : "
+
maxLineNum
);
return
sBuffer
.
toString
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
if
(
reader
!=
null
)
{
try
{
reader
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
return
null
;
return
null
;
}
/*
// it will return the number of characters actually skipped
reader.skip(Long.MAX_VALUE);
int maxLineNum = reader.getLineNumber();
maxLineNum++; // 最大行号
*/
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment