Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
4fe4bde0
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 搜索 >>
提交
4fe4bde0
编写于
1月 22, 2022
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
新增一个 mica-tinylog 组件。
上级
35d75f79
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
336 addition
and
2 deletion
+336
-2
build.gradle
build.gradle
+3
-2
mica-bom/build.gradle
mica-bom/build.gradle
+1
-0
mica-tinylog/README.md
mica-tinylog/README.md
+19
-0
mica-tinylog/build.gradle
mica-tinylog/build.gradle
+8
-0
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/config/MicaTinyLogConfiguration.java
...dreamlu/mica/tinylog/config/MicaTinyLogConfiguration.java
+41
-0
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/config/MicaTinyLogProperties.java
...et/dreamlu/mica/tinylog/config/MicaTinyLogProperties.java
+47
-0
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/core/TinyLogLoggingSystem.java
...a/net/dreamlu/mica/tinylog/core/TinyLogLoggingSystem.java
+83
-0
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/listener/TinyLogStartedEventListener.java
...lu/mica/tinylog/listener/TinyLogStartedEventListener.java
+46
-0
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/writers/ConsoleWriter.java
.../java/net/dreamlu/mica/tinylog/writers/ConsoleWriter.java
+70
-0
mica-tinylog/src/main/resources/META-INF/services/org.tinylog.writers.Writer
...in/resources/META-INF/services/org.tinylog.writers.Writer
+1
-0
mica-tinylog/src/main/resources/META-INF/spring.factories
mica-tinylog/src/main/resources/META-INF/spring.factories
+3
-0
mica-tinylog/src/test/java/net/dreamlu/mica/tinylog/test/TinyLogTest.java
.../test/java/net/dreamlu/mica/tinylog/test/TinyLogTest.java
+11
-0
mica-tinylog/src/test/resources/tinylog.properties
mica-tinylog/src/test/resources/tinylog.properties
+2
-0
settings.gradle
settings.gradle
+1
-0
未找到文件。
build.gradle
浏览文件 @
4fe4bde0
...
...
@@ -4,10 +4,10 @@ plugins {
ext
{
javaVersion
=
JavaVersion
.
VERSION_1_8
springBootVersion
=
"2.6.
2
"
springBootVersion
=
"2.6.
3
"
springNativeVersion
=
"0.10.5"
springCloudVersion
=
"2021.0.0"
micaAutoVersion
=
"2.2.
1
"
micaAutoVersion
=
"2.2.
2
"
micaWeiXinVersion
=
"2.1.2"
knife4jVersion
=
"3.0.3"
springdocVersion
=
"1.5.10"
...
...
@@ -24,6 +24,7 @@ ext {
zxingVersion
=
"3.4.1"
jetCacheVersion
=
"2.6.2"
jfinalVersion
=
"4.9.16"
tinylogVersion
=
"2.4.1"
}
configure
(
subprojects
)
{
...
...
mica-bom/build.gradle
浏览文件 @
4fe4bde0
...
...
@@ -30,6 +30,7 @@ dependencyManagement {
dependency
"net.dreamlu:mica-metrics:${VERSION}"
dependency
"net.dreamlu:mica-caffeine:${VERSION}"
dependency
"net.dreamlu:mica-logging:${VERSION}"
dependency
"net.dreamlu:mica-tinylog:${VERSION}"
dependency
"net.dreamlu:mica-qrcode:${VERSION}"
dependency
"net.dreamlu:mica-jetcache:${VERSION}"
dependency
"net.dreamlu:mica-lite:${VERSION}"
...
...
mica-tinylog/README.md
0 → 100644
浏览文件 @
4fe4bde0
# mica-tinylog 组件
## 说明
`tinylog`
组件。支持 Spring boot 配置,支持启动完毕后关闭 Console,
## 使用
### maven
```
xml
<dependency>
<groupId>
net.dreamlu
</groupId>
<artifactId>
mica-tinylog
</artifactId>
<version>
${version}
</version>
</dependency>
```
### gradle
```
groovy
compile
(
"net.dreamlu:mica-tinylog:${version}"
)
```
mica-tinylog/build.gradle
0 → 100644
浏览文件 @
4fe4bde0
dependencies
{
implementation
"org.tinylog:slf4j-tinylog:${tinylogVersion}"
implementation
"org.tinylog:tinylog-impl:${tinylogVersion}"
implementation
"org.springframework.boot:spring-boot"
compileOnly
"org.springframework.cloud:spring-cloud-context"
annotationProcessor
"org.springframework.boot:spring-boot-configuration-processor:$springBootVersion"
annotationProcessor
"org.springframework.boot:spring-boot-autoconfigure-processor:$springBootVersion"
}
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/config/MicaTinyLogConfiguration.java
0 → 100644
浏览文件 @
4fe4bde0
/*
* 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.tinylog.config
;
import
net.dreamlu.mica.tinylog.listener.TinyLogStartedEventListener
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
/**
* logging 日志配置
*
* @author L.cm
*/
@Order
(
Ordered
.
HIGHEST_PRECEDENCE
)
@Configuration
(
proxyBeanMethods
=
false
)
@EnableConfigurationProperties
(
MicaTinyLogProperties
.
class
)
public
class
MicaTinyLogConfiguration
{
@Bean
public
TinyLogStartedEventListener
loggingStartedEventListener
(
MicaTinyLogProperties
properties
)
{
return
new
TinyLogStartedEventListener
(
properties
);
}
}
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/config/MicaTinyLogProperties.java
0 → 100644
浏览文件 @
4fe4bde0
/*
* 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.tinylog.config
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.context.config.annotation.RefreshScope
;
/**
* logging 配置
*
* @author L.cm
*/
@Getter
@Setter
@RefreshScope
@ConfigurationProperties
(
MicaTinyLogProperties
.
PREFIX
)
public
class
MicaTinyLogProperties
{
public
static
final
String
PREFIX
=
"mica.tinylog"
;
private
final
Console
console
=
new
Console
();
@Getter
@Setter
public
static
class
Console
{
/**
* 是否启动完成后关闭控制台日志,适用于,正式环境
*/
private
boolean
closeAfterStart
=
false
;
}
}
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/core/TinyLogLoggingSystem.java
0 → 100644
浏览文件 @
4fe4bde0
/*
* 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.tinylog.core
;
import
org.springframework.boot.context.properties.bind.Bindable
;
import
org.springframework.boot.context.properties.bind.Binder
;
import
org.springframework.boot.logging.*
;
import
org.springframework.boot.logging.logback.LogbackLoggingSystem
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.core.env.Environment
;
import
org.springframework.util.ClassUtils
;
import
org.tinylog.Level
;
import
org.tinylog.configuration.Configuration
;
/**
* TinyLog LoggingSystem
*
* @author L.cm
*/
public
class
TinyLogLoggingSystem
extends
Slf4JLoggingSystem
{
private
static
final
LogLevels
<
Level
>
LEVELS
=
new
LogLevels
<>();
static
{
LEVELS
.
map
(
LogLevel
.
TRACE
,
Level
.
TRACE
);
LEVELS
.
map
(
LogLevel
.
DEBUG
,
Level
.
DEBUG
);
LEVELS
.
map
(
LogLevel
.
INFO
,
Level
.
INFO
);
LEVELS
.
map
(
LogLevel
.
WARN
,
Level
.
WARN
);
LEVELS
.
map
(
LogLevel
.
ERROR
,
Level
.
ERROR
);
LEVELS
.
map
(
LogLevel
.
FATAL
,
Level
.
ERROR
);
LEVELS
.
map
(
LogLevel
.
OFF
,
Level
.
OFF
);
}
public
TinyLogLoggingSystem
(
ClassLoader
classLoader
)
{
super
(
classLoader
);
}
@Override
protected
String
[]
getStandardConfigLocations
()
{
return
new
String
[]{
"tinylog-dev.properties"
,
"tinylog-test.properties"
,
"tinylog.properties"
};
}
@Override
protected
void
loadDefaults
(
LoggingInitializationContext
initializationContext
,
LogFile
logFile
)
{
Environment
environment
=
initializationContext
.
getEnvironment
();
Binder
.
get
(
environment
)
.
bind
(
"tinylog"
,
Bindable
.
mapOf
(
String
.
class
,
String
.
class
))
.
ifBound
(
props
->
props
.
forEach
(
Configuration:
:
set
));
}
/**
* {@link LoggingSystemFactory} that returns {@link LogbackLoggingSystem} if possible.
*/
@Order
public
static
class
Factory
implements
LoggingSystemFactory
{
private
static
final
boolean
PRESENT
=
ClassUtils
.
isPresent
(
"org.tinylog.Logger"
,
LogbackLoggingSystem
.
Factory
.
class
.
getClassLoader
());
@Override
public
LoggingSystem
getLoggingSystem
(
ClassLoader
classLoader
)
{
if
(
PRESENT
)
{
return
new
LogbackLoggingSystem
(
classLoader
);
}
return
null
;
}
}
}
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/listener/TinyLogStartedEventListener.java
0 → 100644
浏览文件 @
4fe4bde0
/*
* 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.tinylog.listener
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.tinylog.config.MicaTinyLogProperties
;
import
net.dreamlu.mica.tinylog.writers.ConsoleWriter
;
import
org.springframework.boot.web.context.WebServerInitializedEvent
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.scheduling.annotation.Async
;
/**
* 项目启动事件通知
*
* @author L.cm
*/
@RequiredArgsConstructor
public
class
TinyLogStartedEventListener
{
private
final
MicaTinyLogProperties
properties
;
@Async
@Order
@EventListener
(
WebServerInitializedEvent
.
class
)
public
void
afterStart
()
{
// 1. 关闭控制台
MicaTinyLogProperties
.
Console
console
=
properties
.
getConsole
();
if
(
console
.
isCloseAfterStart
())
{
ConsoleWriter
.
setEnabled
(
false
);
}
}
}
mica-tinylog/src/main/java/net/dreamlu/mica/tinylog/writers/ConsoleWriter.java
0 → 100644
浏览文件 @
4fe4bde0
/*
* 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.tinylog.writers
;
import
org.tinylog.core.LogEntry
;
import
org.tinylog.core.LogEntryValue
;
import
org.tinylog.writers.Writer
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Map
;
/**
* console Writer
*
* @author L.cm
*/
public
class
ConsoleWriter
implements
Writer
{
private
final
org
.
tinylog
.
writers
.
ConsoleWriter
consoleWriter
;
private
static
volatile
boolean
enabled
=
true
;
public
ConsoleWriter
()
{
this
(
Collections
.
emptyMap
());
}
public
ConsoleWriter
(
final
Map
<
String
,
String
>
properties
)
{
this
.
consoleWriter
=
new
org
.
tinylog
.
writers
.
ConsoleWriter
(
properties
);
}
@Override
public
Collection
<
LogEntryValue
>
getRequiredLogEntryValues
()
{
return
consoleWriter
.
getRequiredLogEntryValues
();
}
@Override
public
void
write
(
LogEntry
logEntry
)
throws
Exception
{
// 判断是否开启 控制台日志
if
(
enabled
)
{
consoleWriter
.
write
(
logEntry
);
}
}
public
static
void
setEnabled
(
boolean
enabled
)
{
ConsoleWriter
.
enabled
=
enabled
;
}
@Override
public
void
flush
()
throws
Exception
{
}
@Override
public
void
close
()
throws
Exception
{
}
}
mica-tinylog/src/main/resources/META-INF/services/org.tinylog.writers.Writer
0 → 100644
浏览文件 @
4fe4bde0
net.dreamlu.mica.tinylog.writers.ConsoleWriter
mica-tinylog/src/main/resources/META-INF/spring.factories
0 → 100644
浏览文件 @
4fe4bde0
# TinyLog Logging Systems
org.springframework.boot.logging.LoggingSystemFactory=\
net.dreamlu.mica.tinylog.core.TinyLogLoggingSystem.Factory
mica-tinylog/src/test/java/net/dreamlu/mica/tinylog/test/TinyLogTest.java
0 → 100644
浏览文件 @
4fe4bde0
package
net.dreamlu.mica.tinylog.test
;
import
org.tinylog.Logger
;
public
class
TinyLogTest
{
public
static
void
main
(
String
[]
args
)
{
Logger
.
info
(
"123123"
);
}
}
mica-tinylog/src/test/resources/tinylog.properties
0 → 100644
浏览文件 @
4fe4bde0
writer
=
console
writer.format
=
{date: HH:mm:ss.SSS} {level}: {message}
settings.gradle
浏览文件 @
4fe4bde0
...
...
@@ -19,3 +19,4 @@ include "mica-jetcache"
include
"mica-lite"
include
"mica-activerecord"
include
"mica-prometheus"
include
"mica-tinylog"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录