Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
e4eae311
Commit
e4eae311
authored
Jun 02, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
压缩视频
parent
6e170c8b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
18 deletions
+90
-18
Log.java
...util-base/src/main/java/com/yanzuoguang/util/log/Log.java
+1
-0
LogDefault.java
...se/src/main/java/com/yanzuoguang/util/log/LogDefault.java
+46
-11
LogInfo.java
...-base/src/main/java/com/yanzuoguang/util/log/LogInfo.java
+19
-7
TestByteHelper.java
yzg-util-base/src/test/java/log/TestByteHelper.java
+24
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/log/Log.java
View file @
e4eae311
...
@@ -88,6 +88,7 @@ public class Log {
...
@@ -88,6 +88,7 @@ public class Log {
private
static
void
add
(
LogInfo
info
)
{
private
static
void
add
(
LogInfo
info
)
{
// 获取当前线程编号
// 获取当前线程编号
String
threadId
=
getThreadId
();
String
threadId
=
getThreadId
();
info
.
setThreadId
(
threadId
);
// 判断当前线程日志是否需要特殊处理
// 判断当前线程日志是否需要特殊处理
LogDate
date
;
LogDate
date
;
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/log/LogDefault.java
View file @
e4eae311
package
com
.
yanzuoguang
.
util
.
log
;
package
com
.
yanzuoguang
.
util
.
log
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.MapRow
;
import
java.io.File
;
import
java.util.Date
;
/**
/**
* 日志处理默认处理函数
* 日志处理默认处理函数
...
@@ -10,6 +15,18 @@ import com.yanzuoguang.util.helper.StringHelper;
...
@@ -10,6 +15,18 @@ import com.yanzuoguang.util.helper.StringHelper;
*/
*/
public
class
LogDefault
implements
RunnableLog
{
public
class
LogDefault
implements
RunnableLog
{
private
static
String
pathFormat
=
StringHelper
.
EMPTY
;
public
static
String
getPathFormat
()
{
return
pathFormat
;
}
public
static
void
setPathFormat
(
String
pathFormat
)
{
LogDefault
.
pathFormat
=
pathFormat
;
}
/**
/**
* 需要处理的日志
* 需要处理的日志
*
*
...
@@ -26,23 +43,41 @@ public class LogDefault implements RunnableLog {
...
@@ -26,23 +43,41 @@ public class LogDefault implements RunnableLog {
clsName
=
info
.
getCls
().
getSimpleName
();
clsName
=
info
.
getCls
().
getSimpleName
();
}
}
StringBuilder
sb
=
new
StringBuilder
(
String
.
format
(
"/* %s pid:%d t:%d/%d ms %s %s */ %s"
,
StringBuilder
sb
=
new
StringBuilder
();
DateHelper
.
getDateTimeString
(
"HH:mm:ss.SSS"
,
info
.
getNow
()),
sb
.
append
(
"/* "
);
Thread
.
currentThread
().
getId
(),
sb
.
append
(
DateHelper
.
getDateTimeString
(
"HH:mm:ss.SSS"
,
info
.
getNow
()));
info
.
getTime
(),
sb
.
append
(
" pid:"
);
info
.
getTotalTime
(),
sb
.
append
(
info
.
getThreadId
());
clsName
,
sb
.
append
(
" t:"
);
info
.
getTag
(),
sb
.
append
(
info
.
getTime
());
info
.
getMessage
()
sb
.
append
(
" /"
);
));
sb
.
append
(
info
.
getTotalTime
());
sb
.
append
(
" ms "
);
sb
.
append
(
clsName
);
sb
.
append
(
" "
);
sb
.
append
(
info
.
getTag
());
sb
.
append
(
" */ "
);
sb
.
append
(
info
.
getMessage
());
Throwable
ex
=
info
.
getException
();
Throwable
ex
=
info
.
getException
();
if
(
ex
!=
null
)
{
if
(
ex
!=
null
)
{
sb
.
append
(
ex
.
getClass
().
getName
());
sb
.
append
(
ex
.
getClass
().
getName
());
sb
.
append
(
ex
.
getMessage
());
sb
.
append
(
ex
.
getMessage
());
System
.
err
.
println
(
sb
.
toString
());
sb
.
append
(
System
.
getProperty
(
"line.separator"
));
System
.
err
.
print
(
sb
.
toString
());
ex
.
printStackTrace
();
ex
.
printStackTrace
();
}
else
{
}
else
{
System
.
out
.
println
(
sb
.
toString
());
sb
.
append
(
System
.
getProperty
(
"line.separator"
));
System
.
out
.
print
(
sb
.
toString
());
}
if
(!
StringHelper
.
isEmpty
(
pathFormat
))
{
MapRow
row
=
new
MapRow
();
row
.
put
(
"day"
,
DateHelper
.
getToday
(
info
.
getNow
()));
row
.
put
(
"thread"
,
info
.
getThreadId
());
String
path
=
StringHelper
.
getCodeString
(
pathFormat
,
row
);
FileHelper
.
writeFile
(
new
File
(
path
),
sb
.
toString
(),
"UTF-8"
);
}
}
}
}
}
}
yzg-util-base/src/main/java/com/yanzuoguang/util/log/LogInfo.java
View file @
e4eae311
...
@@ -4,6 +4,7 @@ import java.util.Date;
...
@@ -4,6 +4,7 @@ import java.util.Date;
/**
/**
* 日志实体记录类
* 日志实体记录类
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
LogInfo
{
public
class
LogInfo
{
...
@@ -36,6 +37,11 @@ public class LogInfo {
...
@@ -36,6 +37,11 @@ public class LogInfo {
*/
*/
private
long
totalTime
;
private
long
totalTime
;
/**
* 线程Id
*/
private
String
threadId
;
/**
/**
* 构造函数
* 构造函数
*
*
...
@@ -109,19 +115,17 @@ public class LogInfo {
...
@@ -109,19 +115,17 @@ public class LogInfo {
}
}
public
Date
getNow
()
{
public
Date
getNow
()
{
if
(
this
.
now
==
0
)
{
if
(
this
.
now
==
0
)
{
return
null
;
return
null
;
}
}
else
{
else
{
return
new
Date
(
this
.
now
);
return
new
Date
(
this
.
now
);
}
}
}
}
public
void
setNow
(
Date
now
)
{
public
void
setNow
(
Date
now
)
{
if
(
now
!=
null
){
if
(
now
!=
null
)
{
this
.
now
=
now
.
getTime
()
;
this
.
now
=
now
.
getTime
();
}
}
else
{
else
{
this
.
now
=
0
;
this
.
now
=
0
;
}
}
}
}
...
@@ -165,4 +169,12 @@ public class LogInfo {
...
@@ -165,4 +169,12 @@ public class LogInfo {
public
void
setTotalTime
(
long
totalTime
)
{
public
void
setTotalTime
(
long
totalTime
)
{
this
.
totalTime
=
totalTime
;
this
.
totalTime
=
totalTime
;
}
}
public
String
getThreadId
()
{
return
threadId
;
}
public
void
setThreadId
(
String
threadId
)
{
this
.
threadId
=
threadId
;
}
}
}
yzg-util-base/src/test/java/log/TestByteHelper.java
0 → 100755
View file @
e4eae311
package
log
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.log.LogDefault
;
import
com.yanzuoguang.util.thread.RunnableListAuto
;
import
org.junit.Test
;
public
class
TestByteHelper
{
@Test
public
void
test
()
{
LogDefault
.
setPathFormat
(
"/home/yanzuoguang/log/{day}/{thread}.log"
);
RunnableListAuto
.
run
(
new
Runnable
()
{
@Override
public
void
run
()
{
Log
.
info
(
TestByteHelper
.
class
,
"等待2秒秒"
);
}
},
new
Runnable
()
{
@Override
public
void
run
()
{
Log
.
info
(
TestByteHelper
.
class
,
"等待2秒秒"
);
}
});
}
}
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