Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
63d62ddb
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
63d62ddb
编写于
8月 17, 2020
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove whatsmars-logging
上级
e990e69d
变更
38
展开全部
隐藏空白更改
内联
并排
Showing
38 changed file
with
58 addition
and
4137 deletion
+58
-4137
pom.xml
pom.xml
+7
-0
whatsmars-rpc/pom.xml
whatsmars-rpc/pom.xml
+0
-1
whatsmars-rpc/whatsmars-logging/pom.xml
whatsmars-rpc/whatsmars-logging/pom.xml
+0
-31
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InnerLoggerFactory.java
...g/hongxi/whatsmars/common/logging/InnerLoggerFactory.java
+0
-482
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InternalLogger.java
...a/org/hongxi/whatsmars/common/logging/InternalLogger.java
+0
-63
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InternalLoggerFactory.java
...ongxi/whatsmars/common/logging/InternalLoggerFactory.java
+0
-89
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/Slf4jLoggerFactory.java
...g/hongxi/whatsmars/common/logging/Slf4jLoggerFactory.java
+0
-158
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Appender.java
...a/org/hongxi/whatsmars/common/logging/inner/Appender.java
+0
-236
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Layout.java
...ava/org/hongxi/whatsmars/common/logging/inner/Layout.java
+0
-39
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Level.java
...java/org/hongxi/whatsmars/common/logging/inner/Level.java
+0
-158
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Logger.java
...ava/org/hongxi/whatsmars/common/logging/inner/Logger.java
+0
-485
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/LoggingBuilder.java
...hongxi/whatsmars/common/logging/inner/LoggingBuilder.java
+0
-1235
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/LoggingEvent.java
...g/hongxi/whatsmars/common/logging/inner/LoggingEvent.java
+0
-116
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/SysLogger.java
.../org/hongxi/whatsmars/common/logging/inner/SysLogger.java
+0
-89
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/BasicLoggerTest.java
.../org/hongxi/whatsmars/common/logging/BasicLoggerTest.java
+0
-66
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/InnerLoggerFactoryTest.java
...ngxi/whatsmars/common/logging/InnerLoggerFactoryTest.java
+0
-92
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/InternalLoggerTest.java
...g/hongxi/whatsmars/common/logging/InternalLoggerTest.java
+0
-65
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/Slf4jLoggerFactoryTest.java
...ngxi/whatsmars/common/logging/Slf4jLoggerFactoryTest.java
+0
-80
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/AppenderTest.java
...g/hongxi/whatsmars/common/logging/inner/AppenderTest.java
+0
-160
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LayoutTest.java
...org/hongxi/whatsmars/common/logging/inner/LayoutTest.java
+0
-54
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LevelTest.java
.../org/hongxi/whatsmars/common/logging/inner/LevelTest.java
+0
-37
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggerRepositoryTest.java
.../whatsmars/common/logging/inner/LoggerRepositoryTest.java
+0
-49
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggerTest.java
...org/hongxi/whatsmars/common/logging/inner/LoggerTest.java
+0
-115
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggingBuilderTest.java
...xi/whatsmars/common/logging/inner/LoggingBuilderTest.java
+0
-113
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/MessageFormatterTest.java
.../whatsmars/common/logging/inner/MessageFormatterTest.java
+0
-40
whatsmars-rpc/whatsmars-logging/src/test/resources/logback_test.xml
...rpc/whatsmars-logging/src/test/resources/logback_test.xml
+0
-46
whatsmars-rpc/whatsmars-remoting/pom.xml
whatsmars-rpc/whatsmars-remoting/pom.xml
+17
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/RemotingHelper.java
.../org/hongxi/whatsmars/remoting/common/RemotingHelper.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/RemotingUtil.java
...va/org/hongxi/whatsmars/remoting/common/RemotingUtil.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/ServiceThread.java
...a/org/hongxi/whatsmars/remoting/common/ServiceThread.java
+3
-4
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyDecoder.java
...ava/org/hongxi/whatsmars/remoting/netty/NettyDecoder.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyEncoder.java
...ava/org/hongxi/whatsmars/remoting/netty/NettyEncoder.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyLogger.java
...java/org/hongxi/whatsmars/remoting/netty/NettyLogger.java
+4
-4
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingAbstract.java
...ongxi/whatsmars/remoting/netty/NettyRemotingAbstract.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingClient.java
.../hongxi/whatsmars/remoting/netty/NettyRemotingClient.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingServer.java
.../hongxi/whatsmars/remoting/netty/NettyRemotingServer.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/TlsHelper.java
...n/java/org/hongxi/whatsmars/remoting/netty/TlsHelper.java
+3
-3
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/protocol/RemotingCommand.java
...g/hongxi/whatsmars/remoting/protocol/RemotingCommand.java
+3
-3
未找到文件。
pom.xml
浏览文件 @
63d62ddb
...
...
@@ -46,6 +46,7 @@
<commons-lang.version>
2.6
</commons-lang.version>
<commons-logging.version>
1.2
</commons-logging.version>
<curator.version>
2.12.0
</curator.version>
<disruptor.version>
3.4.2
</disruptor.version>
<dubbo.version>
2.7.3
</dubbo.version>
<fastjson.version>
1.2.70
</fastjson.version>
<guava.version>
20.0
</guava.version>
...
...
@@ -126,6 +127,12 @@
<version>
${log4j.version}
</version>
</dependency>
<dependency>
<groupId>
com.lmax
</groupId>
<artifactId>
disruptor
</artifactId>
<version>
${disruptor.version}
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
...
...
whatsmars-rpc/pom.xml
浏览文件 @
63d62ddb
...
...
@@ -17,7 +17,6 @@
<modules>
<module>
whatsmars-remoting
</module>
<module>
whatsmars-serialization
</module>
<module>
whatsmars-logging
</module>
<module>
whatsmars-netty
</module>
</modules>
...
...
whatsmars-rpc/whatsmars-logging/pom.xml
已删除
100644 → 0
浏览文件 @
e990e69d
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<parent>
<artifactId>
whatsmars-rpc
</artifactId>
<groupId>
org.hongxi
</groupId>
<version>
Rocket.S9
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
whatsmars-logging
</artifactId>
<packaging>
jar
</packaging>
<name>
${project.artifactId}
</name>
<description>
logging for RPC
</description>
<dependencies>
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InnerLoggerFactory.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
org.hongxi.whatsmars.common.logging.inner.Logger
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
InnerLoggerFactory
extends
InternalLoggerFactory
{
public
InnerLoggerFactory
()
{
doRegister
();
}
@Override
protected
InternalLogger
getLoggerInstance
(
String
name
)
{
return
new
InnerLogger
(
name
);
}
@Override
protected
String
getLoggerType
()
{
return
LOGGER_INNER
;
}
@Override
protected
void
shutdown
()
{
Logger
.
getRepository
().
shutdown
();
}
public
static
class
InnerLogger
implements
InternalLogger
{
private
Logger
logger
;
public
InnerLogger
(
String
name
)
{
logger
=
Logger
.
getLogger
(
name
);
}
@Override
public
String
getName
()
{
return
logger
.
getName
();
}
@Override
public
void
debug
(
String
var1
)
{
logger
.
debug
(
var1
);
}
@Override
public
void
debug
(
String
var1
,
Throwable
var2
)
{
logger
.
debug
(
var1
,
var2
);
}
@Override
public
void
info
(
String
var1
)
{
logger
.
info
(
var1
);
}
@Override
public
void
info
(
String
var1
,
Throwable
var2
)
{
logger
.
info
(
var1
,
var2
);
}
@Override
public
void
warn
(
String
var1
)
{
logger
.
warn
(
var1
);
}
@Override
public
void
warn
(
String
var1
,
Throwable
var2
)
{
logger
.
warn
(
var1
,
var2
);
}
@Override
public
void
error
(
String
var1
)
{
logger
.
error
(
var1
);
}
@Override
public
void
error
(
String
var1
,
Throwable
var2
)
{
logger
.
error
(
var1
,
var2
);
}
@Override
public
void
debug
(
String
var1
,
Object
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
);
logger
.
debug
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
debug
(
String
var1
,
Object
var2
,
Object
var3
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
,
var3
);
logger
.
debug
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
debug
(
String
var1
,
Object
...
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
arrayFormat
(
var1
,
var2
);
logger
.
debug
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
info
(
String
var1
,
Object
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
);
logger
.
info
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
info
(
String
var1
,
Object
var2
,
Object
var3
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
,
var3
);
logger
.
info
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
info
(
String
var1
,
Object
...
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
arrayFormat
(
var1
,
var2
);
logger
.
info
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
warn
(
String
var1
,
Object
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
warn
(
String
var1
,
Object
...
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
arrayFormat
(
var1
,
var2
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
warn
(
String
var1
,
Object
var2
,
Object
var3
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
,
var3
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
error
(
String
var1
,
Object
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
error
(
String
var1
,
Object
var2
,
Object
var3
)
{
FormattingTuple
format
=
MessageFormatter
.
format
(
var1
,
var2
,
var3
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
@Override
public
void
error
(
String
var1
,
Object
...
var2
)
{
FormattingTuple
format
=
MessageFormatter
.
arrayFormat
(
var1
,
var2
);
logger
.
warn
(
format
.
getMessage
(),
format
.
getThrowable
());
}
public
Logger
getLogger
()
{
return
logger
;
}
}
public
static
class
FormattingTuple
{
private
String
message
;
private
Throwable
throwable
;
private
Object
[]
argArray
;
public
FormattingTuple
(
String
message
)
{
this
(
message
,
null
,
null
);
}
public
FormattingTuple
(
String
message
,
Object
[]
argArray
,
Throwable
throwable
)
{
this
.
message
=
message
;
this
.
throwable
=
throwable
;
if
(
throwable
==
null
)
{
this
.
argArray
=
argArray
;
}
else
{
this
.
argArray
=
trimmedCopy
(
argArray
);
}
}
static
Object
[]
trimmedCopy
(
Object
[]
argArray
)
{
if
(
argArray
!=
null
&&
argArray
.
length
!=
0
)
{
int
trimemdLen
=
argArray
.
length
-
1
;
Object
[]
trimmed
=
new
Object
[
trimemdLen
];
System
.
arraycopy
(
argArray
,
0
,
trimmed
,
0
,
trimemdLen
);
return
trimmed
;
}
else
{
throw
new
IllegalStateException
(
"non-sensical empty or null argument array"
);
}
}
public
String
getMessage
()
{
return
this
.
message
;
}
public
Object
[]
getArgArray
()
{
return
this
.
argArray
;
}
public
Throwable
getThrowable
()
{
return
this
.
throwable
;
}
}
public
static
class
MessageFormatter
{
public
MessageFormatter
()
{
}
public
static
FormattingTuple
format
(
String
messagePattern
,
Object
arg
)
{
return
arrayFormat
(
messagePattern
,
new
Object
[]{
arg
});
}
public
static
FormattingTuple
format
(
String
messagePattern
,
Object
arg1
,
Object
arg2
)
{
return
arrayFormat
(
messagePattern
,
new
Object
[]{
arg1
,
arg2
});
}
static
Throwable
getThrowableCandidate
(
Object
[]
argArray
)
{
if
(
argArray
!=
null
&&
argArray
.
length
!=
0
)
{
Object
lastEntry
=
argArray
[
argArray
.
length
-
1
];
return
lastEntry
instanceof
Throwable
?
(
Throwable
)
lastEntry
:
null
;
}
else
{
return
null
;
}
}
public
static
FormattingTuple
arrayFormat
(
String
messagePattern
,
Object
[]
argArray
)
{
Throwable
throwableCandidate
=
getThrowableCandidate
(
argArray
);
if
(
messagePattern
==
null
)
{
return
new
FormattingTuple
(
null
,
argArray
,
throwableCandidate
);
}
else
if
(
argArray
==
null
)
{
return
new
FormattingTuple
(
messagePattern
);
}
else
{
int
i
=
0
;
StringBuilder
sbuf
=
new
StringBuilder
(
messagePattern
.
length
()
+
50
);
int
len
;
for
(
len
=
0
;
len
<
argArray
.
length
;
++
len
)
{
int
j
=
messagePattern
.
indexOf
(
"{}"
,
i
);
if
(
j
==
-
1
)
{
if
(
i
==
0
)
{
return
new
FormattingTuple
(
messagePattern
,
argArray
,
throwableCandidate
);
}
sbuf
.
append
(
messagePattern
.
substring
(
i
,
messagePattern
.
length
()));
return
new
FormattingTuple
(
sbuf
.
toString
(),
argArray
,
throwableCandidate
);
}
if
(
isEscapeDelimeter
(
messagePattern
,
j
))
{
if
(!
isDoubleEscaped
(
messagePattern
,
j
))
{
--
len
;
sbuf
.
append
(
messagePattern
.
substring
(
i
,
j
-
1
));
sbuf
.
append
(
'{'
);
i
=
j
+
1
;
}
else
{
sbuf
.
append
(
messagePattern
.
substring
(
i
,
j
-
1
));
deeplyAppendParameter
(
sbuf
,
argArray
[
len
],
null
);
i
=
j
+
2
;
}
}
else
{
sbuf
.
append
(
messagePattern
.
substring
(
i
,
j
));
deeplyAppendParameter
(
sbuf
,
argArray
[
len
],
null
);
i
=
j
+
2
;
}
}
sbuf
.
append
(
messagePattern
.
substring
(
i
,
messagePattern
.
length
()));
if
(
len
<
argArray
.
length
-
1
)
{
return
new
FormattingTuple
(
sbuf
.
toString
(),
argArray
,
throwableCandidate
);
}
else
{
return
new
FormattingTuple
(
sbuf
.
toString
(),
argArray
,
null
);
}
}
}
static
boolean
isEscapeDelimeter
(
String
messagePattern
,
int
delimeterStartIndex
)
{
if
(
delimeterStartIndex
==
0
)
{
return
false
;
}
else
{
char
potentialEscape
=
messagePattern
.
charAt
(
delimeterStartIndex
-
1
);
return
potentialEscape
==
92
;
}
}
static
boolean
isDoubleEscaped
(
String
messagePattern
,
int
delimeterStartIndex
)
{
return
delimeterStartIndex
>=
2
&&
messagePattern
.
charAt
(
delimeterStartIndex
-
2
)
==
92
;
}
private
static
void
deeplyAppendParameter
(
StringBuilder
sbuf
,
Object
o
,
Map
<
Object
[],
Object
>
seenMap
)
{
if
(
o
==
null
)
{
sbuf
.
append
(
"null"
);
}
else
{
if
(!
o
.
getClass
().
isArray
())
{
safeObjectAppend
(
sbuf
,
o
);
}
else
if
(
o
instanceof
boolean
[])
{
booleanArrayAppend
(
sbuf
,
(
boolean
[])
o
);
}
else
if
(
o
instanceof
byte
[])
{
byteArrayAppend
(
sbuf
,
(
byte
[])
o
);
}
else
if
(
o
instanceof
char
[])
{
charArrayAppend
(
sbuf
,
(
char
[])
o
);
}
else
if
(
o
instanceof
short
[])
{
shortArrayAppend
(
sbuf
,
(
short
[])
o
);
}
else
if
(
o
instanceof
int
[])
{
intArrayAppend
(
sbuf
,
(
int
[])
o
);
}
else
if
(
o
instanceof
long
[])
{
longArrayAppend
(
sbuf
,
(
long
[])
o
);
}
else
if
(
o
instanceof
float
[])
{
floatArrayAppend
(
sbuf
,
(
float
[])
o
);
}
else
if
(
o
instanceof
double
[])
{
doubleArrayAppend
(
sbuf
,
(
double
[])
o
);
}
else
{
objectArrayAppend
(
sbuf
,
(
Object
[])
o
,
seenMap
);
}
}
}
private
static
void
safeObjectAppend
(
StringBuilder
sbuf
,
Object
o
)
{
try
{
String
t
=
o
.
toString
();
sbuf
.
append
(
t
);
}
catch
(
Throwable
var3
)
{
System
.
err
.
println
(
"RocketMQ InnerLogger: Failed toString() invocation on an object of type ["
+
o
.
getClass
().
getName
()
+
"]"
);
var3
.
printStackTrace
();
sbuf
.
append
(
"[FAILED toString()]"
);
}
}
private
static
void
objectArrayAppend
(
StringBuilder
sbuf
,
Object
[]
a
,
Map
<
Object
[],
Object
>
seenMap
)
{
if
(
seenMap
==
null
)
{
seenMap
=
new
HashMap
<
Object
[],
Object
>();
}
sbuf
.
append
(
'['
);
if
(!
seenMap
.
containsKey
(
a
))
{
seenMap
.
put
(
a
,
null
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
deeplyAppendParameter
(
sbuf
,
a
[
i
],
seenMap
);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
seenMap
.
remove
(
a
);
}
else
{
sbuf
.
append
(
"..."
);
}
sbuf
.
append
(
']'
);
}
private
static
void
booleanArrayAppend
(
StringBuilder
sbuf
,
boolean
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
byteArrayAppend
(
StringBuilder
sbuf
,
byte
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
charArrayAppend
(
StringBuilder
sbuf
,
char
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
shortArrayAppend
(
StringBuilder
sbuf
,
short
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
intArrayAppend
(
StringBuilder
sbuf
,
int
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
longArrayAppend
(
StringBuilder
sbuf
,
long
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
floatArrayAppend
(
StringBuilder
sbuf
,
float
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
private
static
void
doubleArrayAppend
(
StringBuilder
sbuf
,
double
[]
a
)
{
sbuf
.
append
(
'['
);
int
len
=
a
.
length
;
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
sbuf
.
append
(
a
[
i
]);
if
(
i
!=
len
-
1
)
{
sbuf
.
append
(
", "
);
}
}
sbuf
.
append
(
']'
);
}
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InternalLogger.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
public
interface
InternalLogger
{
String
getName
();
void
debug
(
String
var1
);
void
debug
(
String
var1
,
Object
var2
);
void
debug
(
String
var1
,
Object
var2
,
Object
var3
);
void
debug
(
String
var1
,
Object
...
var2
);
void
debug
(
String
var1
,
Throwable
var2
);
void
info
(
String
var1
);
void
info
(
String
var1
,
Object
var2
);
void
info
(
String
var1
,
Object
var2
,
Object
var3
);
void
info
(
String
var1
,
Object
...
var2
);
void
info
(
String
var1
,
Throwable
var2
);
void
warn
(
String
var1
);
void
warn
(
String
var1
,
Object
var2
);
void
warn
(
String
var1
,
Object
...
var2
);
void
warn
(
String
var1
,
Object
var2
,
Object
var3
);
void
warn
(
String
var1
,
Throwable
var2
);
void
error
(
String
var1
);
void
error
(
String
var1
,
Object
var2
);
void
error
(
String
var1
,
Object
var2
,
Object
var3
);
void
error
(
String
var1
,
Object
...
var2
);
void
error
(
String
var1
,
Throwable
var2
);
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/InternalLoggerFactory.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
java.util.concurrent.ConcurrentHashMap
;
public
abstract
class
InternalLoggerFactory
{
public
static
final
String
LOGGER_SLF4J
=
"slf4j"
;
public
static
final
String
LOGGER_INNER
=
"inner"
;
public
static
final
String
DEFAULT_LOGGER
=
LOGGER_SLF4J
;
private
static
String
loggerType
=
null
;
private
static
ConcurrentHashMap
<
String
,
InternalLoggerFactory
>
loggerFactoryCache
=
new
ConcurrentHashMap
<
String
,
InternalLoggerFactory
>();
public
static
InternalLogger
getLogger
(
Class
clazz
)
{
return
getLogger
(
clazz
.
getName
());
}
public
static
InternalLogger
getLogger
(
String
name
)
{
return
getLoggerFactory
().
getLoggerInstance
(
name
);
}
private
static
InternalLoggerFactory
getLoggerFactory
()
{
InternalLoggerFactory
internalLoggerFactory
=
null
;
if
(
loggerType
!=
null
)
{
internalLoggerFactory
=
loggerFactoryCache
.
get
(
loggerType
);
}
if
(
internalLoggerFactory
==
null
)
{
internalLoggerFactory
=
loggerFactoryCache
.
get
(
DEFAULT_LOGGER
);
}
if
(
internalLoggerFactory
==
null
)
{
internalLoggerFactory
=
loggerFactoryCache
.
get
(
LOGGER_INNER
);
}
if
(
internalLoggerFactory
==
null
)
{
throw
new
RuntimeException
(
"[RocketMQ] Logger init failed, please check logger"
);
}
return
internalLoggerFactory
;
}
public
static
void
setCurrentLoggerType
(
String
type
)
{
loggerType
=
type
;
}
static
{
try
{
new
Slf4jLoggerFactory
();
}
catch
(
Throwable
e
)
{
//ignore
}
try
{
new
InnerLoggerFactory
();
}
catch
(
Throwable
e
)
{
//ignore
}
}
protected
void
doRegister
()
{
String
loggerType
=
getLoggerType
();
if
(
loggerFactoryCache
.
get
(
loggerType
)
!=
null
)
{
return
;
}
loggerFactoryCache
.
put
(
loggerType
,
this
);
}
protected
abstract
void
shutdown
();
protected
abstract
InternalLogger
getLoggerInstance
(
String
name
);
protected
abstract
String
getLoggerType
();
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/Slf4jLoggerFactory.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
public
class
Slf4jLoggerFactory
extends
InternalLoggerFactory
{
public
Slf4jLoggerFactory
()
{
LoggerFactory
.
getILoggerFactory
();
doRegister
();
}
@Override
protected
String
getLoggerType
()
{
return
LOGGER_SLF4J
;
}
@Override
protected
InternalLogger
getLoggerInstance
(
String
name
)
{
return
new
Slf4jLogger
(
name
);
}
@Override
protected
void
shutdown
()
{
}
public
static
class
Slf4jLogger
implements
InternalLogger
{
private
Logger
logger
=
null
;
public
Slf4jLogger
(
String
name
)
{
logger
=
LoggerFactory
.
getLogger
(
name
);
}
@Override
public
String
getName
()
{
return
logger
.
getName
();
}
@Override
public
void
debug
(
String
s
)
{
logger
.
debug
(
s
);
}
@Override
public
void
debug
(
String
s
,
Object
o
)
{
logger
.
debug
(
s
,
o
);
}
@Override
public
void
debug
(
String
s
,
Object
o
,
Object
o1
)
{
logger
.
debug
(
s
,
o
,
o1
);
}
@Override
public
void
debug
(
String
s
,
Object
...
objects
)
{
logger
.
debug
(
s
,
objects
);
}
@Override
public
void
debug
(
String
s
,
Throwable
throwable
)
{
logger
.
debug
(
s
,
throwable
);
}
@Override
public
void
info
(
String
s
)
{
logger
.
info
(
s
);
}
@Override
public
void
info
(
String
s
,
Object
o
)
{
logger
.
info
(
s
,
o
);
}
@Override
public
void
info
(
String
s
,
Object
o
,
Object
o1
)
{
logger
.
info
(
s
,
o
,
o1
);
}
@Override
public
void
info
(
String
s
,
Object
...
objects
)
{
logger
.
info
(
s
,
objects
);
}
@Override
public
void
info
(
String
s
,
Throwable
throwable
)
{
logger
.
info
(
s
,
throwable
);
}
@Override
public
void
warn
(
String
s
)
{
logger
.
warn
(
s
);
}
@Override
public
void
warn
(
String
s
,
Object
o
)
{
logger
.
warn
(
s
,
o
);
}
@Override
public
void
warn
(
String
s
,
Object
...
objects
)
{
logger
.
warn
(
s
,
objects
);
}
@Override
public
void
warn
(
String
s
,
Object
o
,
Object
o1
)
{
logger
.
warn
(
s
,
o
,
o1
);
}
@Override
public
void
warn
(
String
s
,
Throwable
throwable
)
{
logger
.
warn
(
s
,
throwable
);
}
@Override
public
void
error
(
String
s
)
{
logger
.
error
(
s
);
}
@Override
public
void
error
(
String
s
,
Object
o
)
{
logger
.
error
(
s
,
o
);
}
@Override
public
void
error
(
String
s
,
Object
o
,
Object
o1
)
{
logger
.
error
(
s
,
o
,
o1
);
}
@Override
public
void
error
(
String
s
,
Object
...
objects
)
{
logger
.
error
(
s
,
objects
);
}
@Override
public
void
error
(
String
s
,
Throwable
throwable
)
{
logger
.
error
(
s
,
throwable
);
}
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Appender.java
已删除
100755 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
java.io.InterruptedIOException
;
import
java.util.Enumeration
;
import
java.util.Vector
;
public
abstract
class
Appender
{
public
static
final
int
CODE_WRITE_FAILURE
=
1
;
public
static
final
int
CODE_FLUSH_FAILURE
=
2
;
public
static
final
int
CODE_CLOSE_FAILURE
=
3
;
public
static
final
int
CODE_FILE_OPEN_FAILURE
=
4
;
public
final
static
String
LINE_SEP
=
System
.
getProperty
(
"line.separator"
);
boolean
firstTime
=
true
;
protected
Layout
layout
;
protected
String
name
;
protected
boolean
closed
=
false
;
public
void
activateOptions
()
{
}
abstract
protected
void
append
(
LoggingEvent
event
);
@Override
public
void
finalize
()
{
try
{
super
.
finalize
();
}
catch
(
Throwable
throwable
)
{
SysLogger
.
error
(
"Finalizing appender named ["
+
name
+
"]. error"
,
throwable
);
}
if
(
this
.
closed
)
{
return
;
}
SysLogger
.
debug
(
"Finalizing appender named ["
+
name
+
"]."
);
close
();
}
public
Layout
getLayout
()
{
return
layout
;
}
public
final
String
getName
()
{
return
this
.
name
;
}
public
synchronized
void
doAppend
(
LoggingEvent
event
)
{
if
(
closed
)
{
SysLogger
.
error
(
"Attempted to append to closed appender named ["
+
name
+
"]."
);
return
;
}
this
.
append
(
event
);
}
public
void
setLayout
(
Layout
layout
)
{
this
.
layout
=
layout
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
abstract
void
close
();
public
void
handleError
(
String
message
,
Exception
e
,
int
errorCode
)
{
if
(
e
instanceof
InterruptedIOException
||
e
instanceof
InterruptedException
)
{
Thread
.
currentThread
().
interrupt
();
}
if
(
firstTime
)
{
SysLogger
.
error
(
message
+
" code:"
+
errorCode
,
e
);
firstTime
=
false
;
}
}
public
void
handleError
(
String
message
)
{
if
(
firstTime
)
{
SysLogger
.
error
(
message
);
firstTime
=
false
;
}
}
public
interface
AppenderPipeline
{
void
addAppender
(
Appender
newAppender
);
Enumeration
getAllAppenders
();
Appender
getAppender
(
String
name
);
boolean
isAttached
(
Appender
appender
);
void
removeAllAppenders
();
void
removeAppender
(
Appender
appender
);
void
removeAppender
(
String
name
);
}
public
static
class
AppenderPipelineImpl
implements
AppenderPipeline
{
protected
Vector
<
Appender
>
appenderList
;
@Override
public
void
addAppender
(
Appender
newAppender
)
{
if
(
newAppender
==
null
)
{
return
;
}
if
(
appenderList
==
null
)
{
appenderList
=
new
Vector
<
Appender
>(
1
);
}
if
(!
appenderList
.
contains
(
newAppender
))
{
appenderList
.
addElement
(
newAppender
);
}
}
public
int
appendLoopOnAppenders
(
LoggingEvent
event
)
{
int
size
=
0
;
Appender
appender
;
if
(
appenderList
!=
null
)
{
size
=
appenderList
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
appender
=
appenderList
.
elementAt
(
i
);
appender
.
doAppend
(
event
);
}
}
return
size
;
}
@Override
public
Enumeration
getAllAppenders
()
{
if
(
appenderList
==
null
)
{
return
null
;
}
else
{
return
appenderList
.
elements
();
}
}
@Override
public
Appender
getAppender
(
String
name
)
{
if
(
appenderList
==
null
||
name
==
null
)
{
return
null
;
}
int
size
=
appenderList
.
size
();
Appender
appender
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
appender
=
appenderList
.
elementAt
(
i
);
if
(
name
.
equals
(
appender
.
getName
()))
{
return
appender
;
}
}
return
null
;
}
@Override
public
boolean
isAttached
(
Appender
appender
)
{
if
(
appenderList
==
null
||
appender
==
null
)
{
return
false
;
}
int
size
=
appenderList
.
size
();
Appender
a
;
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
a
=
appenderList
.
elementAt
(
i
);
if
(
a
==
appender
)
{
return
true
;
}
}
return
false
;
}
@Override
public
void
removeAllAppenders
()
{
if
(
appenderList
!=
null
)
{
int
len
=
appenderList
.
size
();
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
Appender
a
=
appenderList
.
elementAt
(
i
);
a
.
close
();
}
appenderList
.
removeAllElements
();
appenderList
=
null
;
}
}
@Override
public
void
removeAppender
(
Appender
appender
)
{
if
(
appender
==
null
||
appenderList
==
null
)
{
return
;
}
appenderList
.
removeElement
(
appender
);
}
@Override
public
void
removeAppender
(
String
name
)
{
if
(
name
==
null
||
appenderList
==
null
)
{
return
;
}
int
size
=
appenderList
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
if
(
name
.
equals
((
appenderList
.
elementAt
(
i
)).
getName
()))
{
appenderList
.
removeElementAt
(
i
);
break
;
}
}
}
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Layout.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
public
abstract
class
Layout
{
public
abstract
String
format
(
LoggingEvent
event
);
public
String
getContentType
()
{
return
"text/plain"
;
}
public
String
getHeader
()
{
return
null
;
}
public
String
getFooter
()
{
return
null
;
}
abstract
public
boolean
ignoresThrowable
();
}
\ No newline at end of file
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Level.java
已删除
100755 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
java.io.Serializable
;
public
class
Level
implements
Serializable
{
transient
int
level
;
transient
String
levelStr
;
transient
int
syslogEquivalent
;
public
final
static
int
OFF_INT
=
Integer
.
MAX_VALUE
;
public
final
static
int
ERROR_INT
=
40000
;
public
final
static
int
WARN_INT
=
30000
;
public
final
static
int
INFO_INT
=
20000
;
public
final
static
int
DEBUG_INT
=
10000
;
public
final
static
int
ALL_INT
=
Integer
.
MIN_VALUE
;
private
static
final
String
ALL_NAME
=
"ALL"
;
private
static
final
String
DEBUG_NAME
=
"DEBUG"
;
private
static
final
String
INFO_NAME
=
"INFO"
;
private
static
final
String
WARN_NAME
=
"WARN"
;
private
static
final
String
ERROR_NAME
=
"ERROR"
;
private
static
final
String
OFF_NAME
=
"OFF"
;
final
static
public
Level
OFF
=
new
Level
(
OFF_INT
,
OFF_NAME
,
0
);
final
static
public
Level
ERROR
=
new
Level
(
ERROR_INT
,
ERROR_NAME
,
3
);
final
static
public
Level
WARN
=
new
Level
(
WARN_INT
,
WARN_NAME
,
4
);
final
static
public
Level
INFO
=
new
Level
(
INFO_INT
,
INFO_NAME
,
6
);
final
static
public
Level
DEBUG
=
new
Level
(
DEBUG_INT
,
DEBUG_NAME
,
7
);
final
static
public
Level
ALL
=
new
Level
(
ALL_INT
,
ALL_NAME
,
7
);
static
final
long
serialVersionUID
=
3491141966387921974L
;
protected
Level
(
int
level
,
String
levelStr
,
int
syslogEquivalent
)
{
this
.
level
=
level
;
this
.
levelStr
=
levelStr
;
this
.
syslogEquivalent
=
syslogEquivalent
;
}
public
static
Level
toLevel
(
String
sArg
)
{
return
toLevel
(
sArg
,
Level
.
DEBUG
);
}
public
static
Level
toLevel
(
int
val
)
{
return
toLevel
(
val
,
Level
.
DEBUG
);
}
public
static
Level
toLevel
(
int
val
,
Level
defaultLevel
)
{
switch
(
val
)
{
case
ALL_INT:
return
ALL
;
case
DEBUG_INT:
return
Level
.
DEBUG
;
case
INFO_INT:
return
Level
.
INFO
;
case
WARN_INT:
return
Level
.
WARN
;
case
ERROR_INT:
return
Level
.
ERROR
;
case
OFF_INT:
return
OFF
;
default
:
return
defaultLevel
;
}
}
public
static
Level
toLevel
(
String
sArg
,
Level
defaultLevel
)
{
if
(
sArg
==
null
)
{
return
defaultLevel
;
}
String
s
=
sArg
.
toUpperCase
();
if
(
s
.
equals
(
ALL_NAME
))
{
return
Level
.
ALL
;
}
if
(
s
.
equals
(
DEBUG_NAME
))
{
return
Level
.
DEBUG
;
}
if
(
s
.
equals
(
INFO_NAME
))
{
return
Level
.
INFO
;
}
if
(
s
.
equals
(
WARN_NAME
))
{
return
Level
.
WARN
;
}
if
(
s
.
equals
(
ERROR_NAME
))
{
return
Level
.
ERROR
;
}
if
(
s
.
equals
(
OFF_NAME
))
{
return
Level
.
OFF
;
}
if
(
s
.
equals
(
INFO_NAME
))
{
return
Level
.
INFO
;
}
return
defaultLevel
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
o
instanceof
Level
)
{
Level
r
=
(
Level
)
o
;
return
this
.
level
==
r
.
level
;
}
else
{
return
false
;
}
}
@Override
public
int
hashCode
()
{
int
result
=
level
;
result
=
31
*
result
+
(
levelStr
!=
null
?
levelStr
.
hashCode
()
:
0
);
result
=
31
*
result
+
syslogEquivalent
;
return
result
;
}
public
boolean
isGreaterOrEqual
(
Level
r
)
{
return
level
>=
r
.
level
;
}
@Override
final
public
String
toString
()
{
return
levelStr
;
}
public
final
int
toInt
()
{
return
level
;
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/Logger.java
已删除
100755 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
java.util.Enumeration
;
import
java.util.Hashtable
;
import
java.util.Vector
;
public
class
Logger
implements
Appender
.
AppenderPipeline
{
private
static
final
String
FQCN
=
Logger
.
class
.
getName
();
private
static
final
DefaultLoggerRepository
REPOSITORY
=
new
DefaultLoggerRepository
(
new
RootLogger
(
Level
.
DEBUG
));
public
static
LoggerRepository
getRepository
()
{
return
REPOSITORY
;
}
private
String
name
;
volatile
private
Level
level
;
volatile
private
Logger
parent
;
Appender
.
AppenderPipelineImpl
appenderPipeline
;
private
boolean
additive
=
true
;
private
Logger
(
String
name
)
{
this
.
name
=
name
;
}
static
public
Logger
getLogger
(
String
name
)
{
return
getRepository
().
getLogger
(
name
);
}
static
public
Logger
getLogger
(
Class
clazz
)
{
return
getRepository
().
getLogger
(
clazz
.
getName
());
}
public
static
Logger
getRootLogger
()
{
return
getRepository
().
getRootLogger
();
}
@Override
synchronized
public
void
addAppender
(
Appender
newAppender
)
{
if
(
appenderPipeline
==
null
)
{
appenderPipeline
=
new
Appender
.
AppenderPipelineImpl
();
}
appenderPipeline
.
addAppender
(
newAppender
);
}
public
void
callAppenders
(
LoggingEvent
event
)
{
int
writes
=
0
;
for
(
Logger
logger
=
this
;
logger
!=
null
;
logger
=
logger
.
parent
)
{
synchronized
(
logger
)
{
if
(
logger
.
appenderPipeline
!=
null
)
{
writes
+=
logger
.
appenderPipeline
.
appendLoopOnAppenders
(
event
);
}
if
(!
logger
.
additive
)
{
break
;
}
}
}
if
(
writes
==
0
)
{
getRepository
().
emitNoAppenderWarning
(
this
);
}
}
synchronized
void
closeNestedAppenders
()
{
Enumeration
enumeration
=
this
.
getAllAppenders
();
if
(
enumeration
!=
null
)
{
while
(
enumeration
.
hasMoreElements
())
{
Appender
a
=
(
Appender
)
enumeration
.
nextElement
();
if
(
a
instanceof
Appender
.
AppenderPipeline
)
{
a
.
close
();
}
}
}
}
public
void
debug
(
Object
message
)
{
if
(
getRepository
().
isDisabled
(
Level
.
DEBUG_INT
))
{
return
;
}
if
(
Level
.
DEBUG
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
DEBUG
,
message
,
null
);
}
}
public
void
debug
(
Object
message
,
Throwable
t
)
{
if
(
getRepository
().
isDisabled
(
Level
.
DEBUG_INT
))
{
return
;
}
if
(
Level
.
DEBUG
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
DEBUG
,
message
,
t
);
}
}
public
void
error
(
Object
message
)
{
if
(
getRepository
().
isDisabled
(
Level
.
ERROR_INT
))
{
return
;
}
if
(
Level
.
ERROR
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
ERROR
,
message
,
null
);
}
}
public
void
error
(
Object
message
,
Throwable
t
)
{
if
(
getRepository
().
isDisabled
(
Level
.
ERROR_INT
))
{
return
;
}
if
(
Level
.
ERROR
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
ERROR
,
message
,
t
);
}
}
protected
void
forcedLog
(
String
fqcn
,
Level
level
,
Object
message
,
Throwable
t
)
{
callAppenders
(
new
LoggingEvent
(
fqcn
,
this
,
level
,
message
,
t
));
}
@Override
synchronized
public
Enumeration
getAllAppenders
()
{
if
(
appenderPipeline
==
null
)
{
return
null
;
}
else
{
return
appenderPipeline
.
getAllAppenders
();
}
}
@Override
synchronized
public
Appender
getAppender
(
String
name
)
{
if
(
appenderPipeline
==
null
||
name
==
null
)
{
return
null
;
}
return
appenderPipeline
.
getAppender
(
name
);
}
public
Level
getEffectiveLevel
()
{
for
(
Logger
c
=
this
;
c
!=
null
;
c
=
c
.
parent
)
{
if
(
c
.
level
!=
null
)
{
return
c
.
level
;
}
}
return
null
;
}
public
final
String
getName
()
{
return
name
;
}
final
public
Level
getLevel
()
{
return
this
.
level
;
}
public
void
info
(
Object
message
)
{
if
(
getRepository
().
isDisabled
(
Level
.
INFO_INT
))
{
return
;
}
if
(
Level
.
INFO
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
INFO
,
message
,
null
);
}
}
public
void
info
(
Object
message
,
Throwable
t
)
{
if
(
getRepository
().
isDisabled
(
Level
.
INFO_INT
))
{
return
;
}
if
(
Level
.
INFO
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
INFO
,
message
,
t
);
}
}
@Override
public
boolean
isAttached
(
Appender
appender
)
{
return
appender
!=
null
&&
appenderPipeline
!=
null
&&
appenderPipeline
.
isAttached
(
appender
);
}
@Override
synchronized
public
void
removeAllAppenders
()
{
if
(
appenderPipeline
!=
null
)
{
appenderPipeline
.
removeAllAppenders
();
appenderPipeline
=
null
;
}
}
@Override
synchronized
public
void
removeAppender
(
Appender
appender
)
{
if
(
appender
==
null
||
appenderPipeline
==
null
)
{
return
;
}
appenderPipeline
.
removeAppender
(
appender
);
}
@Override
synchronized
public
void
removeAppender
(
String
name
)
{
if
(
name
==
null
||
appenderPipeline
==
null
)
{
return
;
}
appenderPipeline
.
removeAppender
(
name
);
}
public
void
setAdditivity
(
boolean
additive
)
{
this
.
additive
=
additive
;
}
public
void
setLevel
(
Level
level
)
{
this
.
level
=
level
;
}
public
void
warn
(
Object
message
)
{
if
(
getRepository
().
isDisabled
(
Level
.
WARN_INT
))
{
return
;
}
if
(
Level
.
WARN
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
WARN
,
message
,
null
);
}
}
public
void
warn
(
Object
message
,
Throwable
t
)
{
if
(
getRepository
().
isDisabled
(
Level
.
WARN_INT
))
{
return
;
}
if
(
Level
.
WARN
.
isGreaterOrEqual
(
this
.
getEffectiveLevel
()))
{
forcedLog
(
FQCN
,
Level
.
WARN
,
message
,
t
);
}
}
public
interface
LoggerRepository
{
boolean
isDisabled
(
int
level
);
void
setLogLevel
(
Level
level
);
void
emitNoAppenderWarning
(
Logger
cat
);
Level
getLogLevel
();
Logger
getLogger
(
String
name
);
Logger
getRootLogger
();
Logger
exists
(
String
name
);
void
shutdown
();
Enumeration
getCurrentLoggers
();
}
public
static
class
ProvisionNode
extends
Vector
<
Logger
>
{
ProvisionNode
(
Logger
logger
)
{
super
();
addElement
(
logger
);
}
}
public
static
class
DefaultLoggerRepository
implements
LoggerRepository
{
final
Hashtable
<
CategoryKey
,
Object
>
ht
=
new
Hashtable
<
CategoryKey
,
Object
>();
Logger
root
;
int
logLevelInt
;
Level
logLevel
;
boolean
emittedNoAppenderWarning
=
false
;
public
DefaultLoggerRepository
(
Logger
root
)
{
this
.
root
=
root
;
setLogLevel
(
Level
.
ALL
);
}
@Override
public
void
emitNoAppenderWarning
(
Logger
cat
)
{
if
(!
this
.
emittedNoAppenderWarning
)
{
SysLogger
.
warn
(
"No appenders could be found for logger ("
+
cat
.
getName
()
+
")."
);
SysLogger
.
warn
(
"Please initialize the logger system properly."
);
this
.
emittedNoAppenderWarning
=
true
;
}
}
@Override
public
Logger
exists
(
String
name
)
{
Object
o
=
ht
.
get
(
new
CategoryKey
(
name
));
if
(
o
instanceof
Logger
)
{
return
(
Logger
)
o
;
}
else
{
return
null
;
}
}
@Override
public
void
setLogLevel
(
Level
l
)
{
if
(
l
!=
null
)
{
logLevelInt
=
l
.
level
;
logLevel
=
l
;
}
}
@Override
public
Level
getLogLevel
()
{
return
logLevel
;
}
@Override
public
Logger
getLogger
(
String
name
)
{
CategoryKey
key
=
new
CategoryKey
(
name
);
Logger
logger
;
synchronized
(
ht
)
{
Object
o
=
ht
.
get
(
key
);
if
(
o
==
null
)
{
logger
=
makeNewLoggerInstance
(
name
);
ht
.
put
(
key
,
logger
);
updateParents
(
logger
);
return
logger
;
}
else
if
(
o
instanceof
Logger
)
{
return
(
Logger
)
o
;
}
else
if
(
o
instanceof
ProvisionNode
)
{
logger
=
makeNewLoggerInstance
(
name
);
ht
.
put
(
key
,
logger
);
updateChildren
((
ProvisionNode
)
o
,
logger
);
updateParents
(
logger
);
return
logger
;
}
else
{
return
null
;
}
}
}
public
Logger
makeNewLoggerInstance
(
String
name
)
{
return
new
Logger
(
name
);
}
@Override
public
Enumeration
getCurrentLoggers
()
{
Vector
<
Logger
>
loggers
=
new
Vector
<
Logger
>(
ht
.
size
());
Enumeration
elems
=
ht
.
elements
();
while
(
elems
.
hasMoreElements
())
{
Object
o
=
elems
.
nextElement
();
if
(
o
instanceof
Logger
)
{
Logger
logger
=
(
Logger
)
o
;
loggers
.
addElement
(
logger
);
}
}
return
loggers
.
elements
();
}
@Override
public
Logger
getRootLogger
()
{
return
root
;
}
@Override
public
boolean
isDisabled
(
int
level
)
{
return
logLevelInt
>
level
;
}
@Override
public
void
shutdown
()
{
Logger
root
=
getRootLogger
();
root
.
closeNestedAppenders
();
synchronized
(
ht
)
{
Enumeration
cats
=
this
.
getCurrentLoggers
();
while
(
cats
.
hasMoreElements
())
{
Logger
c
=
(
Logger
)
cats
.
nextElement
();
c
.
closeNestedAppenders
();
}
root
.
removeAllAppenders
();
}
}
private
void
updateParents
(
Logger
cat
)
{
String
name
=
cat
.
name
;
int
length
=
name
.
length
();
boolean
parentFound
=
false
;
for
(
int
i
=
name
.
lastIndexOf
(
'.'
,
length
-
1
);
i
>=
0
;
i
=
name
.
lastIndexOf
(
'.'
,
i
-
1
))
{
String
substr
=
name
.
substring
(
0
,
i
);
CategoryKey
key
=
new
CategoryKey
(
substr
);
Object
o
=
ht
.
get
(
key
);
if
(
o
==
null
)
{
ht
.
put
(
key
,
new
ProvisionNode
(
cat
));
}
else
if
(
o
instanceof
Logger
)
{
parentFound
=
true
;
cat
.
parent
=
(
Logger
)
o
;
break
;
}
else
if
(
o
instanceof
ProvisionNode
)
{
((
ProvisionNode
)
o
).
addElement
(
cat
);
}
else
{
Exception
e
=
new
IllegalStateException
(
"unexpected object type "
+
o
.
getClass
()
+
" in ht."
);
e
.
printStackTrace
();
}
}
if
(!
parentFound
)
{
cat
.
parent
=
root
;
}
}
private
void
updateChildren
(
ProvisionNode
pn
,
Logger
logger
)
{
final
int
last
=
pn
.
size
();
for
(
int
i
=
0
;
i
<
last
;
i
++)
{
Logger
l
=
pn
.
elementAt
(
i
);
if
(!
l
.
parent
.
name
.
startsWith
(
logger
.
name
))
{
logger
.
parent
=
l
.
parent
;
l
.
parent
=
logger
;
}
}
}
private
class
CategoryKey
{
String
name
;
int
hashCache
;
CategoryKey
(
String
name
)
{
this
.
name
=
name
;
hashCache
=
name
.
hashCode
();
}
@Override
final
public
int
hashCode
()
{
return
hashCache
;
}
@Override
final
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
{
return
true
;
}
if
(
o
!=
null
&&
o
instanceof
CategoryKey
)
{
CategoryKey
cc
=
(
CategoryKey
)
o
;
return
name
.
equals
(
cc
.
name
);
}
else
{
return
false
;
}
}
}
}
public
static
class
RootLogger
extends
Logger
{
public
RootLogger
(
Level
level
)
{
super
(
"root"
);
setLevel
(
level
);
}
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/LoggingBuilder.java
已删除
100644 → 0
浏览文件 @
e990e69d
此差异已折叠。
点击以展开。
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/LoggingEvent.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
java.io.*
;
import
java.util.ArrayList
;
public
class
LoggingEvent
implements
java
.
io
.
Serializable
{
transient
public
final
String
fqnOfCategoryClass
;
transient
private
Object
message
;
transient
private
Level
level
;
transient
private
Logger
logger
;
private
String
renderedMessage
;
private
String
threadName
;
public
final
long
timeStamp
;
private
Throwable
throwable
;
public
LoggingEvent
(
String
fqnOfCategoryClass
,
Logger
logger
,
Level
level
,
Object
message
,
Throwable
throwable
)
{
this
.
fqnOfCategoryClass
=
fqnOfCategoryClass
;
this
.
message
=
message
;
this
.
logger
=
logger
;
this
.
throwable
=
throwable
;
this
.
level
=
level
;
timeStamp
=
System
.
currentTimeMillis
();
}
public
Object
getMessage
()
{
if
(
message
!=
null
)
{
return
message
;
}
else
{
return
getRenderedMessage
();
}
}
public
String
getRenderedMessage
()
{
if
(
renderedMessage
==
null
&&
message
!=
null
)
{
if
(
message
instanceof
String
)
{
renderedMessage
=
(
String
)
message
;
}
else
{
renderedMessage
=
message
.
toString
();
}
}
return
renderedMessage
;
}
public
String
getThreadName
()
{
if
(
threadName
==
null
)
{
threadName
=
(
Thread
.
currentThread
()).
getName
();
}
return
threadName
;
}
public
Level
getLevel
()
{
return
level
;
}
public
String
getLoggerName
()
{
return
logger
.
getName
();
}
public
String
[]
getThrowableStr
()
{
if
(
throwable
==
null
)
{
return
null
;
}
StringWriter
sw
=
new
StringWriter
();
PrintWriter
pw
=
new
PrintWriter
(
sw
);
try
{
throwable
.
printStackTrace
(
pw
);
}
catch
(
RuntimeException
ex
)
{
SysLogger
.
warn
(
"InnerLogger print stack trace error"
,
ex
);
}
pw
.
flush
();
LineNumberReader
reader
=
new
LineNumberReader
(
new
StringReader
(
sw
.
toString
()));
ArrayList
<
String
>
lines
=
new
ArrayList
<
String
>();
try
{
String
line
=
reader
.
readLine
();
while
(
line
!=
null
)
{
lines
.
add
(
line
);
line
=
reader
.
readLine
();
}
}
catch
(
IOException
ex
)
{
if
(
ex
instanceof
InterruptedIOException
)
{
Thread
.
currentThread
().
interrupt
();
}
lines
.
add
(
ex
.
toString
());
}
String
[]
tempRep
=
new
String
[
lines
.
size
()];
lines
.
toArray
(
tempRep
);
return
tempRep
;
}
}
whatsmars-rpc/whatsmars-logging/src/main/java/org/hongxi/whatsmars/common/logging/inner/SysLogger.java
已删除
100755 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
public
class
SysLogger
{
protected
static
boolean
debugEnabled
=
false
;
private
static
boolean
quietMode
=
false
;
private
static
final
String
PREFIX
=
"RocketMQLog: "
;
private
static
final
String
ERR_PREFIX
=
"RocketMQLog:ERROR "
;
private
static
final
String
WARN_PREFIX
=
"RocketMQLog:WARN "
;
public
static
void
setInternalDebugging
(
boolean
enabled
)
{
debugEnabled
=
enabled
;
}
public
static
void
debug
(
String
msg
)
{
if
(
debugEnabled
&&
!
quietMode
)
{
System
.
out
.
printf
(
"%s"
,
PREFIX
+
msg
);
}
}
public
static
void
debug
(
String
msg
,
Throwable
t
)
{
if
(
debugEnabled
&&
!
quietMode
)
{
System
.
out
.
printf
(
"%s"
,
PREFIX
+
msg
);
if
(
t
!=
null
)
{
t
.
printStackTrace
(
System
.
out
);
}
}
}
public
static
void
error
(
String
msg
)
{
if
(
quietMode
)
{
return
;
}
System
.
err
.
println
(
ERR_PREFIX
+
msg
);
}
public
static
void
error
(
String
msg
,
Throwable
t
)
{
if
(
quietMode
)
{
return
;
}
System
.
err
.
println
(
ERR_PREFIX
+
msg
);
if
(
t
!=
null
)
{
t
.
printStackTrace
();
}
}
public
static
void
setQuietMode
(
boolean
quietMode
)
{
SysLogger
.
quietMode
=
quietMode
;
}
public
static
void
warn
(
String
msg
)
{
if
(
quietMode
)
{
return
;
}
System
.
err
.
println
(
WARN_PREFIX
+
msg
);
}
public
static
void
warn
(
String
msg
,
Throwable
t
)
{
if
(
quietMode
)
{
return
;
}
System
.
err
.
println
(
WARN_PREFIX
+
msg
);
if
(
t
!=
null
)
{
t
.
printStackTrace
();
}
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/BasicLoggerTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
org.hongxi.whatsmars.common.logging.inner.Level
;
import
org.hongxi.whatsmars.common.logging.inner.Logger
;
import
org.hongxi.whatsmars.common.logging.inner.LoggingEvent
;
import
org.junit.After
;
import
org.junit.Before
;
import
java.io.*
;
public
class
BasicLoggerTest
{
protected
Logger
logger
=
Logger
.
getLogger
(
"test"
);
protected
LoggingEvent
loggingEvent
;
protected
String
loggingDir
=
System
.
getProperty
(
"user.home"
)
+
"/logs/rocketmq-test"
;
@Before
public
void
createLoggingEvent
()
{
loggingEvent
=
new
LoggingEvent
(
Logger
.
class
.
getName
(),
logger
,
Level
.
INFO
,
"junit test error"
,
new
RuntimeException
(
"createLogging error"
));
}
public
String
readFile
(
String
file
)
throws
IOException
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
FileInputStream
fileInputStream
=
new
FileInputStream
(
file
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
fileInputStream
));
String
line
=
bufferedReader
.
readLine
();
while
(
line
!=
null
)
{
stringBuilder
.
append
(
line
);
stringBuilder
.
append
(
"\r\n"
);
line
=
bufferedReader
.
readLine
();
}
bufferedReader
.
close
();
return
stringBuilder
.
toString
();
}
@After
public
void
clean
()
{
File
file
=
new
File
(
loggingDir
);
if
(
file
.
exists
())
{
File
[]
files
=
file
.
listFiles
();
for
(
File
file1
:
files
)
{
file1
.
delete
();
}
}
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/InnerLoggerFactoryTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
org.hongxi.whatsmars.common.logging.inner.Appender
;
import
org.hongxi.whatsmars.common.logging.inner.Level
;
import
org.hongxi.whatsmars.common.logging.inner.Logger
;
import
org.hongxi.whatsmars.common.logging.inner.LoggingBuilder
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
public
class
InnerLoggerFactoryTest
extends
BasicLoggerTest
{
private
ByteArrayOutputStream
byteArrayOutputStream
;
public
static
final
String
LOGGER
=
"ConsoleLogger"
;
private
PrintStream
out
;
@Before
public
void
initLogger
()
{
out
=
System
.
out
;
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
byteArrayOutputStream
));
Appender
consoleAppender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
Logger
consoleLogger
=
Logger
.
getLogger
(
"ConsoleLogger"
);
consoleLogger
.
setAdditivity
(
false
);
consoleLogger
.
addAppender
(
consoleAppender
);
consoleLogger
.
setLevel
(
Level
.
INFO
);
}
@After
public
void
fixConsole
()
{
System
.
setOut
(
out
);
}
@Test
public
void
testInnerLoggerFactory
()
{
InternalLoggerFactory
.
setCurrentLoggerType
(
InternalLoggerFactory
.
LOGGER_INNER
);
InternalLogger
logger1
=
InnerLoggerFactory
.
getLogger
(
LOGGER
);
InternalLogger
logger
=
InternalLoggerFactory
.
getLogger
(
LOGGER
);
Assert
.
assertTrue
(
logger
.
getName
().
equals
(
logger1
.
getName
()));
InternalLogger
logger2
=
InnerLoggerFactory
.
getLogger
(
InnerLoggerFactoryTest
.
class
);
InnerLoggerFactory
.
InnerLogger
logger3
=
(
InnerLoggerFactory
.
InnerLogger
)
logger2
;
logger
.
info
(
"innerLogger inner info Message"
);
logger
.
error
(
"innerLogger inner error Message"
,
new
RuntimeException
());
logger
.
debug
(
"innerLogger inner debug message"
);
logger3
.
info
(
"innerLogger info message"
);
logger3
.
error
(
"logback error message"
);
logger3
.
info
(
"info {}"
,
"hahahah"
);
logger3
.
warn
(
"warn {}"
,
"hahahah"
);
logger3
.
warn
(
"logger3 warn"
);
logger3
.
error
(
"error {}"
,
"hahahah"
);
logger3
.
debug
(
"debug {}"
,
"hahahah"
);
String
content
=
new
String
(
byteArrayOutputStream
.
toByteArray
());
System
.
out
.
println
(
content
);
Assert
.
assertTrue
(
content
.
contains
(
"InnerLoggerFactoryTest"
));
Assert
.
assertTrue
(
content
.
contains
(
"info"
));
Assert
.
assertTrue
(
content
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(!
content
.
contains
(
"debug"
));
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/InternalLoggerTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
org.hongxi.whatsmars.common.logging.inner.*
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
public
class
InternalLoggerTest
{
@Test
public
void
testInternalLogger
()
{
SysLogger
.
setQuietMode
(
false
);
SysLogger
.
setInternalDebugging
(
true
);
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
byteArrayOutputStream
));
Appender
consoleAppender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
Logger
consoleLogger
=
Logger
.
getLogger
(
"ConsoleLogger"
);
consoleLogger
.
setAdditivity
(
false
);
consoleLogger
.
addAppender
(
consoleAppender
);
consoleLogger
.
setLevel
(
Level
.
INFO
);
Logger
.
getRootLogger
().
addAppender
(
consoleAppender
);
InternalLoggerFactory
.
setCurrentLoggerType
(
InternalLoggerFactory
.
LOGGER_INNER
);
InternalLogger
logger
=
InternalLoggerFactory
.
getLogger
(
InternalLoggerTest
.
class
);
InternalLogger
consoleLogger1
=
InternalLoggerFactory
.
getLogger
(
"ConsoleLogger"
);
consoleLogger1
.
warn
(
"simple warn {}"
,
14555
);
logger
.
info
(
"testInternalLogger"
);
consoleLogger1
.
info
(
"consoleLogger1"
);
System
.
setOut
(
out
);
consoleAppender
.
close
();
String
result
=
new
String
(
byteArrayOutputStream
.
toByteArray
());
Assert
.
assertTrue
(
result
.
contains
(
"consoleLogger1"
));
Assert
.
assertTrue
(
result
.
contains
(
"testInternalLogger"
));
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/Slf4jLoggerFactoryTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging
;
import
ch.qos.logback.classic.joran.JoranConfigurator
;
import
ch.qos.logback.core.Context
;
import
ch.qos.logback.core.joran.spi.JoranException
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.slf4j.ILoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.net.URL
;
public
class
Slf4jLoggerFactoryTest
extends
BasicLoggerTest
{
public
static
final
String
LOGGER
=
"Slf4jTestLogger"
;
@Before
public
void
initLogback
()
throws
JoranException
{
InternalLoggerFactory
.
setCurrentLoggerType
(
InternalLoggerFactory
.
LOGGER_SLF4J
);
System
.
setProperty
(
"loggingDir"
,
loggingDir
);
ILoggerFactory
iLoggerFactory
=
LoggerFactory
.
getILoggerFactory
();
JoranConfigurator
joranConfigurator
=
new
JoranConfigurator
();
joranConfigurator
.
setContext
((
Context
)
iLoggerFactory
);
URL
logbackConfigFile
=
Slf4jLoggerFactoryTest
.
class
.
getClassLoader
().
getResource
(
"logback_test.xml"
);
if
(
logbackConfigFile
==
null
)
{
throw
new
RuntimeException
(
"can't find logback_test.xml"
);
}
else
{
joranConfigurator
.
doConfigure
(
logbackConfigFile
);
}
}
@Test
public
void
testSlf4j
()
throws
IOException
{
InternalLogger
logger1
=
Slf4jLoggerFactory
.
getLogger
(
LOGGER
);
InternalLogger
logger
=
InternalLoggerFactory
.
getLogger
(
LOGGER
);
Assert
.
assertTrue
(
logger
.
getName
().
equals
(
logger1
.
getName
()));
InternalLogger
logger2
=
Slf4jLoggerFactory
.
getLogger
(
Slf4jLoggerFactoryTest
.
class
);
Slf4jLoggerFactory
.
Slf4jLogger
logger3
=
(
Slf4jLoggerFactory
.
Slf4jLogger
)
logger2
;
String
file
=
loggingDir
+
"/logback_test.log"
;
logger
.
info
(
"logback slf4j info Message"
);
logger
.
error
(
"logback slf4j error Message"
,
new
RuntimeException
(
"test"
));
logger
.
debug
(
"logback slf4j debug message"
);
logger3
.
info
(
"logback info message"
);
logger3
.
error
(
"logback error message"
);
logger3
.
info
(
"info {}"
,
"hahahah"
);
logger3
.
warn
(
"warn {}"
,
"hahahah"
);
logger3
.
warn
(
"logger3 warn"
);
logger3
.
error
(
"error {}"
,
"hahahah"
);
logger3
.
debug
(
"debug {}"
,
"hahahah"
);
String
content
=
readFile
(
file
);
System
.
out
.
println
(
content
);
Assert
.
assertTrue
(
content
.
contains
(
"Slf4jLoggerFactoryTest"
));
Assert
.
assertTrue
(
content
.
contains
(
"info"
));
Assert
.
assertTrue
(
content
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(!
content
.
contains
(
"debug"
));
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/AppenderTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.BasicLoggerTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
public
class
AppenderTest
extends
BasicLoggerTest
{
@Test
public
void
testConsole
()
{
SysLogger
.
setQuietMode
(
false
);
SysLogger
.
setInternalDebugging
(
true
);
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
byteArrayOutputStream
));
Appender
consoleAppender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
LoggingBuilder
.
ConsoleAppender
consoleAppender1
=
(
LoggingBuilder
.
ConsoleAppender
)
consoleAppender
;
String
target
=
consoleAppender1
.
getTarget
();
Assert
.
assertTrue
(
target
.
equals
(
LoggingBuilder
.
SYSTEM_OUT
));
Layout
layout
=
consoleAppender
.
getLayout
();
Assert
.
assertTrue
(
layout
instanceof
LoggingBuilder
.
DefaultLayout
);
Logger
consoleLogger
=
Logger
.
getLogger
(
"ConsoleLogger"
);
consoleLogger
.
setAdditivity
(
false
);
consoleLogger
.
addAppender
(
consoleAppender
);
consoleLogger
.
setLevel
(
Level
.
INFO
);
Logger
.
getRootLogger
().
addAppender
(
consoleAppender
);
Logger
.
getLogger
(
AppenderTest
.
class
).
info
(
"this is a AppenderTest log"
);
Logger
.
getLogger
(
"ConsoleLogger"
).
info
(
"console info Message"
);
Logger
.
getLogger
(
"ConsoleLogger"
).
error
(
"console error Message"
,
new
RuntimeException
());
Logger
.
getLogger
(
"ConsoleLogger"
).
debug
(
"console debug message"
);
System
.
setOut
(
out
);
consoleAppender
.
close
();
String
result
=
new
String
(
byteArrayOutputStream
.
toByteArray
());
Assert
.
assertTrue
(
result
.
contains
(
"info"
));
Assert
.
assertTrue
(
result
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(!
result
.
contains
(
"debug"
));
Assert
.
assertTrue
(
result
.
contains
(
"AppenderTest"
));
}
@Test
public
void
testInnerFile
()
throws
IOException
{
String
file
=
loggingDir
+
"/logger.log"
;
Logger
fileLogger
=
Logger
.
getLogger
(
"fileLogger"
);
Appender
myappender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withDailyFileRollingAppender
(
file
,
"'.'yyyy-MM-dd"
)
.
withName
(
"myappender"
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
fileLogger
.
addAppender
(
myappender
);
Logger
.
getLogger
(
"fileLogger"
).
setLevel
(
Level
.
INFO
);
Logger
.
getLogger
(
"fileLogger"
).
info
(
"fileLogger info Message"
);
Logger
.
getLogger
(
"fileLogger"
).
error
(
"fileLogger error Message"
,
new
RuntimeException
());
Logger
.
getLogger
(
"fileLogger"
).
debug
(
"fileLogger debug message"
);
myappender
.
close
();
String
content
=
readFile
(
file
);
System
.
out
.
println
(
content
);
Assert
.
assertTrue
(
content
.
contains
(
"info"
));
Assert
.
assertTrue
(
content
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(!
content
.
contains
(
"debug"
));
}
@Test
public
void
asyncAppenderTest
()
{
Appender
appender
=
LoggingBuilder
.
newAppenderBuilder
().
withAsync
(
false
,
1024
)
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
Assert
.
assertTrue
(
appender
instanceof
LoggingBuilder
.
AsyncAppender
);
LoggingBuilder
.
AsyncAppender
asyncAppender
=
(
LoggingBuilder
.
AsyncAppender
)
appender
;
Assert
.
assertTrue
(!
asyncAppender
.
getBlocking
());
Assert
.
assertTrue
(
asyncAppender
.
getBufferSize
()
>
0
);
}
@Test
public
void
testWriteAppender
()
{
LoggingBuilder
.
WriterAppender
writerAppender
=
new
LoggingBuilder
.
WriterAppender
();
writerAppender
.
setImmediateFlush
(
true
);
Assert
.
assertTrue
(
writerAppender
.
getImmediateFlush
());
}
@Test
public
void
testFileAppender
()
throws
IOException
{
LoggingBuilder
.
FileAppender
fileAppender
=
new
LoggingBuilder
.
FileAppender
(
new
LoggingBuilder
.
SimpleLayout
(),
loggingDir
+
"/simple.log"
,
true
);
fileAppender
.
setBufferSize
(
1024
);
int
bufferSize
=
fileAppender
.
getBufferSize
();
boolean
bufferedIO
=
fileAppender
.
getBufferedIO
();
Assert
.
assertTrue
(!
bufferedIO
);
Assert
.
assertTrue
(
bufferSize
>
0
);
Assert
.
assertTrue
(
fileAppender
.
getAppend
());
LoggingBuilder
.
RollingFileAppender
rollingFileAppender
=
new
LoggingBuilder
.
RollingFileAppender
();
rollingFileAppender
.
setImmediateFlush
(
true
);
rollingFileAppender
.
setMaximumFileSize
(
1024
*
1024
);
rollingFileAppender
.
setMaxBackupIndex
(
10
);
rollingFileAppender
.
setAppend
(
true
);
rollingFileAppender
.
setFile
(
loggingDir
+
"/rolling_file.log"
);
rollingFileAppender
.
setName
(
"myRollingFileAppender"
);
rollingFileAppender
.
activateOptions
();
Assert
.
assertTrue
(
rollingFileAppender
.
getMaximumFileSize
()
>
0
);
Assert
.
assertTrue
(
rollingFileAppender
.
getMaxBackupIndex
()
==
10
);
}
@Test
public
void
testDailyRollingAppender
()
{
LoggingBuilder
.
DailyRollingFileAppender
dailyRollingFileAppender
=
new
LoggingBuilder
.
DailyRollingFileAppender
();
dailyRollingFileAppender
.
setFile
(
loggingDir
+
"/daily.log"
);
dailyRollingFileAppender
.
setName
(
"dailyAppender"
);
dailyRollingFileAppender
.
setAppend
(
true
);
dailyRollingFileAppender
.
setDatePattern
(
"'.'yyyy-mm-dd"
);
String
datePattern
=
dailyRollingFileAppender
.
getDatePattern
();
Assert
.
assertTrue
(
datePattern
!=
null
);
dailyRollingFileAppender
.
activateOptions
();
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LayoutTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.BasicLoggerTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
LayoutTest
extends
BasicLoggerTest
{
@Test
public
void
testSimpleLayout
()
{
Layout
layout
=
LoggingBuilder
.
newLayoutBuilder
().
withSimpleLayout
().
build
();
String
format
=
layout
.
format
(
loggingEvent
);
Assert
.
assertTrue
(
format
.
contains
(
"junit"
));
}
@Test
public
void
testDefaultLayout
()
{
Layout
layout
=
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
();
String
format
=
layout
.
format
(
loggingEvent
);
String
contentType
=
layout
.
getContentType
();
Assert
.
assertTrue
(
contentType
.
contains
(
"text"
));
Assert
.
assertTrue
(
format
.
contains
(
"createLoggingEvent"
));
Assert
.
assertTrue
(
format
.
contains
(
"createLogging error"
));
Assert
.
assertTrue
(
format
.
contains
(
Thread
.
currentThread
().
getName
()));
}
@Test
public
void
testLogFormat
()
{
Layout
innerLayout
=
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
();
LoggingEvent
loggingEvent
=
new
LoggingEvent
(
Logger
.
class
.
getName
(),
logger
,
Level
.
INFO
,
"junit test error"
,
null
);
String
format
=
innerLayout
.
format
(
loggingEvent
);
System
.
out
.
println
(
format
);
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LevelTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
LevelTest
{
@Test
public
void
levelTest
()
{
Level
info
=
Level
.
toLevel
(
"info"
);
Level
error
=
Level
.
toLevel
(
3
);
Assert
.
assertTrue
(
error
!=
null
&&
info
!=
null
);
}
@Test
public
void
loggerLevel
(){
Level
level
=
Logger
.
getRootLogger
().
getLevel
();
Assert
.
assertTrue
(
level
!=
null
);
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggerRepositoryTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.BasicLoggerTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.util.Enumeration
;
public
class
LoggerRepositoryTest
extends
BasicLoggerTest
{
@Test
public
void
testLoggerRepository
()
{
Logger
.
getRepository
().
setLogLevel
(
Level
.
INFO
);
String
file
=
loggingDir
+
"/repo.log"
;
Logger
fileLogger
=
Logger
.
getLogger
(
"repoLogger"
);
Appender
myappender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withDailyFileRollingAppender
(
file
,
"'.'yyyy-MM-dd"
)
.
withName
(
"repoAppender"
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
fileLogger
.
addAppender
(
myappender
);
Logger
.
getLogger
(
"repoLogger"
).
setLevel
(
Level
.
INFO
);
Logger
repoLogger
=
Logger
.
getRepository
().
exists
(
"repoLogger"
);
Assert
.
assertTrue
(
repoLogger
!=
null
);
Enumeration
currentLoggers
=
Logger
.
getRepository
().
getCurrentLoggers
();
Level
logLevel
=
Logger
.
getRepository
().
getLogLevel
();
Assert
.
assertTrue
(
logLevel
.
equals
(
Level
.
INFO
));
// Logger.getRepository().shutdown();
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggerTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.BasicLoggerTest
;
import
org.hongxi.whatsmars.common.logging.InnerLoggerFactory
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.junit.After
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.PrintStream
;
public
class
LoggerTest
extends
BasicLoggerTest
{
@Before
public
void
init
()
{
InternalLoggerFactory
.
setCurrentLoggerType
(
InnerLoggerFactory
.
LOGGER_INNER
);
}
@Test
public
void
testInnerConsoleLogger
()
throws
IOException
{
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
byteArrayOutputStream
));
Appender
consoleAppender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
Logger
.
getLogger
(
"ConsoleLogger"
).
addAppender
(
consoleAppender
);
Logger
.
getLogger
(
"ConsoleLogger"
).
setLevel
(
Level
.
INFO
);
InternalLogger
consoleLogger1
=
InternalLoggerFactory
.
getLogger
(
"ConsoleLogger"
);
consoleLogger1
.
info
(
"console info Message"
);
consoleLogger1
.
error
(
"console error Message"
,
new
RuntimeException
());
consoleLogger1
.
debug
(
"console debug message"
);
consoleLogger1
.
info
(
"console {} test"
,
"simple"
);
consoleLogger1
.
info
(
"[WATERMARK] Send Queue Size: {} SlowTimeMills: {}"
,
1
,
300
);
consoleLogger1
.
info
(
"new consumer connected, group: {} {} {} channel: {}"
,
"mygroup"
,
"orderly"
,
"broudcast"
,
new
RuntimeException
(
"simple object"
));
System
.
setOut
(
out
);
consoleAppender
.
close
();
String
result
=
new
String
(
byteArrayOutputStream
.
toByteArray
());
System
.
out
.
println
(
result
);
Assert
.
assertTrue
(
result
.
contains
(
"info"
));
Assert
.
assertTrue
(
result
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(
result
.
contains
(
"WATERMARK"
));
Assert
.
assertTrue
(
result
.
contains
(
"consumer"
));
Assert
.
assertTrue
(
result
.
contains
(
"broudcast"
));
Assert
.
assertTrue
(
result
.
contains
(
"simple test"
));
Assert
.
assertTrue
(!
result
.
contains
(
"debug"
));
}
@Test
public
void
testInnerFileLogger
()
throws
IOException
{
String
file
=
loggingDir
+
"/inner.log"
;
Logger
fileLogger
=
Logger
.
getLogger
(
"innerLogger"
);
Appender
myappender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withDailyFileRollingAppender
(
file
,
"'.'yyyy-MM-dd"
)
.
withName
(
"innerAppender"
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
fileLogger
.
addAppender
(
myappender
);
fileLogger
.
setLevel
(
Level
.
INFO
);
InternalLogger
innerLogger
=
InternalLoggerFactory
.
getLogger
(
"innerLogger"
);
innerLogger
.
info
(
"fileLogger info Message"
);
innerLogger
.
error
(
"fileLogger error Message"
,
new
RuntimeException
());
innerLogger
.
debug
(
"fileLogger debug message"
);
myappender
.
close
();
String
content
=
readFile
(
file
);
System
.
out
.
println
(
content
);
Assert
.
assertTrue
(
content
.
contains
(
"info"
));
Assert
.
assertTrue
(
content
.
contains
(
"RuntimeException"
));
Assert
.
assertTrue
(!
content
.
contains
(
"debug"
));
}
@After
public
void
close
()
{
InternalLoggerFactory
.
setCurrentLoggerType
(
null
);
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/LoggingBuilderTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.BasicLoggerTest
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FilenameFilter
;
import
java.io.PrintStream
;
public
class
LoggingBuilderTest
extends
BasicLoggerTest
{
@Test
public
void
testConsole
()
{
PrintStream
out
=
System
.
out
;
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
System
.
setOut
(
new
PrintStream
(
byteArrayOutputStream
));
Appender
consoleAppender
=
LoggingBuilder
.
newAppenderBuilder
()
.
withConsoleAppender
(
LoggingBuilder
.
SYSTEM_OUT
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
consoleAppender
.
doAppend
(
loggingEvent
);
String
result
=
new
String
(
byteArrayOutputStream
.
toByteArray
());
System
.
setOut
(
out
);
Assert
.
assertTrue
(
result
.
contains
(
loggingEvent
.
getMessage
().
toString
()));
}
@Test
public
void
testFileAppender
()
throws
InterruptedException
{
String
logFile
=
loggingDir
+
"/file.log"
;
Appender
rollingFileAppender
=
LoggingBuilder
.
newAppenderBuilder
().
withAsync
(
false
,
102400
)
.
withFileAppender
(
logFile
).
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
rollingFileAppender
.
doAppend
(
loggingEvent
);
}
rollingFileAppender
.
close
();
File
file
=
new
File
(
logFile
);
Assert
.
assertTrue
(
file
.
length
()
>
0
);
}
@Test
public
void
testRollingFileAppender
()
throws
InterruptedException
{
String
rollingFile
=
loggingDir
+
"/rolling.log"
;
Appender
rollingFileAppender
=
LoggingBuilder
.
newAppenderBuilder
().
withAsync
(
false
,
1024
)
.
withRollingFileAppender
(
rollingFile
,
"1024"
,
5
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
rollingFileAppender
.
doAppend
(
loggingEvent
);
}
rollingFileAppender
.
close
();
int
cc
=
0
;
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
File
file
;
if
(
i
==
0
)
{
file
=
new
File
(
rollingFile
);
}
else
{
file
=
new
File
(
rollingFile
+
"."
+
i
);
}
if
(
file
.
exists
()
&&
file
.
length
()
>
0
)
{
cc
+=
1
;
}
}
Assert
.
assertTrue
(
cc
>=
2
);
}
//@Test
public
void
testDailyRollingFileAppender
()
throws
InterruptedException
{
String
rollingFile
=
loggingDir
+
"/daily-rolling--222.log"
;
Appender
rollingFileAppender
=
LoggingBuilder
.
newAppenderBuilder
().
withAsync
(
false
,
1024
)
.
withDailyFileRollingAppender
(
rollingFile
,
"'.'yyyy-MM-dd_HH-mm-ss-SSS"
)
.
withLayout
(
LoggingBuilder
.
newLayoutBuilder
().
withDefaultLayout
().
build
()).
build
();
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
rollingFileAppender
.
doAppend
(
loggingEvent
);
}
rollingFileAppender
.
close
();
File
file
=
new
File
(
loggingDir
);
String
[]
list
=
file
.
list
(
new
FilenameFilter
()
{
@Override
public
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
startsWith
(
"daily-rolling--222.log"
);
}
});
Assert
.
assertTrue
(
list
.
length
>
0
);
}
}
whatsmars-rpc/whatsmars-logging/src/test/java/org/hongxi/whatsmars/common/logging/inner/MessageFormatterTest.java
已删除
100644 → 0
浏览文件 @
e990e69d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.hongxi.whatsmars.common.logging.inner
;
import
org.hongxi.whatsmars.common.logging.InnerLoggerFactory
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
MessageFormatterTest
{
@Test
public
void
formatTest
(){
InnerLoggerFactory
.
FormattingTuple
logging
=
InnerLoggerFactory
.
MessageFormatter
.
format
(
"this is {},and {}"
,
"logging"
,
6546
);
String
message
=
logging
.
getMessage
();
Assert
.
assertTrue
(
message
.
contains
(
"logging"
));
InnerLoggerFactory
.
FormattingTuple
format
=
InnerLoggerFactory
.
MessageFormatter
.
format
(
"cause exception {}"
,
143545
,
new
RuntimeException
());
String
message1
=
format
.
getMessage
();
Throwable
throwable
=
format
.
getThrowable
();
System
.
out
.
println
(
message1
);
Assert
.
assertTrue
(
throwable
!=
null
);
}
}
whatsmars-rpc/whatsmars-logging/src/test/resources/logback_test.xml
已删除
100644 → 0
浏览文件 @
e990e69d
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<configuration>
<appender
name=
"RocketmqClientAppender"
class=
"ch.qos.logback.core.rolling.RollingFileAppender"
>
<file>
${loggingDir}/logback_test.log
</file>
<append>
true
</append>
<rollingPolicy
class=
"ch.qos.logback.core.rolling.FixedWindowRollingPolicy"
>
<fileNamePattern>
${loggingDir}/logback_test.%i.log
</fileNamePattern>
<minIndex>
1
</minIndex>
<maxIndex>
5
</maxIndex>
</rollingPolicy>
<triggeringPolicy
class=
"ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"
>
<maxFileSize>
10MB
</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>
%d{yyy-MM-dd HH:mm:stack,GMT+8} %p %t - %m%n
</pattern>
<charset
class=
"java.nio.charset.Charset"
>
UTF-8
</charset>
</encoder>
</appender>
<logger
name=
"Slf4jTestLogger"
additivity=
"false"
>
<level
value=
"INFO"
/>
<appender-ref
ref=
"RocketmqClientAppender"
/>
</logger>
</configuration>
whatsmars-rpc/whatsmars-remoting/pom.xml
浏览文件 @
63d62ddb
...
...
@@ -29,9 +29,23 @@
<artifactId>
fastjson
</artifactId>
</dependency>
<dependency>
<groupId>
org.hongxi
</groupId>
<artifactId>
whatsmars-logging
</artifactId>
<version>
Rocket.S9
</version>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-slf4j-impl
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.apache.logging.log4j
</groupId>
<artifactId>
log4j-core
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
com.lmax
</groupId>
<artifactId>
disruptor
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/RemotingHelper.java
浏览文件 @
63d62ddb
...
...
@@ -17,12 +17,12 @@
package
org.hongxi.whatsmars.remoting.common
;
import
io.netty.channel.Channel
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.exception.RemotingConnectException
;
import
org.hongxi.whatsmars.remoting.exception.RemotingSendRequestException
;
import
org.hongxi.whatsmars.remoting.exception.RemotingTimeoutException
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
...
...
@@ -34,7 +34,7 @@ public class RemotingHelper {
public
static
final
String
ROCKETMQ_REMOTING
=
"RocketmqRemoting"
;
public
static
final
String
DEFAULT_CHARSET
=
"UTF-8"
;
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ROCKETMQ_REMOTING
);
public
static
String
exceptionSimpleDesc
(
final
Throwable
e
)
{
StringBuffer
sb
=
new
StringBuffer
();
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/RemotingUtil.java
浏览文件 @
63d62ddb
...
...
@@ -19,8 +19,8 @@ package org.hongxi.whatsmars.remoting.common;
import
io.netty.channel.Channel
;
import
io.netty.channel.ChannelFuture
;
import
io.netty.channel.ChannelFutureListener
;
import
org.
hongxi.whatsmars.common.logging.Internal
Logger
;
import
org.
hongxi.whatsmars.common.logging.Internal
LoggerFactory
;
import
org.
slf4j.
Logger
;
import
org.
slf4j.
LoggerFactory
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
...
...
@@ -34,7 +34,7 @@ import java.util.Enumeration;
public
class
RemotingUtil
{
public
static
final
String
OS_NAME
=
System
.
getProperty
(
"os.name"
);
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
boolean
isLinuxPlatform
=
false
;
private
static
boolean
isWindowsPlatform
=
false
;
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/common/ServiceThread.java
浏览文件 @
63d62ddb
...
...
@@ -16,15 +16,14 @@
*/
package
org.hongxi.whatsmars.remoting.common
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Base class for background thread
*/
public
abstract
class
ServiceThread
implements
Runnable
{
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
long
JOIN_TIME
=
90
*
1000
;
protected
final
Thread
thread
;
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyDecoder.java
浏览文件 @
63d62ddb
...
...
@@ -19,16 +19,16 @@ package org.hongxi.whatsmars.remoting.netty;
import
io.netty.buffer.ByteBuf
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.handler.codec.LengthFieldBasedFrameDecoder
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.common.RemotingHelper
;
import
org.hongxi.whatsmars.remoting.common.RemotingUtil
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.nio.ByteBuffer
;
public
class
NettyDecoder
extends
LengthFieldBasedFrameDecoder
{
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
int
FRAME_MAX_LENGTH
=
Integer
.
parseInt
(
System
.
getProperty
(
"com.rocketmq.remoting.frameMaxLength"
,
"16777216"
));
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyEncoder.java
浏览文件 @
63d62ddb
...
...
@@ -19,16 +19,16 @@ package org.hongxi.whatsmars.remoting.netty;
import
io.netty.buffer.ByteBuf
;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.handler.codec.MessageToByteEncoder
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.common.RemotingHelper
;
import
org.hongxi.whatsmars.remoting.common.RemotingUtil
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.nio.ByteBuffer
;
public
class
NettyEncoder
extends
MessageToByteEncoder
<
RemotingCommand
>
{
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
@Override
public
void
encode
(
ChannelHandlerContext
ctx
,
RemotingCommand
remotingCommand
,
ByteBuf
out
)
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyLogger.java
浏览文件 @
63d62ddb
...
...
@@ -19,8 +19,8 @@ package org.hongxi.whatsmars.remoting.netty;
import
io.netty.util.internal.logging.InternalLogLevel
;
import
org.
hongxi.whatsmars.common.logging.Internal
Logger
;
import
org.
hongxi.whatsmars.common.logging.Internal
LoggerFactory
;
import
org.
slf4j.
Logger
;
import
org.
slf4j.
LoggerFactory
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
...
@@ -50,10 +50,10 @@ public class NettyLogger {
private
static
class
NettyBridgeLogger
implements
io
.
netty
.
util
.
internal
.
logging
.
InternalLogger
{
private
Internal
Logger
logger
=
null
;
private
Logger
logger
=
null
;
public
NettyBridgeLogger
(
String
name
)
{
logger
=
Internal
LoggerFactory
.
getLogger
(
name
);
logger
=
LoggerFactory
.
getLogger
(
name
);
}
@Override
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingAbstract.java
浏览文件 @
63d62ddb
...
...
@@ -22,8 +22,6 @@ import io.netty.channel.ChannelFutureListener;
import
io.netty.channel.ChannelHandlerContext
;
import
io.netty.handler.ssl.SslContext
;
import
io.netty.handler.ssl.SslHandler
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.ChannelEventListener
;
import
org.hongxi.whatsmars.remoting.InvokeCallback
;
import
org.hongxi.whatsmars.remoting.RPCHook
;
...
...
@@ -36,6 +34,8 @@ import org.hongxi.whatsmars.remoting.exception.RemotingTimeoutException;
import
org.hongxi.whatsmars.remoting.exception.RemotingTooMuchRequestException
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingSysResponseCode
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.net.SocketAddress
;
import
java.util.HashMap
;
...
...
@@ -50,7 +50,7 @@ public abstract class NettyRemotingAbstract {
/**
* Remoting logger instance.
*/
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
/**
* Semaphore to limit maximum number of on-going one-way requests, which protects system memory footprint.
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingClient.java
浏览文件 @
63d62ddb
...
...
@@ -25,8 +25,6 @@ import io.netty.handler.timeout.IdleState;
import
io.netty.handler.timeout.IdleStateEvent
;
import
io.netty.handler.timeout.IdleStateHandler
;
import
io.netty.util.concurrent.DefaultEventExecutorGroup
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.ChannelEventListener
;
import
org.hongxi.whatsmars.remoting.InvokeCallback
;
import
org.hongxi.whatsmars.remoting.RPCHook
;
...
...
@@ -39,6 +37,8 @@ import org.hongxi.whatsmars.remoting.exception.RemotingSendRequestException;
import
org.hongxi.whatsmars.remoting.exception.RemotingTimeoutException
;
import
org.hongxi.whatsmars.remoting.exception.RemotingTooMuchRequestException
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.net.SocketAddress
;
...
...
@@ -51,7 +51,7 @@ import java.util.concurrent.locks.Lock;
import
java.util.concurrent.locks.ReentrantLock
;
public
class
NettyRemotingClient
extends
NettyRemotingAbstract
implements
RemotingClient
{
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
long
LOCK_TIMEOUT_MILLIS
=
3000
;
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/NettyRemotingServer.java
浏览文件 @
63d62ddb
...
...
@@ -30,8 +30,6 @@ import io.netty.handler.timeout.IdleState;
import
io.netty.handler.timeout.IdleStateEvent
;
import
io.netty.handler.timeout.IdleStateHandler
;
import
io.netty.util.concurrent.DefaultEventExecutorGroup
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.ChannelEventListener
;
import
org.hongxi.whatsmars.remoting.InvokeCallback
;
import
org.hongxi.whatsmars.remoting.RPCHook
;
...
...
@@ -44,6 +42,8 @@ import org.hongxi.whatsmars.remoting.exception.RemotingSendRequestException;
import
org.hongxi.whatsmars.remoting.exception.RemotingTimeoutException
;
import
org.hongxi.whatsmars.remoting.exception.RemotingTooMuchRequestException
;
import
org.hongxi.whatsmars.remoting.protocol.RemotingCommand
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.IOException
;
import
java.net.InetSocketAddress
;
...
...
@@ -57,7 +57,7 @@ import java.util.concurrent.ThreadFactory;
import
java.util.concurrent.atomic.AtomicInteger
;
public
class
NettyRemotingServer
extends
NettyRemotingAbstract
implements
RemotingServer
{
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
final
ServerBootstrap
serverBootstrap
;
private
final
EventLoopGroup
eventLoopGroupSelector
;
private
final
EventLoopGroup
eventLoopGroupBoss
;
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/netty/TlsHelper.java
浏览文件 @
63d62ddb
...
...
@@ -20,9 +20,9 @@ package org.hongxi.whatsmars.remoting.netty;
import
io.netty.handler.ssl.*
;
import
io.netty.handler.ssl.util.InsecureTrustManagerFactory
;
import
io.netty.handler.ssl.util.SelfSignedCertificate
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.common.RemotingHelper
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -47,7 +47,7 @@ public class TlsHelper {
InputStream
decryptPrivateKey
(
String
privateKeyEncryptPath
,
boolean
forClient
)
throws
IOException
;
}
private
static
final
InternalLogger
LOGGER
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
DecryptionStrategy
decryptionStrategy
=
new
DecryptionStrategy
()
{
@Override
...
...
whatsmars-rpc/whatsmars-remoting/src/main/java/org/hongxi/whatsmars/remoting/protocol/RemotingCommand.java
浏览文件 @
63d62ddb
...
...
@@ -17,12 +17,12 @@
package
org.hongxi.whatsmars.remoting.protocol
;
import
com.alibaba.fastjson.annotation.JSONField
;
import
org.hongxi.whatsmars.common.logging.InternalLogger
;
import
org.hongxi.whatsmars.common.logging.InternalLoggerFactory
;
import
org.hongxi.whatsmars.remoting.CommandCustomHeader
;
import
org.hongxi.whatsmars.remoting.annotation.CFNotNull
;
import
org.hongxi.whatsmars.remoting.common.RemotingHelper
;
import
org.hongxi.whatsmars.remoting.exception.RemotingCommandException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Field
;
...
...
@@ -36,7 +36,7 @@ public class RemotingCommand {
public
static
final
String
SERIALIZE_TYPE_PROPERTY
=
"rocketmq.serialize.type"
;
public
static
final
String
SERIALIZE_TYPE_ENV
=
"ROCKETMQ_SERIALIZE_TYPE"
;
public
static
final
String
REMOTING_VERSION_KEY
=
"rocketmq.remoting.version"
;
private
static
final
InternalLogger
log
=
Internal
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
RemotingHelper
.
ROCKETMQ_REMOTING
);
private
static
final
int
RPC_TYPE
=
0
;
// 0, REQUEST_COMMAND
private
static
final
int
RPC_ONEWAY
=
1
;
// 0, RPC
private
static
final
Map
<
Class
<?
extends
CommandCustomHeader
>,
Field
[]>
CLASS_HASH_MAP
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录