Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
45f10244
提交
45f10244
authored
1月 09, 2009
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enabling the trace mechanism by creating a specially named file is no longer supported.
上级
d7b57e07
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
69 行增加
和
55 行删除
+69
-55
Trace.java
h2/src/main/org/h2/message/Trace.java
+55
-18
TraceSystem.java
h2/src/main/org/h2/message/TraceSystem.java
+14
-37
没有找到文件。
h2/src/main/org/h2/message/Trace.java
浏览文件 @
45f10244
...
@@ -97,6 +97,7 @@ public class Trace {
...
@@ -97,6 +97,7 @@ public class Trace {
private
TraceWriter
traceWriter
;
private
TraceWriter
traceWriter
;
private
String
module
;
private
String
module
;
private
String
lineSeparator
;
private
String
lineSeparator
;
private
int
level
=
TraceSystem
.
PARENT
;
Trace
(
TraceWriter
traceWriter
,
String
module
)
{
Trace
(
TraceWriter
traceWriter
,
String
module
)
{
this
.
traceWriter
=
traceWriter
;
this
.
traceWriter
=
traceWriter
;
...
@@ -104,13 +105,30 @@ public class Trace {
...
@@ -104,13 +105,30 @@ public class Trace {
this
.
lineSeparator
=
SysProperties
.
LINE_SEPARATOR
;
this
.
lineSeparator
=
SysProperties
.
LINE_SEPARATOR
;
}
}
/**
* Set the trace level of this component. This setting overrides the parent
* trace level.
*
* @param level the new level
*/
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
private
boolean
isEnabled
(
int
level
)
{
if
(
this
.
level
==
TraceSystem
.
PARENT
)
{
return
traceWriter
.
isEnabled
(
level
);
}
return
level
<=
this
.
level
;
}
/**
/**
* Check if the trace level is equal or higher than INFO.
* Check if the trace level is equal or higher than INFO.
*
*
* @return true if it is
* @return true if it is
*/
*/
public
boolean
isInfoEnabled
()
{
public
boolean
isInfoEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
INFO
);
return
isEnabled
(
TraceSystem
.
INFO
);
}
}
/**
/**
...
@@ -119,7 +137,7 @@ public class Trace {
...
@@ -119,7 +137,7 @@ public class Trace {
* @return true if it is
* @return true if it is
*/
*/
public
boolean
isDebugEnabled
()
{
public
boolean
isDebugEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
DEBUG
);
return
isEnabled
(
TraceSystem
.
DEBUG
);
}
}
/**
/**
...
@@ -128,7 +146,9 @@ public class Trace {
...
@@ -128,7 +146,9 @@ public class Trace {
* @param s the message
* @param s the message
*/
*/
public
void
error
(
String
s
)
{
public
void
error
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
null
);
if
(
isEnabled
(
TraceSystem
.
ERROR
))
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
null
);
}
}
}
/**
/**
...
@@ -138,7 +158,9 @@ public class Trace {
...
@@ -138,7 +158,9 @@ public class Trace {
* @param t the exception
* @param t the exception
*/
*/
public
void
error
(
String
s
,
Throwable
t
)
{
public
void
error
(
String
s
,
Throwable
t
)
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
t
);
if
(
isEnabled
(
TraceSystem
.
ERROR
))
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
t
);
}
}
}
/**
/**
...
@@ -147,7 +169,9 @@ public class Trace {
...
@@ -147,7 +169,9 @@ public class Trace {
* @param s the message
* @param s the message
*/
*/
public
void
info
(
String
s
)
{
public
void
info
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
null
);
if
(
isEnabled
(
TraceSystem
.
INFO
))
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
null
);
}
}
}
/**
/**
...
@@ -157,16 +181,9 @@ public class Trace {
...
@@ -157,16 +181,9 @@ public class Trace {
* @param t the exception
* @param t the exception
*/
*/
public
void
info
(
String
s
,
Throwable
t
)
{
public
void
info
(
String
s
,
Throwable
t
)
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
t
);
if
(
isEnabled
(
TraceSystem
.
INFO
))
{
}
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
t
);
}
/**
* Write Java source code with trace level DEBUG to the trace system.
*
* @param java the source code
*/
public
void
debugCode
(
String
java
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
}
/**
/**
...
@@ -175,7 +192,9 @@ public class Trace {
...
@@ -175,7 +192,9 @@ public class Trace {
* @param java the source code
* @param java the source code
*/
*/
public
void
infoCode
(
String
java
)
{
public
void
infoCode
(
String
java
)
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
if
(
isEnabled
(
TraceSystem
.
INFO
))
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
}
}
/**
/**
...
@@ -187,6 +206,9 @@ public class Trace {
...
@@ -187,6 +206,9 @@ public class Trace {
* @param time the time it took to run the statement in ms
* @param time the time it took to run the statement in ms
*/
*/
public
void
infoSQL
(
String
sql
,
String
params
,
int
count
,
long
time
)
{
public
void
infoSQL
(
String
sql
,
String
params
,
int
count
,
long
time
)
{
if
(!
isEnabled
(
TraceSystem
.
INFO
))
{
return
;
}
StringBuffer
buff
=
new
StringBuffer
(
sql
.
length
()
+
params
.
length
()
+
20
);
StringBuffer
buff
=
new
StringBuffer
(
sql
.
length
()
+
params
.
length
()
+
20
);
buff
.
append
(
lineSeparator
);
buff
.
append
(
lineSeparator
);
buff
.
append
(
"/*SQL"
);
buff
.
append
(
"/*SQL"
);
...
@@ -229,7 +251,9 @@ public class Trace {
...
@@ -229,7 +251,9 @@ public class Trace {
* @param s the message
* @param s the message
*/
*/
public
void
debug
(
String
s
)
{
public
void
debug
(
String
s
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
null
);
if
(
isEnabled
(
TraceSystem
.
DEBUG
))
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
null
);
}
}
}
/**
/**
...
@@ -239,7 +263,20 @@ public class Trace {
...
@@ -239,7 +263,20 @@ public class Trace {
* @param t the exception
* @param t the exception
*/
*/
public
void
debug
(
String
s
,
Throwable
t
)
{
public
void
debug
(
String
s
,
Throwable
t
)
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
t
);
if
(
isEnabled
(
TraceSystem
.
DEBUG
))
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
t
);
}
}
/**
* Write Java source code with trace level DEBUG to the trace system.
*
* @param java the source code
*/
public
void
debugCode
(
String
java
)
{
if
(
isEnabled
(
TraceSystem
.
DEBUG
))
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
}
}
}
}
h2/src/main/org/h2/message/TraceSystem.java
浏览文件 @
45f10244
...
@@ -31,6 +31,11 @@ import org.h2.util.SmallLRUCache;
...
@@ -31,6 +31,11 @@ import org.h2.util.SmallLRUCache;
*/
*/
public
class
TraceSystem
implements
TraceWriter
{
public
class
TraceSystem
implements
TraceWriter
{
/**
* The parent trace level should be used.
*/
public
static
final
int
PARENT
=
-
1
;
/**
/**
* This trace level means nothing should be written.
* This trace level means nothing should be written.
*/
*/
...
@@ -74,21 +79,19 @@ public class TraceSystem implements TraceWriter {
...
@@ -74,21 +79,19 @@ public class TraceSystem implements TraceWriter {
*/
*/
private
static
final
int
DEFAULT_MAX_FILE_SIZE
=
64
*
1024
*
1024
;
private
static
final
int
DEFAULT_MAX_FILE_SIZE
=
64
*
1024
*
1024
;
private
static
final
int
CHECK_FILE_TIME
=
4000
;
private
static
final
int
CHECK_SIZE_EACH_WRITES
=
128
;
private
static
final
int
CHECK_SIZE_EACH_WRITES
=
128
;
private
int
levelSystemOut
=
DEFAULT_TRACE_LEVEL_SYSTEM_OUT
;
private
int
levelSystemOut
=
DEFAULT_TRACE_LEVEL_SYSTEM_OUT
;
private
int
levelFile
=
DEFAULT_TRACE_LEVEL_FILE
;
private
int
levelFile
=
DEFAULT_TRACE_LEVEL_FILE
;
private
int
level
;
private
int
maxFileSize
=
DEFAULT_MAX_FILE_SIZE
;
private
int
maxFileSize
=
DEFAULT_MAX_FILE_SIZE
;
private
String
fileName
;
private
String
fileName
;
private
long
lastCheck
;
private
SmallLRUCache
traces
;
private
SmallLRUCache
traces
;
private
SimpleDateFormat
dateFormat
;
private
SimpleDateFormat
dateFormat
;
private
Writer
fileWriter
;
private
Writer
fileWriter
;
private
PrintWriter
printWriter
;
private
PrintWriter
printWriter
;
private
int
checkSize
;
private
int
checkSize
;
private
boolean
closed
;
private
boolean
closed
;
private
boolean
manualEnabling
=
true
;
private
boolean
writingErrorLogged
;
private
boolean
writingErrorLogged
;
private
TraceWriter
writer
=
this
;
private
TraceWriter
writer
=
this
;
...
@@ -100,6 +103,7 @@ public class TraceSystem implements TraceWriter {
...
@@ -100,6 +103,7 @@ public class TraceSystem implements TraceWriter {
*/
*/
public
TraceSystem
(
String
fileName
,
boolean
init
)
{
public
TraceSystem
(
String
fileName
,
boolean
init
)
{
this
.
fileName
=
fileName
;
this
.
fileName
=
fileName
;
updateLevel
();
traces
=
new
SmallLRUCache
(
100
);
traces
=
new
SmallLRUCache
(
100
);
dateFormat
=
new
SimpleDateFormat
(
"MM-dd HH:mm:ss "
);
dateFormat
=
new
SimpleDateFormat
(
"MM-dd HH:mm:ss "
);
if
(
fileName
!=
null
&&
init
)
{
if
(
fileName
!=
null
&&
init
)
{
...
@@ -111,6 +115,10 @@ public class TraceSystem implements TraceWriter {
...
@@ -111,6 +115,10 @@ public class TraceSystem implements TraceWriter {
}
}
}
}
private
void
updateLevel
()
{
level
=
Math
.
max
(
levelSystemOut
,
levelFile
);
}
/**
/**
* Write the exception to the driver manager log writer if configured.
* Write the exception to the driver manager log writer if configured.
*
*
...
@@ -123,16 +131,6 @@ public class TraceSystem implements TraceWriter {
...
@@ -123,16 +131,6 @@ public class TraceSystem implements TraceWriter {
}
}
}
}
/**
* Allow to manually enable the trace option by placing a specially named
* file in the right folder.
*
* @param value the new value
*/
public
void
setManualEnabling
(
boolean
value
)
{
this
.
manualEnabling
=
value
;
}
/**
/**
* Get or create a trace object for this module.
* Get or create a trace object for this module.
*
*
...
@@ -149,8 +147,7 @@ public class TraceSystem implements TraceWriter {
...
@@ -149,8 +147,7 @@ public class TraceSystem implements TraceWriter {
}
}
public
boolean
isEnabled
(
int
level
)
{
public
boolean
isEnabled
(
int
level
)
{
int
max
=
Math
.
max
(
levelSystemOut
,
levelFile
);
return
level
<=
this
.
level
;
return
level
<=
max
;
}
}
/**
/**
...
@@ -178,6 +175,7 @@ public class TraceSystem implements TraceWriter {
...
@@ -178,6 +175,7 @@ public class TraceSystem implements TraceWriter {
*/
*/
public
void
setLevelSystemOut
(
int
level
)
{
public
void
setLevelSystemOut
(
int
level
)
{
levelSystemOut
=
level
;
levelSystemOut
=
level
;
updateLevel
();
}
}
/**
/**
...
@@ -208,6 +206,7 @@ public class TraceSystem implements TraceWriter {
...
@@ -208,6 +206,7 @@ public class TraceSystem implements TraceWriter {
}
}
}
}
levelFile
=
level
;
levelFile
=
level
;
updateLevel
();
}
}
private
String
format
(
String
module
,
String
s
)
{
private
String
format
(
String
module
,
String
s
)
{
...
@@ -224,34 +223,12 @@ public class TraceSystem implements TraceWriter {
...
@@ -224,34 +223,12 @@ public class TraceSystem implements TraceWriter {
}
}
}
}
if
(
fileName
!=
null
)
{
if
(
fileName
!=
null
)
{
if
(
level
>
levelFile
)
{
enableIfRequired
();
}
if
(
level
<=
levelFile
)
{
if
(
level
<=
levelFile
)
{
writeFile
(
format
(
module
,
s
),
t
);
writeFile
(
format
(
module
,
s
),
t
);
}
}
}
}
}
}
private
void
enableIfRequired
()
{
if
(!
manualEnabling
)
{
return
;
}
long
time
=
System
.
currentTimeMillis
();
if
(
time
>
lastCheck
+
CHECK_FILE_TIME
)
{
String
checkFile
=
fileName
+
Constants
.
SUFFIX_TRACE_START_FILE
;
lastCheck
=
time
;
if
(
FileUtils
.
exists
(
checkFile
))
{
levelFile
=
DEBUG
;
try
{
FileUtils
.
delete
(
checkFile
);
}
catch
(
Exception
e
)
{
// the file may be read only
}
}
}
}
private
synchronized
void
writeFile
(
String
s
,
Throwable
t
)
{
private
synchronized
void
writeFile
(
String
s
,
Throwable
t
)
{
try
{
try
{
if
(
checkSize
++
>=
CHECK_SIZE_EACH_WRITES
)
{
if
(
checkSize
++
>=
CHECK_SIZE_EACH_WRITES
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论