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

io.sealights.agents.plugin.upgrade.utils.UserMessageHelper Maven / Gradle / Ivy

package io.sealights.agents.plugin.upgrade.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Created by shahar on 8/2/2016.
 */
public class UserMessageHelper {

    private String preFix = null;
    private boolean debugMode = false;

    public UserMessageHelper(String preFix) {
        this(preFix, false);
    }

    public UserMessageHelper(String preFix, boolean debugMode) {
        this.preFix = preFix;
        this.debugMode = debugMode;
    }

    public void println(String text){
        System.out.println(preFix + " - " + text);
    }

    public void printWarn(String text) {
        println("WARN - " + text);
    }

    public void printError(String text){
        System.err.println(preFix + " - " + text);
    }

    public void printError(String text, Throwable throwable){
        String exception = toString(throwable);
        String message = text + " " + exception;
        this.printError(message);
    }

    private String toString(Throwable throwable)
    {
        StringWriter sw = new StringWriter();
        throwable.printStackTrace(new PrintWriter(sw));

        String message = sw.toString();
        return message;
    }

    public void printDebug(String text){
        if (debugMode)
            println("DEBUG - " + text);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy