001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.pattern.color;
015
016import ch.qos.logback.classic.Level;
017import ch.qos.logback.classic.spi.ILoggingEvent;
018import static ch.qos.logback.core.pattern.color.ANSIConstants.*;
019import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase;
020
021/**
022 * Highlights inner-text depending on the level, in bold red for events of level ERROR, in red for WARN,
023 * in BLUE for INFO, and in the default color for other levels.
024 */
025public class HighlightingCompositeConverter extends ForegroundCompositeConverterBase<ILoggingEvent> {
026
027    @Override
028    protected String getForegroundColorCode(ILoggingEvent event) {
029        Level level = event.getLevel();
030        switch (level.toInt()) {
031        case Level.ERROR_INT:
032            return BOLD + RED_FG;
033        case Level.WARN_INT:
034            return RED_FG;
035        case Level.INFO_INT:
036            return BLUE_FG;
037        default:
038            return DEFAULT_FG;
039        }
040
041    }
042}