Created
June 29, 2020 14:47
-
-
Save vprusa/70866e4df35b19107dafdd788311a93d to your computer and use it in GitHub Desktop.
Custom multidimensional logger sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Custom multidimensional logger sketch (WildFly compatible?) | |
* | |
* TODO checkout | |
* - https://github.com/jamezp/wildfly-examples/tree/master/custom-log-filter | |
*/ | |
public final class Log { | |
// TODO load from env variable, config file, option -D | |
public static Class[] enabledLogTypes = { | |
LoggerType1.class, | |
// LoggerType2.class, | |
LoggerType3.class | |
}; | |
public static class LoggerType {} | |
public static class LoggerType1 extends LoggerType {} | |
public static class LoggerType2 extends LoggerType {} | |
public static class LoggerType3 extends LoggerType {} | |
public static final Logger logger = Logger.getLogger(Log.class.getSimpleName()); | |
public static void info(Object s) { | |
logger.info(s); | |
} | |
public static void info(Class c, Object s) { | |
logger.info(c.getSimpleName() + ": " + s.toString()); | |
} | |
public static void infoCreate(Class c, Object s) { | |
info(c, " created: " + s.toString()); | |
} | |
public static void infoRemove(Class c, Object s) { | |
info(c, " removed: " + s.toString()); | |
} | |
public static void infoUpdate(Class c, Object s) { | |
info(c, " updated: " + s.toString()); | |
} | |
public static void infoDelete(Class c, Object s) { | |
info(c, " deleted: " + s.toString()); | |
} | |
public static class TypedLogger<T extends LoggerType> { | |
public final Class t; | |
public static final Logger logger = Logger.getLogger(Log.class.getSimpleName()); | |
public TypedLogger(Class t) { | |
this.t = t; | |
} | |
public void info(Object o) { | |
if (Arrays.asList(Log.enabledLogTypes).contains(t)){ | |
Log.info(o); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: