Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touzizhuo03
Dubbo
提交
81ca7e9f
D
Dubbo
项目概览
touzizhuo03
/
Dubbo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dubbo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
81ca7e9f
编写于
7月 04, 2012
作者:
L
liangfei0201
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add logback container
上级
443616d6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
157 addition
and
0 deletion
+157
-0
dubbo-container/dubbo-container-logback/src/main/java/com/alibaba/dubbo/container/logback/LogbackContainer.java
...com/alibaba/dubbo/container/logback/LogbackContainer.java
+107
-0
dubbo-container/dubbo-container-logback/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container
...-INF/dubbo/internal/com.alibaba.dubbo.container.Container
+1
-0
dubbo-container/dubbo-container-logback/src/test/java/com/alibaba/dubbo/container/logback/LogbackContainerTest.java
...alibaba/dubbo/container/logback/LogbackContainerTest.java
+49
-0
未找到文件。
dubbo-container/dubbo-container-logback/src/main/java/com/alibaba/dubbo/container/logback/LogbackContainer.java
0 → 100644
浏览文件 @
81ca7e9f
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed 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
com.alibaba.dubbo.container.logback
;
import
org.slf4j.LoggerFactory
;
import
ch.qos.logback.classic.Level
;
import
ch.qos.logback.classic.Logger
;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.classic.encoder.PatternLayoutEncoder
;
import
ch.qos.logback.classic.spi.ILoggingEvent
;
import
ch.qos.logback.core.rolling.RollingFileAppender
;
import
ch.qos.logback.core.rolling.TimeBasedRollingPolicy
;
import
com.alibaba.dubbo.common.utils.ConfigUtils
;
import
com.alibaba.dubbo.common.utils.StringUtils
;
import
com.alibaba.dubbo.container.Container
;
/**
* LogbackContainer. (SPI, Singleton, ThreadSafe)
*
* @author {@link "mailto:qq55355383@gmail.com" "yi.tong"}
* @date May 30, 2012
*/
public
class
LogbackContainer
implements
Container
{
public
static
final
String
LOGBACK_FILE
=
"dubbo.logback.file"
;
public
static
final
String
LOGBACK_LEVEL
=
"dubbo.logback.level"
;
public
static
final
String
LOGBACK_MAX_HISTORY
=
"dubbo.logback.maxhistory"
;
public
static
final
String
DEFAULT_LOGBACK_LEVEL
=
"ERROR"
;
public
void
start
()
{
String
file
=
ConfigUtils
.
getProperty
(
LOGBACK_FILE
);
if
(
file
!=
null
&&
file
.
length
()
>
0
)
{
String
level
=
ConfigUtils
.
getProperty
(
LOGBACK_LEVEL
);
if
(
level
==
null
||
level
.
length
()
==
0
)
{
level
=
DEFAULT_LOGBACK_LEVEL
;
}
// maxHistory=0 Infinite history
int
maxHistory
=
StringUtils
.
parseInteger
(
ConfigUtils
.
getProperty
(
LOGBACK_MAX_HISTORY
));
doInitializer
(
file
,
level
,
maxHistory
);
}
}
public
void
stop
()
{
}
/**
* Initializer logback
*
* @param file
* @param level
* @param maxHistory
*/
private
void
doInitializer
(
String
file
,
String
level
,
int
maxHistory
)
{
LoggerContext
loggerContext
=
(
LoggerContext
)
LoggerFactory
.
getILoggerFactory
();
Logger
rootLogger
=
loggerContext
.
getLogger
(
Logger
.
ROOT_LOGGER_NAME
);
rootLogger
.
detachAndStopAllAppenders
();
// appender
RollingFileAppender
<
ILoggingEvent
>
fileAppender
=
new
RollingFileAppender
<
ILoggingEvent
>();
fileAppender
.
setContext
(
loggerContext
);
fileAppender
.
setName
(
"application"
);
fileAppender
.
setFile
(
file
);
fileAppender
.
setAppend
(
true
);
// policy
TimeBasedRollingPolicy
<
ILoggingEvent
>
policy
=
new
TimeBasedRollingPolicy
<
ILoggingEvent
>();
policy
.
setContext
(
loggerContext
);
policy
.
setMaxHistory
(
maxHistory
);
policy
.
setFileNamePattern
(
file
+
".%d{yyyy-MM-dd}"
);
policy
.
setParent
(
fileAppender
);
policy
.
start
();
fileAppender
.
setRollingPolicy
(
policy
);
// encoder
PatternLayoutEncoder
encoder
=
new
PatternLayoutEncoder
();
encoder
.
setContext
(
loggerContext
);
encoder
.
setPattern
(
"%date [%thread] %-5level %logger (%file:%line\\) - %msg%n"
);
encoder
.
start
();
fileAppender
.
setEncoder
(
encoder
);
fileAppender
.
start
();
rootLogger
.
addAppender
(
fileAppender
);
rootLogger
.
setLevel
(
Level
.
toLevel
(
level
));
rootLogger
.
setAdditive
(
false
);
}
}
\ No newline at end of file
dubbo-container/dubbo-container-logback/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container
0 → 100644
浏览文件 @
81ca7e9f
logback=com.alibaba.dubbo.container.logback.LogbackContainer
\ No newline at end of file
dubbo-container/dubbo-container-logback/src/test/java/com/alibaba/dubbo/container/logback/LogbackContainerTest.java
0 → 100644
浏览文件 @
81ca7e9f
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed 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
com.alibaba.dubbo.container.logback
;
import
org.junit.Test
;
import
com.alibaba.dubbo.common.extension.ExtensionLoader
;
import
com.alibaba.dubbo.common.logger.Logger
;
import
com.alibaba.dubbo.common.logger.LoggerFactory
;
import
com.alibaba.dubbo.container.Container
;
/**
* StandaloneContainerTest
*
* @author {@link "mailto:qq55355383@gmail.com" "yi.tong"}
* @date May 30, 2012
*/
public
class
LogbackContainerTest
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
LogbackContainerTest
.
class
);
@Test
public
void
testContainer
()
{
LogbackContainer
container
=
(
LogbackContainer
)
ExtensionLoader
.
getExtensionLoader
(
Container
.
class
)
.
getExtension
(
"logback"
);
container
.
start
();
logger
.
debug
(
"Test debug:"
+
this
.
getClass
().
getName
());
logger
.
warn
(
"Test warn:"
+
this
.
getClass
().
getName
());
logger
.
info
(
"Test info:"
+
this
.
getClass
().
getName
());
logger
.
error
(
"Test error:"
+
this
.
getClass
().
getName
());
container
.
stop
();
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录