Java Code Examples for android.util.Log.println()

The following are Jave code examples for showing how to use println() of the android.util.Log class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Instincts-2k17   File: LogHelper.java   View Source Code Vote up 6 votes
public static void log(String tag, int level, Throwable t, Object... messages) {
    if (Log.isLoggable(tag, level)) {
        String message;
        if (t == null && messages != null && messages.length == 1) {
            // handle this common case without the extra cost of creating a stringbuffer:
            message = messages[0].toString();
        } else {
            StringBuilder sb = new StringBuilder();
            if (messages != null) for (Object m : messages) {
                sb.append(m);
            }
            if (t != null) {
                sb.append("\n").append(Log.getStackTraceString(t));
            }
            message = sb.toString();
        }
        Log.println(level, tag, message);
    }
}
 
Example 2
Project: bluetooth-chat-appliction   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 3
Project: tubik   File: LogWrapper.java   View Source Code Vote up 6 votes
/**
 * Prints data out to the console using Android's native log mechanism.
 * @param priority Log level of the data being logged.  Verbose, Error, etc.
 * @param tag Tag for for the log data.  Can be used to organize log statements.
 * @param msg The actual message to be logged. The actual message to be logged.
 * @param tr If an exception was thrown, this can be sent along for the logging facilities
 *           to extract and print useful information.
 */
@Override
public void println(int priority, String tag, String msg, Throwable tr) {
    // There actually are log methods that don't take a msg parameter.  For now,
    // if that's the case, just convert null to the empty string and move on.
    String useMsg = msg;
    if (useMsg == null) {
        useMsg = "";
    }

    // If an exeption was provided, convert that exception to a usable string and attach
    // it to the end of the msg method.
    if (tr != null) {
        msg += "\n" + Log.getStackTraceString(tr);
    }

    // This is functionally identical to Log.x(tag, useMsg);
    // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg)
    Log.println(priority, tag, useMsg);

    // If this isn't the last node in the chain, move things along.
    if (mNext != null) {
        mNext.println(priority, tag, msg, tr);
    }
}
 
Example 4
Project: FBEventSync   File: Logger.java   View Source Code Vote up 6 votes
private void doLog(LogLevel level, String tag, String msg, Object ... args) {
    String formattedMsg = String.format(msg, args);
    String logMsg = String.format("%s %s/%s: %s\n", mDateFormat.format(new Date()), level.toString(),
                                  tag, formattedMsg);
    if (mLogWriter != null) {
        synchronized (mLogWriter) {
            try {
                mLogWriter.write(logMsg);
                mLogWriter.flush();
            } catch (IOException e) {
                Log.e(TAG, "Log IOException: " + e.getMessage());
            }
        }

        if (mLogFile.length() >= MAX_LOG_SIZE) {
            truncateLogs();
        }
    }

    if (level.toInt() >= mMinLogCatLvl.toInt()) {
        Log.println(level.toInt(), tag, formattedMsg);
    }
}
 
Example 5
Project: OKEventBus   File: AndroidLogger.java   View Source Code Vote up 5 votes
@Override
public void log(Level level, String msg, Throwable th) {
    if (level != Level.OFF) {
        // That's how Log does it internally
        Log.println(mapLevel(level), tag, msg + "\n" + Log.getStackTraceString(th));
    }
}
 
Example 6
Project: StatusStories   File: LoggingListener.java   View Source Code Vote up 5 votes
@Override
public boolean onResourceReady(B resource, A model, Target<B> target, boolean isFromMemoryCache,
                               boolean isFirstResource) {
    String resourceString = strip(getResourceDescription(resource));
    String targetString = strip(getTargetDescription(target));
    Log.println(level, "GLIDE", String.format(Locale.ROOT,
            "%s.onResourceReady(%s, %s, %s, %s, %s)",
            name, resourceString, model, targetString, isMem(isFromMemoryCache), isFirst(isFirstResource)));
    return delegate.onResourceReady(resource, model, target, isFromMemoryCache, isFirstResource);
}
 
Example 7
Project: ALog   File: ALog.java   View Source Code Vote up 5 votes
private static void printHead(final int type, final String tag, final String[] head) {
    if (head != null) {
        for (String aHead : head) {
            Log.println(type, tag, sLogBorderSwitch ? LEFT_BORDER + aHead : aHead);
        }
        if (sLogBorderSwitch) Log.println(type, tag, MIDDLE_BORDER);
    }
}
 
Example 8
Project: weex-uikit   File: WXLogUtils.java   View Source Code Vote up 5 votes
private static void log(String tag, String msg, LogLevel level){
  if (WXEnvironment.isApkDebugable() && msg != null && WXEnvironment.sLogLevel.compare(level) >= 0) {
    msg = getLineNumber() + msg;
    Log.println(level.getPriority(),tag, msg);
    writeConsoleLog(level.getName(), msg);
    sendLog(level, msg);
  }
}
 
Example 9
Project: GitHub   File: AndroidPlatform.java   View Source Code Vote up 5 votes
@Override public void log(int level, String message, Throwable t) {
  int logLevel = level == WARN ? Log.WARN : Log.DEBUG;
  if (t != null) message = message + '\n' + Log.getStackTraceString(t);

  // Split by line, then ensure each line can fit into Log's maximum length.
  for (int i = 0, length = message.length(); i < length; i++) {
    int newline = message.indexOf('\n', i);
    newline = newline != -1 ? newline : length;
    do {
      int end = Math.min(newline, i + MAX_LOG_LENGTH);
      Log.println(logLevel, "OkHttp", message.substring(i, end));
      i = end;
    } while (i < newline);
  }
}
 
Example 10
Project: letv   File: ib.java   View Source Code Vote up 5 votes
private static void d(int i, String str, String str2) {
    if (!d) {
        str = "FlurryAgent";
    }
    int length = TextUtils.isEmpty(str2) ? 0 : str2.length();
    int i2 = 0;
    while (i2 < length) {
        int i3 = a > length - i2 ? length : a + i2;
        if (Log.println(i, str, str2.substring(i2, i3)) > 0) {
            i2 = i3;
        } else {
            return;
        }
    }
}
 
Example 11
Project: NeiHanDuanZiTV   File: LogcatLogStrategy.java   View Source Code Vote up 4 votes
@Override
public void log(int priority, String tag, String message) {
  Log.println(priority, tag, message);
}
 
Example 12
Project: OKEventBus   File: AndroidLogger.java   View Source Code Vote up 4 votes
@Override
public void log(Level level, String msg) {
    if (level != Level.OFF) {
        Log.println(mapLevel(level), tag, msg);
    }
}
 
Example 13
Project: ALog   File: ALog.java   View Source Code Vote up 4 votes
private static void printBorder(final int type, final String tag, boolean isTop) {
    if (sLogBorderSwitch) {
        Log.println(type, tag, isTop ? TOP_BORDER : BOTTOM_BORDER);
    }
}
 
Example 14
Project: HeadlineNews   File: LogUtils.java   View Source Code Vote up 4 votes
private static void print(final int type, final String tag, final String msg) {
    Log.println(type, tag, msg);
}
 
Example 15
Project: SlotNSlot_Android   File: AndroidHttpClient.java   View Source Code Vote up 4 votes
/**
 * Prints a message using this configuration.
 */
private void println(String message) {
    Log.println(level, tag, message);
}
 
Example 16
Project: GitHub   File: FLogDefaultLoggingDelegate.java   View Source Code Vote up 4 votes
private void println(int priority, String tag, String msg, Throwable tr) {
  Log.println(priority, prefixTag(tag), getMsg(msg, tr));
}
 
Example 17
Project: GitHub   File: LogcatLogStrategy.java   View Source Code Vote up 4 votes
@Override public void log(int priority, String tag, String message) {
  Log.println(priority, tag, message);
}
 
Example 18
Project: Floo   File: Floo.java   View Source Code Vote up 4 votes
private static void log(int priority, String message) {
    if (configuration().isDebugEnabled()) {
        Log.println(priority, TAG, message);
    }
}
 
Example 19
Project: TPlayer   File: MethodInvocationStub.java   View Source Code Vote up 4 votes
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    MethodProxy methodProxy = getMethodProxy(method.getName());
    boolean useProxy = (methodProxy != null && methodProxy.isEnable());
    boolean mightLog = (mInvocationLoggingCondition != LogInvocation.Condition.NEVER) ||
            (methodProxy != null && methodProxy.getInvocationLoggingCondition() != LogInvocation.Condition.NEVER);

    String argStr = null;
    Object res = null;
    Throwable exception = null;
    if (mightLog) {
        // Arguments to string is done before the method is called because the method might actually change it
        argStr = Arrays.toString(args);
        argStr = argStr.substring(1, argStr.length()-1);
    }


    try {
        if (useProxy && methodProxy.beforeCall(mBaseInterface, method, args)) {
            res = methodProxy.call(mBaseInterface, method, args);
            res = methodProxy.afterCall(mBaseInterface, method, args, res);
        } else {
            res = method.invoke(mBaseInterface, args);
        }
        return res;

    } catch (Throwable t) {
        exception = t;
        if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception).getTargetException() != null) {
            exception = ((InvocationTargetException) exception).getTargetException();
        }
        throw exception;

    } finally {
        if (mightLog) {
            int logPriority = mInvocationLoggingCondition.getLogLevel(useProxy, exception != null);
            if (methodProxy != null) {
                logPriority = Math.max(logPriority, methodProxy.getInvocationLoggingCondition().getLogLevel(useProxy, exception != null));
            }
            if (logPriority >= 0) {
                String retString;
                if (exception != null) {
                    retString = exception.toString();
                } else if (method.getReturnType().equals(void.class)) {
                    retString = "void";
                } else {
                    retString = String.valueOf(res);
                }

                Log.println(logPriority, TAG, method.getDeclaringClass().getSimpleName() + "." + method.getName() + "(" + argStr + ") => " + retString);
            }
        }
    }
}
 
Example 20
Project: android-sex-http   File: Logger.java   View Source Code Vote up 4 votes
private void log(int lvl, String tag, String msg) {
    if (isLogEnable) {
        Log.println(lvl, tag, msg);
    }
}