package com.assimilate.alltrans.common;

import android.text.TextUtils;
import android.util.Log;

import com.assimilate.alltrans.BuildConfig;

public class Logger {
    private final static boolean ENABLE_LOGGER = !"release".equalsIgnoreCase(BuildConfig.BUILD_TYPE);

    public final static String COMMAND_INTERSTITIAL_AD = "google_interstitial_ad";
    public final static String COMMAND_NATIVE_AD = "google_native_ad";

    public static void i(final String tag, final String message) {
        if (ENABLE_LOGGER) {
            Log.i(getTag(tag), getMessage(message));
        }
    }

    public static void d(final String tag, final String message) {
        if (ENABLE_LOGGER) {
            Log.d(getTag(tag), getMessage(message));
        }
    }

    public static void w(final String tag, final String message) {
        if (ENABLE_LOGGER) {
            Log.w(getTag(tag), getMessage(message));
        }
    }

    public static void e(final String tag, final String message) {
        if (ENABLE_LOGGER) {
            Log.e(getTag(tag), getMessage(message));
        }
    }

    private static String getTag(String tag) {
        if (TextUtils.isEmpty(tag)) {
            return "TAG";
        }
        if (tag.length() > 23) {
            final int index2 = tag.length()-10;
            tag = tag.substring(0, 10) + "..." + tag.substring(index2);
        }
        return tag;
    }

    private static String getMessage(String msg) {
        if (TextUtils.isEmpty(msg)) {
            return "null";
        }
        return msg;
    }
}
