LogCat рдореЗрдВ рдбреЗрдЯрд╛ рдЖрдЙрдЯрдкреБрдЯ рдХрд╛ рдкреНрд░рдХрд╛рд░ рдмрджрд▓реЗрдВ

рдорд╛рдирдХ рд▓рдХрдбрд╝рд╣рд╛рд░рд╛ рдкреВрд░реА рддрд░рд╣ рд╕реЗ рд╕реБрд╡рд┐рдзрд╛рдЬрдирдХ рдирд╣реАрдВ рд╣реИ, рдХрдо рд╕реЗ рдХрдо рдореЗрд░реЗ рд▓рд┐рдПред рдиреАрдЪреЗ рдЦреБрдж рдХреЗ рд▓рд┐рдП рдПрдХ рд▓рдХрдбрд╝рд╣рд╛рд░рд╛ рдХрд╛ рдПрдХ рдЙрджрд╛рд╣рд░рдг рд╣реИред рдореИрдВ рдЗрд╕реЗ рдбреЗрдврд╝ рд╕рд╛рд▓ рд╕реЗ рдЬреНрдпрд╛рджрд╛ рд╕рдордп рд╕реЗ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд░ рд░рд╣рд╛ рд╣реВрдВред рд╕реНрдерд╛рдиреАрдп рд╕реНрддрд░ рдкрд░ рдкрд╛рдИ рдЬрд╛рдиреЗ рд╡рд╛рд▓реА рд╕рдорд╕реНрдпрд╛рдУрдВ рдХреЛ рддреЗрдЬреА рд╕реЗ рджреЗрдЦрдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рджреЗрддрд╛ рд╣реИ, рд▓реЙрдЧрд┐рдВрдЧ рдХреА рд╕реБрд╡рд┐рдзрд╛ рджреЗрддрд╛ рд╣реИред рдЕрдкрдиреА рдЖрд╡рд╢реНрдпрдХрддрд╛рдУрдВ рдХреЗ рд▓рд┐рдП рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдХрд░рдирд╛ рдЖрд╕рд╛рди рд╣реИред рдЬрдм рдХрд╛рдо рдХрд░рддреЗ рд╣реИрдВ, рддреЛ рдЗрд╕реЗ рдирд┐рд░рдВрддрд░ рдЯреИрдЧрд┐рдВрдЧ рдпрд╛ рдЯреИрдЧ рдХреЛ рдПрдХ рдЕрд▓рдЧ рдХрдВрдЯреЗрдВрдЯ рдмрдирд╛рдиреЗ рдХреА рдЖрд╡рд╢реНрдпрдХрддрд╛ рдирд╣реАрдВ рд╣реЛрддреА рд╣реИ, рдХреНрдпреЛрдВрдХрд┐ рдПрдХ рд╕реНрд╡рд░реВрдкрд┐рдд рдЯреИрдЧ рд╕реНрд╡рдЪрд╛рд▓рд┐рдд рд░реВрдк рд╕реЗ рдЬрд╛рд░реА рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ

> рд╡рд░реНрдЧ: рдХрд╛рд░реНрдп: рдкрдВрдХреНрддрд┐ рд╕рдВрдЦреНрдпрд╛

рд╣рдо рдЗрд╕реЗ рдЗрд╕ рддрд░рд╣ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╣реИрдВ - Log.w("SUCCESS download")

> DownloadCharts: downloadSongs: 322: SUCCESS рдбрд╛рдЙрдирд▓реЛрдб

