Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
64f378a4
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
64f378a4
编写于
3月 24, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
mica-logging 重新设计 gitee #I3CVAT
上级
7997bb99
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
192 addition
and
16 deletion
+192
-16
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/ILoggingAppender.java
...a/net/dreamlu/mica/logging/appender/ILoggingAppender.java
+34
-2
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingFileAppender.java
...et/dreamlu/mica/logging/appender/LoggingFileAppender.java
+29
-2
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingJsonFileAppender.java
...reamlu/mica/logging/appender/LoggingJsonFileAppender.java
+26
-2
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingLogStashAppender.java
...reamlu/mica/logging/appender/LoggingLogStashAppender.java
+26
-2
mica-logging/src/main/java/net/dreamlu/mica/logging/config/LoggingInitializer.java
...a/net/dreamlu/mica/logging/config/LoggingInitializer.java
+2
-1
mica-logging/src/main/java/net/dreamlu/mica/logging/config/MicaLoggingConfiguration.java
...dreamlu/mica/logging/config/MicaLoggingConfiguration.java
+1
-1
mica-logging/src/main/java/net/dreamlu/mica/logging/config/MicaLoggingProperties.java
...et/dreamlu/mica/logging/config/MicaLoggingProperties.java
+4
-4
mica-logging/src/main/java/net/dreamlu/mica/logging/listener/LogbackLoggerContextListener.java
...u/mica/logging/listener/LogbackLoggerContextListener.java
+68
-0
mica-logging/src/main/java/net/dreamlu/mica/logging/utils/LoggingUtil.java
...main/java/net/dreamlu/mica/logging/utils/LoggingUtil.java
+2
-2
未找到文件。
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/ILoggingAppender.java
浏览文件 @
64f378a4
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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
net.dreamlu.mica.logging.appender
;
import
ch.qos.logback.classic.LoggerContext
;
/**
* logging Appender 抽象
*
* @author L.cm
*/
public
interface
ILoggingAppender
{
/**
* all.log
*/
String
LOG_FILE_ALL
=
"all.log"
;
/**
* error.log
*/
String
LOG_FILE_ERROR
=
"error.log"
;
/**
* 启动
*
* @param context LoggerContext
*/
void
start
();
void
start
(
LoggerContext
context
);
/**
* 重置
*
* @param context LoggerContext
*/
void
reset
();
void
reset
(
LoggerContext
context
);
}
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingFileAppender.java
浏览文件 @
64f378a4
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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
net.dreamlu.mica.logging.appender
;
import
ch.qos.logback.classic.LoggerContext
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
net.dreamlu.mica.logging.config.MicaLoggingProperties
;
/**
* 纯文件日志输出,all.log 和 error.log
*
* @author L.cm
*/
@Slf4j
@RequiredArgsConstructor
public
class
LoggingFileAppender
implements
ILoggingAppender
{
private
final
MicaLoggingProperties
properties
;
@Override
public
void
start
()
{
public
void
start
(
LoggerContext
context
)
{
}
@Override
public
void
reset
()
{
public
void
reset
(
LoggerContext
context
)
{
}
}
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingJsonFileAppender.java
浏览文件 @
64f378a4
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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
net.dreamlu.mica.logging.appender
;
import
ch.qos.logback.classic.LoggerContext
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.logging.config.MicaLoggingProperties
;
/**
* json 日志输出,json 日志只输出 all.log
*
* @author L.cm
*/
@RequiredArgsConstructor
public
class
LoggingJsonFileAppender
implements
ILoggingAppender
{
private
final
MicaLoggingProperties
properties
;
@Override
public
void
start
()
{
public
void
start
(
LoggerContext
context
)
{
}
@Override
public
void
reset
()
{
public
void
reset
(
LoggerContext
context
)
{
}
}
mica-logging/src/main/java/net/dreamlu/mica/logging/appender/LoggingLogStashAppender.java
浏览文件 @
64f378a4
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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
net.dreamlu.mica.logging.appender
;
import
ch.qos.logback.classic.LoggerContext
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.logging.config.MicaLoggingProperties
;
/**
* LogStash 输出 json
*
* @author L.cm
*/
@RequiredArgsConstructor
public
class
LoggingLogStashAppender
implements
ILoggingAppender
{
private
final
MicaLoggingProperties
properties
;
@Override
public
void
start
()
{
public
void
start
(
LoggerContext
context
)
{
}
@Override
public
void
reset
()
{
public
void
reset
(
LoggerContext
context
)
{
}
}
mica-logging/src/main/java/net/dreamlu/mica/logging/config/LoggingInitializer.java
浏览文件 @
64f378a4
...
...
@@ -17,6 +17,7 @@
package
net.dreamlu.mica.logging.config
;
import
net.dreamlu.mica.auto.annotation.AutoContextInitializer
;
import
net.dreamlu.mica.logging.appender.ILoggingAppender
;
import
net.dreamlu.mica.logging.utils.LoggingUtil
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ConfigurableApplicationContext
;
...
...
@@ -37,7 +38,7 @@ public class LoggingInitializer implements ApplicationContextInitializer<Configu
// 读取系统配置的日志目录,默认为项目下 logs
String
logBase
=
environment
.
getProperty
(
"logging.file.path"
,
LoggingUtil
.
DEFAULT_LOG_DIR
);
// 用于 spring boot admin 中展示日志
System
.
setProperty
(
"logging.file.name"
,
logBase
+
"/${spring.application.name}/
all.log"
);
System
.
setProperty
(
"logging.file.name"
,
logBase
+
"/${spring.application.name}/
"
+
ILoggingAppender
.
LOG_FILE_ALL
);
}
@Override
...
...
mica-logging/src/main/java/net/dreamlu/mica/logging/config/MicaLoggingConfiguration.java
浏览文件 @
64f378a4
...
...
@@ -66,7 +66,7 @@ public class MicaLoggingConfiguration {
customFields
.
put
(
"profile"
,
profile
);
String
customFieldsJson
=
JsonUtil
.
toJson
(
customFields
);
// 是否采用 json 格式化
boolean
useJsonFormat
=
loggingProperties
.
isUseJsonFormat
();
boolean
useJsonFormat
=
loggingProperties
.
getFiles
().
isUseJsonFormat
();
if
(
logStashProperties
.
isEnabled
())
{
LoggingUtil
.
addLogStashTcpSocketAppender
(
context
,
customFieldsJson
,
logStashProperties
);
}
else
{
...
...
mica-logging/src/main/java/net/dreamlu/mica/logging/config/MicaLoggingProperties.java
浏览文件 @
64f378a4
...
...
@@ -33,10 +33,6 @@ import org.springframework.cloud.context.config.annotation.RefreshScope;
public
class
MicaLoggingProperties
{
public
static
final
String
PREFIX
=
"mica.logging"
;
/**
* 使用 json 格式化
*/
private
boolean
useJsonFormat
=
false
;
private
final
Console
console
=
new
Console
();
private
final
Files
files
=
new
Files
();
private
final
Logstash
logstash
=
new
Logstash
();
...
...
@@ -58,6 +54,10 @@ public class MicaLoggingProperties {
* 是否开启文件日志
*/
private
boolean
enabled
=
true
;
/**
* 使用 json 格式化
*/
private
boolean
useJsonFormat
=
false
;
}
@Getter
...
...
mica-logging/src/main/java/net/dreamlu/mica/logging/listener/LogbackLoggerContextListener.java
0 → 100644
浏览文件 @
64f378a4
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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
net.dreamlu.mica.logging.listener
;
import
ch.qos.logback.classic.Level
;
import
ch.qos.logback.classic.Logger
;
import
ch.qos.logback.classic.LoggerContext
;
import
ch.qos.logback.classic.spi.LoggerContextListener
;
import
ch.qos.logback.core.spi.ContextAwareBase
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.logging.appender.ILoggingAppender
;
import
java.util.List
;
/**
* Logback configuration is achieved by configuration file and API.
* When configuration file change is detected, the configuration is reset.
* This listener ensures that the programmatic configuration is also re-applied after reset.
*
* @author L.cm
*/
@RequiredArgsConstructor
public
class
LogbackLoggerContextListener
extends
ContextAwareBase
implements
LoggerContextListener
{
private
final
List
<
ILoggingAppender
>
appenderList
;
@Override
public
boolean
isResetResistant
()
{
return
true
;
}
@Override
public
void
onStart
(
LoggerContext
context
)
{
for
(
ILoggingAppender
appender
:
appenderList
)
{
appender
.
start
(
context
);
}
}
@Override
public
void
onReset
(
LoggerContext
context
)
{
for
(
ILoggingAppender
appender
:
appenderList
)
{
appender
.
reset
(
context
);
}
}
@Override
public
void
onStop
(
LoggerContext
context
)
{
// Nothing to do.
}
@Override
public
void
onLevelChange
(
Logger
logger
,
Level
level
)
{
// Nothing to do.
}
}
mica-logging/src/main/java/net/dreamlu/mica/logging/utils/LoggingUtil.java
浏览文件 @
64f378a4
...
...
@@ -335,7 +335,7 @@ public class LoggingUtil {
if
(
this
.
loggingProperties
.
getLogstash
().
isEnabled
())
{
addLogStashTcpSocketAppender
(
context
,
customFields
,
loggingProperties
.
getLogstash
());
}
else
{
boolean
useJsonFormat
=
loggingProperties
.
isUseJsonFormat
();
boolean
useJsonFormat
=
loggingProperties
.
getFiles
().
isUseJsonFormat
();
addFileAppender
(
context
,
logFile
,
logErrorFile
,
useJsonFormat
,
customFields
);
}
}
...
...
@@ -345,7 +345,7 @@ public class LoggingUtil {
if
(
this
.
loggingProperties
.
getLogstash
().
isEnabled
())
{
addLogStashTcpSocketAppender
(
context
,
customFields
,
loggingProperties
.
getLogstash
());
}
else
{
boolean
useJsonFormat
=
loggingProperties
.
isUseJsonFormat
();
boolean
useJsonFormat
=
loggingProperties
.
getFiles
().
isUseJsonFormat
();
addFileAppender
(
context
,
logFile
,
logErrorFile
,
useJsonFormat
,
customFields
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录