001package jmri.jmrit.ctc;
002
003import jmri.InstanceManager;
004
005/**
006 * @author Gregory J. Bedlek Copyright (C) 2018, 2019, 2020
007 * 
008 * The purpose of this class is to provide a single point of interface to the
009 * JMRI error logging system.
010 */
011@edu.umd.cs.findbugs.annotations.SuppressFBWarnings( value="SLF4J_FORMAT_SHOULD_BE_CONST",
012    justification="Logging Strings provided by calling classes.")
013public class CTCException extends Exception {
014
015    private final String _mModule;
016    private final String _mUserIdentifier;
017    private final String _mParameter;
018    private final String _mReason;
019    private static final CTCExceptionBuffer _ctcExceptionBuffer = InstanceManager.getDefault(CTCExceptionBuffer.class);
020
021    public CTCException(String module, String userIdentifier, String parameter, String reason) {
022        _mModule = module;
023        _mUserIdentifier = userIdentifier;
024        _mParameter = parameter;
025        _mReason = reason;
026    }
027
028    public String getExceptionString() {
029        return _mModule + ", " + _mUserIdentifier + _mParameter + ", " + _mReason;
030    }
031
032    public void logError() {
033        logError(getExceptionString());
034    }
035
036    public void logWarning() {
037        logWarning(getExceptionString());
038    }
039
040    static public void logError(String string) {
041        log.error(string);
042        _ctcExceptionBuffer.logString(CTCExceptionBuffer.ExceptionBufferRecordSeverity.ERROR, string);
043    }
044
045    static public void logWarning(String string) {
046        log.warn(string);
047        _ctcExceptionBuffer.logString(CTCExceptionBuffer.ExceptionBufferRecordSeverity.WARN, string);
048    }
049
050    static public void logInfo(String string) {
051        log.info(string);
052        _ctcExceptionBuffer.logString(CTCExceptionBuffer.ExceptionBufferRecordSeverity.INFO, string);
053    }
054
055    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(CTCException.class);
056
057}