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
023 * ERROR, in red for WARN, in BLUE for INFO, and in the default color for other
024 * levels.
025 */
026public class HighlightingCompositeConverter extends ForegroundCompositeConverterBase<ILoggingEvent> {
027
028    @Override
029    protected String getForegroundColorCode(ILoggingEvent event) {
030        Level level = event.getLevel();
031        switch (level.toInt()) {
032        case Level.ERROR_INT:
033            return BOLD + RED_FG;
034        case Level.WARN_INT:
035            return RED_FG;
036        case Level.INFO_INT:
037            return BLUE_FG;
038        default:
039            return DEFAULT_FG;
040        }
041
042    }
043}