검색결과 리스트
글
!markdown
# Java
## Logback 컬러링 기능
### 1. Pattern (패턴)
- `%highlight`를 이용하여 로그레벨별로 부각시킬 수 있다.
- `%black, %red, %green, %yellow, %blue, %magenta, %cyan, %white, %gray, %boldRed, %boldGreen, %boldYellow, %boldBlue, %boldMagenta, %boldCyan, %boldWhite`를 이용하여 특정구간의 색을 정할 수 있다.
- 컬러패턴 다음에는 `( )`, 즉 `sub-pattern을 이용하여 구간을 정한다.`
- `Windows`의 `cmd`에서는 작동하지 않습니다. 하지만, `jansi`라이브러리를 추가하면, `cmd`에서도 작동합니다.
### 2. Example (예제)
- logback.xml
```xml
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- On Windows machines setting withJansi to true enables ANSI
color code interpretation by the Jansi library. This requires
org.fusesource.jansi:jansi:1.8 on the class path. Note that
Unix-based operating systems such as Linux and Mac OS X
support ANSI color codes by default. -->
<withJansi>true</withJansi>
<encoder>
<pattern>[%thread] %highlight(%-5level) %cyan(%logger{15}) - %msg %n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
```
- Gradle (build.gradle)
```
compile 'org.fusesource.jansi:jansi:1.16'
```
### 3. 참조
- Logback - Coloring: [https://logback.qos.ch/manual/layouts.html#coloring](https://logback.qos.ch/manual/layouts.html#coloring)
'LANGUAGE > Java & Groovy ' 카테고리의 다른 글
[Java] Logback - 실행중에 Logger Level 변경 (0) | 2018.01.31 |
---|---|
[Java] Logback - 모든 로그는 Logger를 통하게 하라. (0) | 2017.11.11 |
[Java] 형형색색 색깔 출력 ( print ) (0) | 2017.11.11 |
[Groovy] JDK버전별 (0) | 2017.11.10 |
[Java] Extract TAR, JAR, ZIP (압축풀기) (0) | 2017.03.07 |