| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package com.yalantis.phoenix.util;
- import android.text.TextUtils;
- public final class Logger {
- private static final String TAG = "Phoenix";
- /**
- * Set true or false if you want read logs or not
- */
- private static boolean logEnabled_d = false;
- private static boolean logEnabled_i = false;
- private static boolean logEnabled_e = false;
- public static void d() {
- if (logEnabled_d) {
- android.util.Log.v(TAG, getLocation());
- }
- }
- public static void d(String msg) {
- if (logEnabled_d) {
- android.util.Log.v(TAG, getLocation() + msg);
- }
- }
- public static void i(String msg) {
- if (logEnabled_i) {
- android.util.Log.i(TAG, getLocation() + msg);
- }
- }
- public static void i() {
- if (logEnabled_i) {
- android.util.Log.i(TAG, getLocation());
- }
- }
- public static void e(String msg) {
- if (logEnabled_e) {
- android.util.Log.e(TAG, getLocation() + msg);
- }
- }
- public static void e(String msg, Throwable e) {
- if (logEnabled_e) {
- android.util.Log.e(TAG, getLocation() + msg, e);
- }
- }
- public static void e(Throwable e) {
- if (logEnabled_e) {
- android.util.Log.e(TAG, getLocation(), e);
- }
- }
- public static void e() {
- if (logEnabled_e) {
- android.util.Log.e(TAG, getLocation());
- }
- }
- private static String getLocation() {
- final String className = Logger.class.getName();
- final StackTraceElement[] traces = Thread.currentThread()
- .getStackTrace();
- boolean found = false;
- for (StackTraceElement trace : traces) {
- try {
- if (found) {
- if (!trace.getClassName().startsWith(className)) {
- Class<?> clazz = Class.forName(trace.getClassName());
- return "[" + getClassName(clazz) + ":"
- + trace.getMethodName() + ":"
- + trace.getLineNumber() + "]: ";
- }
- } else if (trace.getClassName().startsWith(className)) {
- found = true;
- }
- } catch (ClassNotFoundException ignored) {
- }
- }
- return "[]: ";
- }
- private static String getClassName(Class<?> clazz) {
- if (clazz != null) {
- if (!TextUtils.isEmpty(clazz.getSimpleName())) {
- return clazz.getSimpleName();
- }
- return getClassName(clazz.getEnclosingClass());
- }
- return "";
- }
- }
|