Skip to content

Commit

Permalink
feat(scaffold): support integrate with log4j2
Browse files Browse the repository at this point in the history
  • Loading branch information
taccisum committed Oct 12, 2019
1 parent 53283e2 commit 43928b8
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ $ yo deepexi-spring-cloud --help
|模板引擎|✅Thymeleaf|☑️Freemarker|
|对象存储|☑️AliOSS|☑️FastDFS|
|ORM|✅MybatisPlus|✅Mapper|☑️JPA|
|日志系统|✅Logback|☑️Log4j2|
|日志系统|✅Logback|✅Log4j2|
|DDD|
|WebSocket|☑️Spring Boot Websocket|
|Bean转换器|✅SpringMVC Converter|☑️MapStruct|
Expand Down
15 changes: 14 additions & 1 deletion generators/app/handler/configurer/configurers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ files.forEach(file => {
}
})

const types = ['discovery', 'db', 'orm', 'dbPool', 'openfeign', 'mq', 'configservice', 'authentication', 'templateEngine', 'cache', 'jsonParser'];
const types = [
'discovery',
'db',
'orm',
'dbPool',
'openfeign',
'mq',
'configservice',
'authentication',
'templateEngine',
'cache',
'jsonParser',
'log'
];

configurers.receive = (event, args) => {
types.forEach(type => {
Expand Down
13 changes: 13 additions & 0 deletions generators/app/handler/configurer/log4j2_configurer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
key: 'log4j2',
fn: {
configureProviderPomDependencies (optionalDependencies, props) {
optionalDependencies.push({
dependency: [
{ groupId: 'org.springframework.boot' },
{ artifactId: 'spring-boot-starter-log4j2' }
]
})
}
}
}
22 changes: 11 additions & 11 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ const obj = {
},
option: { desc: '模板引擎', type: String, default: 'none' }
},
log: {
prompting: {
type: 'list',
choices: [
'logback',
'log4j2'
],
message: '请选择你使用的日志框架类型'
},
option: { desc: '日志框架', type: String, default: 'logback' }
},
jsonParser: {
prompting: {
type: 'list',
Expand Down Expand Up @@ -206,17 +217,6 @@ const obj = {
// }
// }
},
// log: {
// prompting: {
// type: 'list',
// choices: [
// 'logback',
// 'log4j2'
// ],
// message: '请选择你使用的日志框架类型'
// },
// option: { desc: '日志框架', type: String, default: 'logback' }
// },
apm: {
prompting: {
type: 'list',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<%
let exclusions = '';
if (log === 'log4j2') {
exclusions += `<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>`
}
if (exclusions) {
exclusions = `<exclusions>
${exclusions}
</exclusions>`
print(exclusions);
}
%>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
22 changes: 21 additions & 1 deletion generators/test/app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ const expects = {
redis: new Expect(),
skywalking: new Expect(),
fastjson: new Expect(),
gson: new Expect()
gson: new Expect(),
log4j2: new Expect()
};

const required = expects.required;
Expand Down Expand Up @@ -650,6 +651,12 @@ gson.assertNoProperties = () => {
});
}

const log4j2 = expects.log4j2;
log4j2.addProviderArtifacts([
'spring-boot-starter-log4j2',
'spring-boot-starter-logging'
])

function assertByExpected (expected, expects) {
describe('required files or classes', () => {
for (const key in expects) {
Expand Down Expand Up @@ -865,4 +872,17 @@ describe('optional dependencies', () => {
assertByExpected(['required', 'demo', 'gson'], expects)
});
});

describe('log', () => {
describe('log4j2', () => {
before(() => {
return generate({
log: 'log4j2',
demo: true
})
});

assertByExpected(['required', 'demo', 'log4j2'], expects)
});
});
});

0 comments on commit 43928b8

Please sign in to comment.