Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
R
RatelExtension
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ratel
RatelExtension
Commits
93a51bd8
Commit
93a51bd8
authored
Jun 01, 2020
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
允许外部访问log文件,文本日志增加时间标记
parent
a04f42e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
FileLogger.java
src/main/java/com/virjar/ratel/api/extension/FileLogger.java
+27
-2
No files found.
src/main/java/com/virjar/ratel/api/extension/FileLogger.java
View file @
93a51bd8
...
...
@@ -12,10 +12,15 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStreamWriter
;
import
java.io.RandomAccessFile
;
import
java.nio.charset.StandardCharsets
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
java.util.concurrent.BlockingDeque
;
import
java.util.concurrent.LinkedBlockingDeque
;
import
external.org.apache.commons.io.FileUtils
;
import
external.org.apache.commons.io.IOUtils
;
public
class
FileLogger
{
...
...
@@ -25,6 +30,11 @@ public class FileLogger {
private
static
OutputStream
outputStream
=
null
;
private
static
byte
[]
newLine
=
System
.
getProperty
(
"line.separator"
,
"\n"
).
getBytes
();
private
static
File
mLogFile
=
null
;
public
static
File
getLogFile
()
{
return
mLogFile
;
}
public
synchronized
static
void
startRecord
(
File
baseDir
)
{
if
(
syncLogThread
!=
null
)
{
...
...
@@ -43,12 +53,25 @@ public class FileLogger {
File
filename
=
new
File
(
dir
,
processName
+
".txt"
);
mLogFile
=
filename
;
RposedBridge
.
log
(
"filename:"
+
filename
.
getAbsolutePath
());
try
{
if
(!
filename
.
exists
())
{
if
(!
filename
.
createNewFile
())
{
RposedBridge
.
log
(
"failed to create log file :"
+
filename
.
getAbsolutePath
());
}
}
else
{
if
(
filename
.
length
()
>
20
*
1024
*
1024
)
{
RandomAccessFile
accessFile
=
new
RandomAccessFile
(
filename
,
"r"
);
long
total
=
accessFile
.
length
();
long
index
=
total
-
10
*
1024
*
1024
;
if
(
index
>
0
)
{
accessFile
.
seek
(
index
);
byte
[]
bytes
=
new
byte
[
11
*
1024
*
1024
];
int
read
=
accessFile
.
read
(
bytes
);
FileUtils
.
writeByteArrayToFile
(
filename
,
bytes
,
0
,
read
);
}
}
}
outputStream
=
new
FileOutputStream
(
filename
,
true
);
}
catch
(
IOException
e
)
{
...
...
@@ -110,7 +133,7 @@ public class FileLogger {
@Override
public
void
handle
(
OutputStream
outputStream
)
throws
IOException
{
OutputStreamWriter
outputStreamWriter
=
new
OutputStreamWriter
(
outputStream
,
StandardCharsets
.
UTF_8
);
outputStreamWriter
.
write
(
message
);
outputStreamWriter
.
write
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
CHINESE
).
format
(
new
Date
())
+
message
);
outputStreamWriter
.
flush
();
}
...
...
@@ -150,7 +173,8 @@ public class FileLogger {
@Override
public
void
handle
(
OutputStream
outputStream
)
throws
IOException
{
OutputStreamWriter
outputStreamWriter
=
new
OutputStreamWriter
(
outputStream
,
StandardCharsets
.
UTF_8
);
outputStreamWriter
.
append
(
tag
);
outputStreamWriter
.
append
(
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
,
Locale
.
CHINESE
).
format
(
new
Date
()))
.
append
(
tag
);
outputStreamWriter
.
append
(
message
);
outputStreamWriter
.
flush
();
}
...
...
@@ -240,6 +264,7 @@ public class FileLogger {
public
static
String
getTrack
(
Throwable
e
)
{
StringBuilder
msg
=
new
StringBuilder
(
"\n=============>\n"
);
while
(
e
!=
null
)
{
msg
.
append
(
e
.
getClass
().
getName
()).
append
(
":"
).
append
(
e
.
getMessage
()).
append
(
"\n"
);
StackTraceElement
[]
ste
=
e
.
getStackTrace
();
for
(
StackTraceElement
stackTraceElement
:
ste
)
{
msg
.
append
(
stackTraceElement
.
getClassName
()).
append
(
"."
).
append
(
stackTraceElement
.
getMethodName
()).
append
(
":"
).
append
(
stackTraceElement
.
getLineNumber
()).
append
(
"\n"
);
...
...
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