All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.libgraviton.workerbase.logging.TruncatedMessageConverter Maven / Gradle / Ivy

There is a newer version: 0.26.0
Show newest version
package com.github.libgraviton.workerbase.logging;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

import java.util.List;

/**
 * 

Allows to truncate the message size and add a postfix to mark the message visibly as truncated.

* * @author List of contributors {@literal } * @see http://swisscom.ch * @version $Id: $Id */ public class TruncatedMessageConverter extends ClassicConverter { @Override public String convert(ILoggingEvent event) { if(getOptions().size() != 2) { throw new IllegalArgumentException("Expected 2 arguments but got " + getOptionList().size() + "."); } int maxMessageLength = Integer.parseInt(getOptions().get(0)); String postfix = getOptions().get(1); String message = event.getFormattedMessage(); if (message.length() >= maxMessageLength) { message = message.substring(0, maxMessageLength) + " " + postfix; } return message; } /** * For some reason getOptionList() is protected. With getOptions() it's exposed and testable. */ public List getOptions() { return getOptionList(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy