Skip to content

Commit c0012ee

Browse files
committed
ApiBoot Logging Sample示例
1 parent 1465e7d commit c0012ee

File tree

8 files changed

+248
-1
lines changed

8 files changed

+248
-1
lines changed

api-boot-samples/api-boot-sample-integration/src/main/java/org/minbox/framework/knowledge/library/service/resource/service/CommonResourceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
@Transactional(rollbackFor = Exception.class)
2626
public class CommonResourceService extends BaseService {
2727
/**
28-
* 根据目标编号 & 资源类型
28+
* 根据目标编号 资源类型
2929
* 查询资源列表
3030
*
3131
* @param targetId 目标编号
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright [2019] [恒宇少年 - 于起宇]
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
~
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
<parent>
23+
<artifactId>api-boot-samples</artifactId>
24+
<groupId>org.minbox.framework</groupId>
25+
<version>2.1.1-SNAPSHOT</version>
26+
</parent>
27+
<modelVersion>4.0.0</modelVersion>
28+
<description>
29+
ApiBoot Logging Sample
30+
</description>
31+
<artifactId>api-boot-sample-logging</artifactId>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
<!--ApiBoot Logging-->
38+
<dependency>
39+
<groupId>org.minbox.framework</groupId>
40+
<artifactId>api-boot-starter-logging</artifactId>
41+
</dependency>
42+
</dependencies>
43+
<dependencyManagement>
44+
<dependencies>
45+
<dependency>
46+
<groupId>org.minbox.framework</groupId>
47+
<artifactId>api-boot-dependencies</artifactId>
48+
<version>2.1.1-SNAPSHOT</version>
49+
<type>pom</type>
50+
<scope>import</scope>
51+
</dependency>
52+
</dependencies>
53+
</dependencyManagement>
54+
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample.logging;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.boot.SpringApplication;
23+
import org.springframework.boot.autoconfigure.SpringBootApplication;
24+
25+
/**
26+
* 日志示例
27+
*
28+
* @author:恒宇少年 - 于起宇
29+
* <p>
30+
* DateTime:2019-07-15 22:41
31+
* Blog:http://blog.yuqiyu.com
32+
* WebSite:http://www.jianshu.com/u/092df3f77bca
33+
* Gitee:https://gitee.com/hengboy
34+
* GitHub:https://github.com/hengboy
35+
*/
36+
@SpringBootApplication
37+
public class ApiBootLoggingApplication {
38+
/**
39+
* logger instance
40+
*/
41+
static Logger logger = LoggerFactory.getLogger(ApiBootLoggingApplication.class);
42+
43+
public static void main(String[] args) {
44+
SpringApplication.run(ApiBootLoggingApplication.class, args);
45+
logger.info("{}服务启动成功.", "ApiBoot Logging Sample");
46+
}
47+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample.logging;
19+
20+
import org.springframework.web.bind.annotation.ControllerAdvice;
21+
import org.springframework.web.bind.annotation.ExceptionHandler;
22+
import org.springframework.web.bind.annotation.ResponseBody;
23+
import org.springframework.web.bind.annotation.RestController;
24+
25+
/**
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-07-16 14:50
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
@ControllerAdvice(annotations = RestController.class)
35+
@ResponseBody
36+
public class ExceptionAdvice {
37+
@ExceptionHandler(Exception.class)
38+
public String exception(Exception exception) {
39+
return "请求异常";
40+
}
41+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample.logging;
19+
20+
import lombok.Data;
21+
import org.springframework.web.bind.annotation.PostMapping;
22+
import org.springframework.web.bind.annotation.RequestBody;
23+
import org.springframework.web.bind.annotation.RestController;
24+
25+
/**
26+
* @author:恒宇少年 - 于起宇
27+
* <p>
28+
* DateTime:2019-07-15 22:48
29+
* Blog:http://blog.yuqiyu.com
30+
* WebSite:http://www.jianshu.com/u/092df3f77bca
31+
* Gitee:https://gitee.com/hengboy
32+
* GitHub:https://github.com/hengboy
33+
*/
34+
@RestController
35+
public class IndexController {
36+
37+
@PostMapping(value = "/index")
38+
public String index(@RequestBody User user) throws Exception {
39+
//user.setName("恒宇少年");
40+
//throw new Exception("学习下");
41+
return user.getName();
42+
}
43+
44+
@Data
45+
public static class User {
46+
private String name;
47+
private String email;
48+
private int age;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.sample.logging;
19+
20+
import org.minbox.framework.api.boot.plugin.logging.ApiBootLog;
21+
import org.minbox.framework.api.boot.plugin.logging.notice.ApiBootLogNotice;
22+
import org.springframework.stereotype.Component;
23+
24+
/**
25+
* ApiBootLogNotice示例
26+
*
27+
* @author:恒宇少年 - 于起宇
28+
* <p>
29+
* DateTime:2019-07-16 15:35
30+
* Blog:http://blog.yuqiyu.com
31+
* WebSite:http://www.jianshu.com/u/092df3f77bca
32+
* Gitee:https://gitee.com/hengboy
33+
* GitHub:https://github.com/hengboy
34+
*/
35+
@Component
36+
public class LocalNoticeSample implements ApiBootLogNotice {
37+
@Override
38+
public int getOrder() {
39+
return 0;
40+
}
41+
42+
@Override
43+
public void notice(ApiBootLog apiBootLog) {
44+
System.out.println(apiBootLog);
45+
}
46+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spring:
2+
application:
3+
name: api-boot-sample-logging
4+
5+
logging:
6+
level:
7+
org.minbox.framework.api.boot.plugin.logging: debug

api-boot-samples/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<module>api-boot-sample-mybatis-enhance-codegen</module>
2828
<module>api-boot-sample-integration</module>
2929
<module>api-boot-sample-mail</module>
30+
<module>api-boot-sample-logging</module>
3031
</modules>
3132

3233
<build>

0 commit comments

Comments
 (0)