/*
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira.junit
 */
package net.ranides.assira.junit;

/**
 * Entry used by {@link LogObserver} to store all observed messages.
 * Please note that storing all log messages in memory is extremally inefficent both for performance and memory usage.
 * We should use it inside unit tests, when we expect some log message and there is no other way to detect that expected
 * action happened.
 *
 * @author Ranides Atterwim {@literal <ranides@gmail.com>}
 */
public class LogMessage {
    
    private final int level;
            
    private final String text;
    
    private final Throwable error;

    LogMessage(int level, String text, Throwable error) {
        this.level = level;
        this.text = (error==null) ? text : text + " @ " + error;
        this.error = error;
    }

    /**
     * Text of message
     * @return string
     */
    public String text() {
        return text;
    }

    /**
     * Level of messsage.
     * Levels are defined inside {@link org.slf4j.spi.LocationAwareLogger}
     *
     * @return int
     */
    public int level() {
        return level;
    }

    /**
     * Exception connected with the message.
     * slf4j optionally allows to assign to specific message correlated exception.
     *
     * @return exception or null
     */
    public Throwable error() {
        return error;
    }

    @Override
    public String toString() {
        return text;
    }
    
}
