上代码
public class MyLogUtils {
public static boolean isDebug = true;
private static final String TAG = "MyLogUtils-";
private static OnLogWriteListener onLogWriteListener;
public static void setOnClickListener(OnLogWriteListener l) {
onLogWriteListener = l;
}
public interface OnLogWriteListener {
void onLogWrite(String log);
}
public static void i(String tag, String msg) {
if (isDebug) {
if (onLogWriteListener != null)
onLogWriteListener.onLogWrite(msg);
if (msg.length() > 3500) {
for (int i = 0; i < msg.length(); i += 3500) {
if (i + 3500 < msg.length()) {
Log.i(TAG + tag + i, msg.substring(i, i + 3500));
} else {
Log.i(TAG + tag + i, msg.substring(i, msg.length()));
}
}
} else {
Log.i(TAG + tag, msg);
}
}
}
public static void i(Object object, String msg) {
if (isDebug) {
if (onLogWriteListener != null)
onLogWriteListener.onLogWrite(msg);
if (msg.length() > 3500) {
for (int i = 0; i < msg.length(); i += 3500) {
if (i + 3500 < msg.length()) {
Log.i(object.getClass().getSimpleName() + i, msg.substring(i, i + 3500));
} else {
Log.i(object.getClass().getSimpleName(), msg.substring(i, msg.length()));
}
}
} else {
Log.i(object.getClass().getSimpleName(), msg);
}
}
}
public static void e(String tag, String msg) {
if (isDebug) {
if (onLogWriteListener != null)
onLogWriteListener.onLogWrite(msg);
if (msg.length() > 3500) {
for (int i = 0; i < msg.length(); i += 3500) {
if (i + 3500 < msg.length()) {
Log.e(TAG + tag + i, msg.substring(i, i + 3500));
} else {
Log.e(TAG + tag, msg.substring(i, msg.length()));
}
}
} else {
Log.e(TAG + tag, msg);
}
}
}
public static void e(Object object, String msg) {
if (isDebug) {
if (onLogWriteListener != null)
onLogWriteListener.onLogWrite(msg);
if (msg.length() > 3500) {
for (int i = 0; i < msg.length(); i += 3500) {
if (i + 3500 < msg.length()) {
Log.e(object.getClass().getSimpleName() + i, msg.substring(i, i + 3500));
} else {
Log.e(object.getClass().getSimpleName(), msg.substring(i, msg.length()));
}
}
} else {
Log.e(object.getClass().getSimpleName(), msg);
}
}
}
public static void w(String tag, String msg) {
if (isDebug) {
if (onLogWriteListener != null)
onLogWriteListener.onLogWrite(msg);
if (msg.length() > 3500) {
for (int i = 0; i < msg.length(); i += 3500) {
if (i + 3500 < msg.length()) {
Log.w(TAG + tag + i, msg.substring(i, i + 3500));
} else {
Log.w(TAG + tag, msg.substring(i, msg.length()));
}
}
} else {
Log.w(TAG + tag, msg);
}
}
}
}