Skip to content

Instantly share code, notes, and snippets.

@gustinmi
Created October 12, 2022 06:56
Show Gist options
  • Save gustinmi/66fe2c883b4b78a3db567775a49b436c to your computer and use it in GitHub Desktop.
Save gustinmi/66fe2c883b4b78a3db567775a49b436c to your computer and use it in GitHub Desktop.
package com.ellypos.rmq;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Log mock. Provides same method signatures as android logger or at least minimal replacement
* @author mgustin
*
*/
public class Log {
/** Gets the logger for caller class via stack trace
* @return
*/
private static Logger getLoggerForThisClass() {
StackTraceElement myCaller = Thread.currentThread().getStackTrace()[3];
return Logger.getLogger(myCaller.getClassName());
}
/**
* Android compatibility method
* @param tag
* @param msg
*/
public static void d(String tag, String msg) {
Logger l = getLoggerForThisClass();
l.log(Level.INFO, String.format("[%s], tag: %s, %s", l.getName(), tag, msg));
}
/**
* Addition, it logs stach traces
* @param tag
* @param msg
* @param ex
*/
public static void e(String tag, String msg, Exception ex) {
Logger l = getLoggerForThisClass();
l.log(Level.SEVERE, String.format("[%s], tag: %s, ERROR: %s", l.getName(), tag, msg), ex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment