001package org.intellimate.izou.sdk.util; 002 003import org.apache.logging.log4j.Level; 004import org.apache.logging.log4j.spi.AbstractLogger; 005 006/** 007 * This interface has various utility-methods for Logging 008 * @author Leander Kurscheidt 009 * @version 1.0 010 */ 011public interface Loggable extends ContextProvider { 012 String FQCN = Loggable.class.getName(); 013 /** 014 * Used to log messages at debug level 015 * @param msg the message 016 * @param e the Throwable 017 */ 018 default void debug(String msg, Throwable e) { 019 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 020 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, e); 021 } 022 023 /** 024 * Used to log messages at debug level 025 * @param msg the message 026 */ 027 default void debug(String msg) { 028 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 029 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, (Object) null); 030 } 031 032 /** 033 * Used to log messages at error level 034 * @param msg the message 035 * @param e the Throwable 036 */ 037 default void error(String msg, Throwable e) { 038 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 039 logger.logIfEnabled(FQCN, Level.ERROR, null, msg, e); 040 } 041 042 /** 043 * Used to log messages at error level 044 * @param msg the message 045 */ 046 default void error(String msg) { 047 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 048 logger.logIfEnabled(FQCN, Level.ERROR, null, msg, (Object) null); 049 } 050 051 /** 052 * Used to log messages at fatal level 053 * @param msg the message 054 * @param e the Throwable 055 */ 056 default void fatal(String msg, Throwable e) { 057 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 058 logger.logIfEnabled(FQCN, Level.FATAL, null, msg, e); 059 } 060 061 /** 062 * Used to log messages at fatal level 063 * @param msg the message 064 */ 065 default void fatal(String msg) { 066 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 067 logger.logIfEnabled(FQCN, Level.FATAL, null, msg, (Object) null); 068 } 069 070 /** 071 * Used to log messages at warn level 072 * @param msg the message 073 * @param e the Throwable 074 */ 075 default void warn(String msg, Throwable e) { 076 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 077 logger.logIfEnabled(FQCN, Level.WARN, null, msg, e); 078 } 079 080 /** 081 * Used to log messages at warn level 082 * @param msg the message 083 */ 084 default void warn(String msg) { 085 AbstractLogger logger = (AbstractLogger) getContext().getLogger(); 086 logger.logIfEnabled(FQCN, Level.WARN, null, msg, (Object) null); 087 } 088}