์Šคํ”„๋ง ํ”„๋กœ์ ํŠธ์—์„œ logback์„ ์ด์šฉํ•˜์—ฌ ํ™˜๊ฒฝ๋ณ„๋กœ ๋กœ๊ทธ ์„ค์ •์„ ๋‹ค๋ฅด๊ฒŒ ํ•  ๋•Œ 

<if>, <elseif> ๋“ฑ์˜ ํƒœ๊ทธ๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ค„ ์•Œ๊ณ  ์•„๋ž˜์ฒ˜๋Ÿผ ์„ค์ •์„ ํ•ด๋ณด์•˜๋‹ค.

<if condition="property('myproject.profile').equals('live')">
<logger name="com.myproject" level="debug">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.springframework" level="WARN"/>
<root level="info"/>
</if>
<elseif condition="property('myproject.profile').equals('dev')">
<logger name="com.myproject" level="debug">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="org.springframework" level="WARN"/>
<root level="info"/>
</elseif>
<else condition="property('myproject.profile').equals('local')">
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</else>

์œ„ ์ฒ˜๋Ÿผ ์„ค์ •ํ–ˆ๋Š”๋ฐ ์•ฑ ๊ธฐ๋™ ์‹œ ์•„๋ž˜์ฒ˜๋Ÿผ logback์—์„œ ์—๋Ÿฌ๋กœ๊ทธ๋ฅผ ์ฐ์—ˆ๋‹ค.


14:46:24,662 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]

14:46:24,668 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - This appender no longer admits a layout as a sub-component, set an encoder instead.

14:46:24,668 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - To ensure compatibility, wrapping your layout in LayoutWrappingEncoder.

14:46:24,668 |-WARN in ch.qos.logback.core.ConsoleAppender[STDOUT] - See also http://logback.qos.ch/codes.html#layoutInsteadOfEncoder for details

14:46:24,673 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - Could not find Janino library on the class path. Skipping conditional processing.

14:46:24,673 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - See also http://logback.qos.ch/codes.html#ifJanino

14:46:24,673 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@31:64 - no applicable action for [logger], current ElementPath  is [[configuration][if][logger]]

14:46:24,674 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@32:42 - no applicable action for [appender-ref], current ElementPath  is [[configuration][if][logger][appender-ref]]


์›์ธ์€ ๋ช…ํ™•ํ•ด๋ณด์˜€๋‹ค. Janino๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์—†์–ด์„œ์˜€๋‹ค.

<if>, <elseif> ๋“ฑ์˜ ํƒœ๊ทธ๋ฌธ๋ฒ•์„ Janino ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ํ•ด์„์„ ํ•ด์ฃผ๋Š”๋ฐ ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์—†์–ด์„œ logback ์„ค์ •ํŒŒ์ผํ•ด์„์„ ์ œ๋Œ€๋กœ ๋ชปํ•œ ์ƒํƒœ์˜€๋‹ค.

๊ทธ๋ž˜์„œ ํ˜„์žฌ์ผ์ž ๊ฐ€์žฅ ์ตœ์‹ ๋ฒ„์ „์œผ๋กœ ์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค.

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.0.14</version>
</dependency>


๊ทธ๋Ÿฐ๋ฐ ๋˜ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹ค ใ… ใ… 

 Failed to parse condition [property('myproject.profile').equals('live')] org.codehaus.commons.compiler.CompileException: Line 1, Column 45: Closing single quote missing

at org.codehaus.commons.compiler.CompileException: Line 1, Column 45: Closing single quote missing


์กฐ๊ฑด์œผ๋กœ ์ค€๊ฒŒ ํŒŒ์‹ฑ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ๋‹จ๋‹ค. ๊ทธ๋ž˜์„œ ์ปจ๋””์…˜์„ ์•„๋ž˜์ฒ˜๋Ÿผ ๋ฐ”๊พธ์—ˆ๋‹ค.

<if condition='property("myproject.profile").equals("local")'>

์Œ๋”ฐ์˜ดํ‘œ์™€ ํ™‘๋”ฐ์˜ดํ‘œ๋ฅผ ๋ฐ”๊พผ๊ฑฐ๋‹ค.

๊ทธ๋ฆฌ๊ณ  if-else if - else ๋ฅผ ํ•˜๊ธฐ์œ„ํ•ด์„  nested if๋ฅผ ์จ์•ผํ–ˆ๋‹ค.

ํ•˜์ง€๋งŒ nested <if> ๋ฅผ ์“ฐ๊ธฐ์—” ์•ˆ์ชฝ์œผ๋กœ ์ธ๋ดํŠธ ๋˜๋Š” ๊ฒŒ ๋งŽ์•„์ ธ์„œ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง„๋‹ค.

์–ด์ฐจํ”ผ ์กฐ๊ฑด์„ equals๋กœ ๋น„๊ตํ•˜๊ณ  ์žˆ์œผ๋‹ˆ 

๊ฒฐ๊ณผ์ ์œผ๋กœ if๋ฌธ๋งŒ ์จ์„œ profile๊ฐ’์„ ๋น„๊ตํ•ด์ฃผ์–ด๋„ if-elseif์˜ ํšจ๊ณผ๋Š” ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์•„๋ž˜์ฒ˜๋Ÿผ ๋ฐ”๊ฟจ๋‹ค.

<if condition='property("myproject.profile").equals("live")'>
<then>
<logger name="com.myproject" level="debug">
<appender-ref ref="ELASTIC"/>
</logger>
<logger name="org.springframework" level="WARN"/>
<root level="info"/>
</then>
</if>
<if condition='property("myproject.profile").equals("dev")'>
<then>
<logger name="com.myproject" level="debug">
<appender-ref ref="ELASTIC"/>
</logger>
<logger name="org.springframework" level="WARN"/>
<root level="info"/>
</then>
</if>
<if condition='property("myproject.profile").equals("local")'>
<then>
<logger name="com.myproject" level="debug">
<appender-ref ref="STDOUT"/>
</logger>
<root level="info">
<appender-ref ref="STDOUT"/>
</root>
</then>
</if>

์ด์ œ ์ž˜ ๋™์ž‘ํ•œ๋‹ค.