Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.util.Log;

public class Main {
    private static final String TAG = "LOGUTIL";
    private static boolean LOG_ENABLE = true;

    /**
     * info log
     * @param msg log msg
     */
    public static void i(String msg) {
        if (LOG_ENABLE) {
            Log.i(TAG, buildMsg(msg));
        }
    }

    /**
     * info log
     * @param tag tag
     * @param msg log msg
     */
    public static void i(String tag, String msg) {
        if (LOG_ENABLE) {
            Log.i(tag, buildMsg(msg));
        }
    }

    private static String buildMsg(String msg) {
        StringBuilder buffer = new StringBuilder();

        //        if (DETAIL_ENABLE) {
        //            final StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
        //
        //            buffer.append("[ ");
        //            buffer.append(Thread.currentThread().getName());
        //            buffer.append(": ");
        //            buffer.append(stackTraceElement.getFileName());
        //            buffer.append(": ");
        //            buffer.append(stackTraceElement.getLineNumber());
        //            buffer.append(": ");
        //            buffer.append(stackTraceElement.getMethodName());
        //        }

        //        buffer.append("() ] _____ ");

        buffer.append(msg);

        return buffer.toString();
    }
}