рдХрднреА-рдХрднреА рдпрд╣ рдкрддрд╛ рд▓рдЧрд╛рдирд╛ рдЖрд╡рд╢реНрдпрдХ рд╣реИ рдХрд┐ рди рдХреЗрд╡рд▓ рдПрдХ рд╡рд┐рд╢рд┐рд╖реНрдЯ рддреНрд░реБрдЯрд┐ рдХрд╛ рд╕реНрдерд╛рди рд╣реИ, рдмрд▓реНрдХрд┐ рдореВрд▓ рд╡рд░реНрдЧ рднреА рд╣реИред рддрдм рдорд╛рддрд╛-рдкрд┐рддрд╛ рдХреЗ Log.w(this, "") рд╕рд╛рде рдПрдХ рд▓рдХрдбрд╝рд╣рд╛рд░рд╛ рдмрдЪрд╛рд╡ рдореЗрдВ рдЖрддрд╛ рд╣реИ, рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП Log.w(this, "") рддреЛ рд╣рдо рд▓рд╛рдЗрди рдкреНрд░рд╛рдкреНрдд рдХрд░рддреЗ рд╣реИрдВ

> (рдкреИрд░реЗрдВрдЯ) рдХреНрд▓рд╛рд╕: рдлрдВрдХреНрд╢рди: рд▓рд╛рдЗрди рдирдВрдмрд░

> (ChartsLibrary) DownloadCharts: рдбрд╛рдЙрдирд▓реЛрдбрд╕рдВрдЧ: 322: рдЪреЗрддрд╛рд╡рдиреА

рд╣рд╛рд▓рд╛рдБрдХрд┐, рдЗрд╕реЗ рдПрдХ рдмрд╛рд░ рдЖрдЬрд╝рдорд╛рдирд╛ рдФрд░ рдкрд░рд┐рдгрд╛рдо рджреЗрдЦрдирд╛ рдЖрд╕рд╛рди рд╣реИред

