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 {
private
TraceWriter
traceWriter
;
private
String
module
;
private
String
lineSeparator
;
private
int
level
=
TraceSystem
.
PARENT
;
Trace
(
TraceWriter
traceWriter
,
String
module
)
{
this
.
traceWriter
=
traceWriter
;
...
...
@@ -104,13 +105,30 @@ public class Trace {
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.
*
* @return true if it is
*/
public
boolean
isInfoEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
INFO
);
return
isEnabled
(
TraceSystem
.
INFO
);
}
/**
...
...
@@ -119,7 +137,7 @@ public class Trace {
* @return true if it is
*/
public
boolean
isDebugEnabled
()
{
return
traceWriter
.
isEnabled
(
TraceSystem
.
DEBUG
);
return
isEnabled
(
TraceSystem
.
DEBUG
);
}
/**
...
...
@@ -128,8 +146,10 @@ public class Trace {
* @param s the message
*/
public
void
error
(
String
s
)
{
if
(
isEnabled
(
TraceSystem
.
ERROR
))
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
null
);
}
}
/**
* Write a message with trace level ERROR to the trace system.
...
...
@@ -138,8 +158,10 @@ public class Trace {
* @param t the exception
*/
public
void
error
(
String
s
,
Throwable
t
)
{
if
(
isEnabled
(
TraceSystem
.
ERROR
))
{
traceWriter
.
write
(
TraceSystem
.
ERROR
,
module
,
s
,
t
);
}
}
/**
* Write a message with trace level INFO to the trace system.
...
...
@@ -147,8 +169,10 @@ public class Trace {
* @param s the message
*/
public
void
info
(
String
s
)
{
if
(
isEnabled
(
TraceSystem
.
INFO
))
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
s
,
null
);
}
}
/**
* Write a message with trace level INFO to the trace system.
...
...
@@ -157,16 +181,9 @@ public class Trace {
* @param t the exception
*/
public
void
info
(
String
s
,
Throwable
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,8 +192,10 @@ public class Trace {
* @param java the source code
*/
public
void
infoCode
(
String
java
)
{
if
(
isEnabled
(
TraceSystem
.
INFO
))
{
traceWriter
.
write
(
TraceSystem
.
INFO
,
module
,
lineSeparator
+
"/**/"
+
java
,
null
);
}
}
/**
* Write a SQL statement with trace level INFO to the trace system.
...
...
@@ -187,6 +206,9 @@ public class Trace {
* @param time the time it took to run the statement in ms
*/
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
);
buff
.
append
(
lineSeparator
);
buff
.
append
(
"/*SQL"
);
...
...
@@ -229,8 +251,10 @@ public class Trace {
* @param s the message
*/
public
void
debug
(
String
s
)
{
if
(
isEnabled
(
TraceSystem
.
DEBUG
))
{
traceWriter
.
write
(
TraceSystem
.
DEBUG
,
module
,
s
,
null
);
}
}
/**
* Write a message with trace level DEBUG to the trace system.
...
...
@@ -239,7 +263,20 @@ public class Trace {
* @param t the exception
*/
public
void
debug
(
String
s
,
Throwable
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;
*/
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.
*/
...
...
@@ -74,21 +79,19 @@ public class TraceSystem implements TraceWriter {
*/
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
int
levelSystemOut
=
DEFAULT_TRACE_LEVEL_SYSTEM_OUT
;
private
int
levelFile
=
DEFAULT_TRACE_LEVEL_FILE
;
private
int
level
;
private
int
maxFileSize
=
DEFAULT_MAX_FILE_SIZE
;
private
String
fileName
;
private
long
lastCheck
;
private
SmallLRUCache
traces
;
private
SimpleDateFormat
dateFormat
;
private
Writer
fileWriter
;
private
PrintWriter
printWriter
;
private
int
checkSize
;
private
boolean
closed
;
private
boolean
manualEnabling
=
true
;
private
boolean
writingErrorLogged
;
private
TraceWriter
writer
=
this
;
...
...
@@ -100,6 +103,7 @@ public class TraceSystem implements TraceWriter {
*/
public
TraceSystem
(
String
fileName
,
boolean
init
)
{
this
.
fileName
=
fileName
;
updateLevel
();
traces
=
new
SmallLRUCache
(
100
);
dateFormat
=
new
SimpleDateFormat
(
"MM-dd HH:mm:ss "
);
if
(
fileName
!=
null
&&
init
)
{
...
...
@@ -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.
*
...
...
@@ -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.
*
...
...
@@ -149,8 +147,7 @@ public class TraceSystem implements TraceWriter {
}
public
boolean
isEnabled
(
int
level
)
{
int
max
=
Math
.
max
(
levelSystemOut
,
levelFile
);
return
level
<=
max
;
return
level
<=
this
.
level
;
}
/**
...
...
@@ -178,6 +175,7 @@ public class TraceSystem implements TraceWriter {
*/
public
void
setLevelSystemOut
(
int
level
)
{
levelSystemOut
=
level
;
updateLevel
();
}
/**
...
...
@@ -208,6 +206,7 @@ public class TraceSystem implements TraceWriter {
}
}
levelFile
=
level
;
updateLevel
();
}
private
String
format
(
String
module
,
String
s
)
{
...
...
@@ -224,34 +223,12 @@ public class TraceSystem implements TraceWriter {
}
}
if
(
fileName
!=
null
)
{
if
(
level
>
levelFile
)
{
enableIfRequired
();
}
if
(
level
<=
levelFile
)
{
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
)
{
try
{
if
(
checkSize
++
>=
CHECK_SIZE_EACH_WRITES
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论