Example usage for android.util Log println

List of usage examples for android.util Log println

Introduction

In this page you can find the example usage for android.util Log println.

Prototype

public static int println(int priority, String tag, String msg) 

Source Link

Document

Low-level logging call.

Usage

From source file:de.madvertise.android.sdk.MadUtil.java

/**
 * Simple logging helper to prevent producing duplicate code blocks.
 * //from  w ww  . j a  v a  2s . co  m
 * Log-Message is only printed to LogCat if logging is enabled in MadUtils
 * and message is logable with specified tag and level. 
 *  
 * @param tag
 *     use a given tag for logging or use default tag if nil. Default tag can be defined in MadUtil class.
 * @param level
 *     log level from {@link android.util.Log}
 * @param message
 * @see 
 *     android.util.Log
 */
protected static void logMessage(String tag, int level, String message) {
    if (!PRINT_LOG) {
        if (!Log.isLoggable(tag, level))
            return;
    }
    if (tag == null)
        tag = MadUtil.LOG;
    Log.println(level, tag, message);
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

/**
 * When a request fails with a 401 Unauthorized you can call this with the content
 * of the WWW-Authenticate header in the response and it will modify the URI so that
 * if you repeat the request the correct authentication should be used.
 *
 * If you then get a 401, and this gets called again on that same Uri, it will throw
 * an AuthenticationFailure exception rather than continue futilely.
 *
 * @param authRequestHeader/* ww  w.  j a  va  2s . com*/
 * @throws AuthenticationFailure
 */
public void interpretRequestedAuth(Header authRequestHeader) throws AuthenticationFailure {
    // Adjust our authentication setup so the next request will be able
    // to send the correct authentication headers...

    // WWW-Authenticate: Digest realm="DAViCal CalDAV Server", qop="auth", nonce="55a1a0c53c0f337e4675befabeff6a122b5b78de", opaque="52295deb26cc99c2dcc6614e70ed471f7a163e7a", algorithm="MD5"
    // WWW-Authenticate: Digest realm="SabreDAV",qop="auth",nonce="4f08e719a85d0",opaque="df58bdff8cf60599c939187d0b5c54de"
    // WWW-Authenticate:digest nonce="130183646896936966342199963268042751958404602087869166446", realm="Test Realm", algorithm="md5"

    if (debugThisRequest)
        Log.println(Constants.LOGV, TAG, "Interpreting '" + authRequestHeader + "'");

    String name;
    for (HeaderElement he : authRequestHeader.getElements()) {
        if (debugThisRequest)
            Log.println(Constants.LOGV, TAG, "Interpreting Element: '" + he.toString() + "' (" + he.getName()
                    + ":" + he.getValue() + ")");
        name = he.getName();

        if (name.length() > 7 && name.substring(0, 7).equalsIgnoreCase("Digest ")) {
            authType = Servers.AUTH_DIGEST;
            qop = null;
            algorithm = "md5";
            name = name.substring(7);
            if (debugThisRequest)
                Log.println(Constants.LOGV, TAG,
                        "Found '" + getAuthTypeName(authType) + "' auth, realm: " + authRealm);
        } else if (name.length() > 6 && name.substring(0, 6).equalsIgnoreCase("Basic ")) {
            authType = Servers.AUTH_BASIC;
            name = name.substring(6);
        }

        if (name.equalsIgnoreCase("realm")) {
            authRealm = he.getValue();
        } else if (name.equalsIgnoreCase("nonce")) {
            nonce = he.getValue();
        } else if (name.equalsIgnoreCase("opaque")) {
            opaque = he.getValue();
        } else if (name.equalsIgnoreCase("qop")) {
            qop = "auth";
            if (!he.getValue().equalsIgnoreCase("auth")) {
                // Really we should split it out to see whether 'auth' is one of their options.
                Log.w(TAG, "Digest Auth requested qop of '" + he.getValue() + "' but we only support 'auth'");
            }
        } else if (name.equalsIgnoreCase("algorithm")) {
            if (!he.getValue().equalsIgnoreCase(algorithm)) {
                Log.w(TAG, "Digest Auth requested algorithm of '" + he.getValue() + "' but we only support '"
                        + algorithm + "'");
            }
        } else {
            Log.w(TAG, "Digest parameter of '" + name + "=\"" + he.getValue() + "\"' is being ignored.");
        }
    }

    authRequired = true;
}

From source file:com.luseen.luseenbottomnavigation.BottomNavigation.behavior.BottomNavigationBehavior.java

public static void log(final String tag, final int level, String message, Object... arguments) {
    if (BottomNavigationView.DEBUG) {
        Log.println(level, tag, String.format(message, arguments));
    }//w ww  .  j  ava  2s.c o  m
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

private String md5(String in) {
    // Create MD5 Hash
    MessageDigest digest;/*from   ww w.  j a  v a2 s .  c  om*/
    try {
        digest = java.security.MessageDigest.getInstance("MD5");
        digest.update(in.getBytes());
        return StaticHelpers.toHexString(digest.digest());
    } catch (NoSuchAlgorithmException e) {
        Log.e(TAG, e.getMessage());
        Log.println(Constants.LOGV, TAG, Log.getStackTraceString(e));
    }
    return "";
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

private Header basicAuthHeader() {
    String authValue = String.format("Basic %s", Base64Coder.encodeString(username + ":" + password));
    if (Constants.LOG_VERBOSE)
        Log.println(Constants.LOGV, TAG, "BasicAuthDebugging: '" + authValue + "'");
    return new BasicHeader("Authorization", authValue);
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

private Header digestAuthHeader() {
    String authValue;/*from   w ww  .  j  a  v  a2  s . co m*/
    String A1 = md5(username + ":" + authRealm + ":" + password);
    String A2 = md5(method + ":" + path);
    cnonce = md5(AcalConnectionPool.getUserAgent());
    String printNC = String.format("%08x", ++authNC);
    String responseString = A1 + ":" + nonce + ":" + printNC + ":" + cnonce + ":auth:" + A2;
    if (debugThisRequest)
        Log.println(Constants.LOGV, TAG, "DigestDebugging: '" + responseString + "'");
    String response = md5(responseString);
    authValue = String.format(
            "Digest realm=\"%s\", username=\"%s\", nonce=\"%s\", uri=\"%s\""
                    + ", response=\"%s\", algorithm=\"%s\", cnonce=\"%s\", opaque=\"%s\", nc=\"%s\""
                    + (qop == null ? "" : ", qop=\"auth\""),
            authRealm, username, nonce, path, response, algorithm, cnonce, opaque, printNC);
    return new BasicHeader("Authorization", authValue);
}

From source file:com.google.android.car.kitchensink.radio.RadioTestFragment.java

private void addLog(int priority, String message) {
    Log.println(priority, TAG, message);
    synchronized (this) {
        mLogMessages.add(message);// w  ww .  j a  v  a 2s.  co  m
        if (mLogMessages.size() > MAX_LOG_MESSAGES) {
            mLogMessages.poll();
        }
        mLog.setText(TextUtils.join("\n", mLogMessages));
    }
}

From source file:de.madvertise.android.sdk.MadvertiseUtil.java

static void logMessage(final String tag, final int level, String message, Throwable throwable,
        StackTraceElement stackTraceElement) {
    String logTag = tag;//w w  w .ja  v a 2 s .  c om
    if (!PRINT_LOG) {
        return;
    }

    if (tag == null) {
        logTag = MadvertiseUtil.LOG;
    }

    if (message == null) {
        message = "";
    }

    String fullClassName = stackTraceElement.getClassName();
    String className = fullClassName.substring(fullClassName.lastIndexOf(".") + 1);
    int lineNumber = stackTraceElement.getLineNumber();

    String logMessage = "(" + className + ":" + lineNumber + ") : " + message;
    if (throwable != null) {
        logMessage += '\n' + Log.getStackTraceString(throwable);
    }
    Log.println(level, logTag, logMessage);
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

private String getLocationHeader() {
    for (Header h : responseHeaders) {
        if (debugThisRequest)
            Log.println(Constants.LOGV, TAG,
                    "Looking for redirect in Header: " + h.getName() + ":" + h.getValue());
        if (h.getName().equalsIgnoreCase("Location"))
            return h.getValue();
    }//from  www.j  a  v  a 2s  .c om
    return "";
}