рдмрд┐рд▓реНрд▓реА рдХреЗ рдиреАрдЪреЗ рдХреЛрдб рд╣реИред



 package ua.at.tsvetkov.util; import android.text.TextUtils; /** * Extended logger. * * @author A.Tsvetkov 2010 http://tsvetkov.at.ua mailto:al@ukr.net */ public final class Log { // ========================================================== private static final String POSFIX_STRING = ")"; private static final String PREFIX_STRING = "> ("; private static final String PREFIX_MAIN_STRING = " > "; /** * Send a VERBOSE log message. * * @param msg The message you would like logged. */ public static void v(String msg) { android.util.Log.v(getLocation(), msg); } /** * Send a DEBUG log message. * * @param msg The message you would like logged. */ public static void d(String msg) { android.util.Log.d(getLocation(), msg); } /** * Send a INFO log message. * * @param msg The message you would like logged. */ public static void i(String msg) { android.util.Log.i(getLocation(), msg); } /** * Send a WARN log message. * * @param msg The message you would like logged. */ public static void w(String msg) { android.util.Log.w(getLocation(), msg); } /** * Send a ERROR log message. * * @param msg The message you would like logged. */ public static void e(String msg) { android.util.Log.e(getLocation(), msg); } // ========================================================== /** * Send a VERBOSE log message and log the exception. * * @param msg The message you would like logged. * @param tr An exception to log */ public static void v(String msg, Exception e) { android.util.Log.v(getLocation(), msg, e); } /** * Send a DEBUG log message and log the exception. * * @param msg The message you would like logged. * @param tr An exception to log */ public static void d(String msg, Exception e) { android.util.Log.d(getLocation(), msg, e); } /** * Send a INFO log message and log the exception. * * @param msg The message you would like logged. * @param tr An exception to log */ public static void i(String msg, Exception e) { android.util.Log.i(getLocation(), msg, e); } /** * Send a WARN log message and log the exception. * * @param msg The message you would like logged. * @param tr An exception to log */ public static void w(String msg, Exception e) { android.util.Log.w(getLocation(), msg, e); } /** * Send a ERROR log message and log the exception. * * @param msg The message you would like logged. * @param tr An exception to log */ public static void e(String msg, Exception e) { android.util.Log.e(getLocation(), msg, e); } // ========================================================== /** * Send a VERBOSE log the exception. * * @param tr An exception to log */ public static void v(Exception e) { android.util.Log.v(getLocation(), "", e); } /** * Send a DEBUG log the exception. * * @param tr An exception to log */ public static void d(Exception e) { android.util.Log.d(getLocation(), "", e); } /** * Send a INFO log the exception. * * @param tr An exception to log */ public static void i(Exception e) { android.util.Log.i(getLocation(), "", e); } /** * Send a WARN log the exception. * * @param tr An exception to log */ public static void w(Exception e) { android.util.Log.w(getLocation(), "", e); } /** * Send a ERROR log the exception. * * @param tr An exception to log */ public static void e(Exception e) { android.util.Log.e(getLocation(), "", e); } // ========================================================== /** * Send a <b>VERBOSE</b> log message. Using when you extend any Class and wont to receive full info in LogCat tag. * Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumberClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. */ public static void v(Object obj, String msg) { android.util.Log.v(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg); } /** * Send a <b>DEBUG</b> log message. Using when you extend any Class and wont to receive full info in LogCat tag. * Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. */ public static void d(Object obj, String msg) { android.util.Log.d(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg); } /** * Send a <b>INFO</b> log message. Using when you extend any Class and wont to receive full info in LogCat tag. * Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. */ public static void i(Object obj, String msg) { android.util.Log.i(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg); } /** * Send a <b>WARN</b> log message. Using when you extend any Class and wont to receive full info in LogCat tag. * Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. */ public static void w(Object obj, String msg) { android.util.Log.w(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg); } /** * Send a <b>ERROR</b> log message. Using when you extend any Class and wont to receive full info in LogCat tag. * Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. */ public static void e(Object obj, String msg) { android.util.Log.e(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg); } // ========================================================== /** * Send a <b>VERBOSE</b> log message and log the exception. Using when you extend any Class and wont to receive full * info in LogCat tag. Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. * @param tr An exception to log */ public static void v(Object obj, String msg, Exception e) { android.util.Log.v(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg, e); } /** * Send a <b>DEBUG</b> log message and log the exception. Using when you extend any Class and wont to receive full * info in LogCat tag. Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. * @param tr An exception to log */ public static void d(Object obj, String msg, Exception e) { android.util.Log.d(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg, e); } /** * Send a <b>INFO</b> log message and log the exception. Using when you extend any Class and wont to receive full * info in LogCat tag. Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. * @param tr An exception to log */ public static void i(Object obj, String msg, Exception e) { android.util.Log.i(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg, e); } /** * Send a <b>WARN</b> log message and log the exception. Using when you extend any Class and wont to receive full * info in LogCat tag. Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param msg The message you would like logged. * @param tr An exception to log */ public static void w(Object obj, String msg, Exception e) { android.util.Log.w(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg, e); } /** * Send a <b>ERROR</b> log message and log the exception. Using when you extend any Class and wont to receive full * info in LogCat tag. Usually you can use "this" in "obj" parameter. As result you receive tag string * "<b>(Called Main Class) LogginClass:MethodInLogginClass:lineNumber</b>" * * @param obj main class * @param tr An exception to log * @param msg The message you would like logged. */ public static void e(Object obj, String msg, Exception e) { android.util.Log.e(PREFIX_STRING + obj.getClass().getSimpleName() + POSFIX_STRING + getLocation(), msg, e); } private static String getLocation() { final String className = Log.class.getName(); final StackTraceElement[] traces = Thread.currentThread().getStackTrace(); boolean found = false; for (int i = 0; i < traces.length; i++) { StackTraceElement trace = traces[i]; try { if (found) { if (!trace.getClassName().startsWith(className)) { Class<?> clazz = Class.forName(trace.getClassName()); return PREFIX_MAIN_STRING + getClassName(clazz) + ":" + trace.getMethodName() + ":" + trace.getLineNumber(); } } else if (trace.getClassName().startsWith(className)) { found = true; continue; } } catch (ClassNotFoundException e) { } } return "[]: "; } private static String getClassName(Class<?> clazz) { if (clazz != null) { if (!TextUtils.isEmpty(clazz.getSimpleName())) { return clazz.getSimpleName(); } return getClassName(clazz.getEnclosingClass()); } return ""; } } 

Source: https://habr.com/ru/post/In134169/


All Articles