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

sirius.kernel.health.Incident Maven / Gradle / Ivy

Go to download

Provides common core classes and the microkernel powering all Sirius applications

There is a newer version: 12.9.1
Show newest version
/*
 * Made with all the love in the world
 * by scireum in Remshalden, Germany
 *
 * Copyright by scireum GmbH
 * http://www.scireum.de - [email protected]
 */

package sirius.kernel.health;

import sirius.kernel.commons.Tuple;
import sirius.kernel.nls.NLS;

import java.time.Instant;
import java.util.List;

/**
 * Describes a handled exception generated by {@link Exceptions} and passed on to {@link ExceptionHandler}.
 */
public class Incident {
    private String category;
    private String location;
    private long timestamp;
    private List> mdc;
    private HandledException exception;

    protected Incident(String category, String location, List> mdc, HandledException exception) {
        this.timestamp = System.currentTimeMillis();
        this.category = category;
        this.location = location;
        this.mdc = mdc;
        this.exception = exception;
    }

    /**
     * Returns the category (logger name) which was used to log the exception.
     *
     * @return the category of the incident
     */
    public String getCategory() {
        return category;
    }

    /**
     * Returns an unique string describing the location where the incident occurred.
     *
     * @return a unique string description of the location where the error happened
     */
    public String getLocation() {
        return location;
    }

    /**
     * Returns the mapped diagnostic context describing the exact situation of the error.
     *
     * @return the mapped diagnostic context.
     */
    public List> getMDC() {
        return mdc;
    }

    /**
     * Returns the underlying exception.
     *
     * @return the exception describing the error.
     */
    public HandledException getException() {
        return exception;
    }

    /**
     * Returns the timestamp when this incident was created as string.
     *
     * @return the timestamp when this incident was created, formatted as string
     */
    public String getTimestampAsString() {
        return NLS.toUserString(Instant.ofEpochMilli(timestamp));
    }

    /**
     * Returns the timestamp when this incident was created.
     *
     * @return the timestamp when this incident0 was created
     */
    public long getTimestamp() {
        return timestamp;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy