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

The following examples show how to use android.util.Log#println() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogWrapper.java    From graphics-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: LogWrapper.java    From android-MultiWindowPlayground with Apache License 2.0 6 votes vote down vote up
/**
 * 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
Source File: LogHelper.java    From GithubApp with Apache License 2.0 6 votes vote down vote up
private static void log(String tag, int level, Throwable t, Object... messages) {
    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 4
Source File: LogWrapper.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 5
Source File: LogWrapper.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 6
Source File: LogWrapper.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 7
Source File: ULog.java    From DMusic with Apache License 2.0 5 votes vote down vote up
public static void w(String message) {
    if (!DEVELOP_MODE || TextUtils.isEmpty(message)) {
        return;
    }
    final StackTraceElement[] stack = new Throwable().getStackTrace();
    final int i = 1;
    final StackTraceElement ste = stack[i];
    Log.println(Log.WARN, LOG_TAG, String.format("[%s][%s][%s]%s", ste.getFileName(), ste.getMethodName(), ste.getLineNumber(), message));
}
 
Example 8
Source File: P_Logger.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
private void log_private(int level, String tag, String message, StackTraceElement trace)
{
	message = prefixMessage(trace.getMethodName(), message);
	if (m_logger != null)
	{
		m_logger.onLogEntry(level, tag, message);
	}
	else
	{
		Log.println(level, tag, message);
	}
}
 
Example 9
Source File: LogUtils.java    From ShizuruNotes with Apache License 2.0 5 votes vote down vote up
private static void printSubMsg(final int type, final String tag, final String msg) {
    if (!CONFIG.isLogBorderSwitch()) {
        Log.println(type, tag, msg);
        return;
    }
    StringBuilder sb = new StringBuilder();
    String[] lines = msg.split(LINE_SEP);
    for (String line : lines) {
        Log.println(type, tag, LEFT_BORDER + line);
    }
}
 
Example 10
Source File: ApplicationDebugTree.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
private void throwShade(int priority, String message, Throwable t) {
    if (message == null || message.length() == 0) {
        if (t != null) {
            message = Log.getStackTraceString(t);
        } else {
            // Swallow message if it's null and there's no throwable.
            return;
        }
    } else if (t != null) {
        message += "\n" + Log.getStackTraceString(t);
    }

    String tag = createTag();
    if (message.length() < 4000) {
        /*
         * Replacing the original tag with the application tag and
         * using the tag for the class formatted at the beginning.
         */
        String taggedMessage = String.format("%s -> %s", tag, message);
        Log.println(priority, applicationTag, taggedMessage);
    } else {
        // It's rare that the message will be this large, so we're ok with the perf hit of splitting
        // and calling Log.println N times.  It's possible but unlikely that a single line will be
        // longer than 4000 characters: we're explicitly ignoring this case here.
        String[] lines = message.split("\n");
        for (String line : lines) {
            Log.println(priority, tag, line);
        }
    }
}
 
Example 11
Source File: ALog.java    From Aria with Apache License 2.0 5 votes vote down vote up
private static int println(int level, String tag, String msg) {
  if (LOG_LEVEL <= level) {
    return Log.println(level, tag, TextUtils.isEmpty(msg) ? "null" : msg);
  } else {
    return -1;
  }
}
 
Example 12
Source File: ULog.java    From DMusic with Apache License 2.0 5 votes vote down vote up
public static void e(String message) {
    if (!DEVELOP_MODE || TextUtils.isEmpty(message)) {
        return;
    }
    final StackTraceElement[] stack = new Throwable().getStackTrace();
    final int i = 1;
    final StackTraceElement ste = stack[i];
    Log.println(Log.ERROR, LOG_TAG, String.format("[%s][%s][%s]%s", ste.getFileName(), ste.getMethodName(), ste.getLineNumber(), message));
}
 
Example 13
Source File: LoggingListener.java    From StatusStories with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onException(Exception e, A model, Target<B> target, boolean isFirstResource) {
    Log.println(level, "GLIDE", String.format(Locale.ROOT,
            "%s.onException(%s, %s, %s, %s)\n%s",
            name, e, model, strip(target), isFirst(isFirstResource), Log.getStackTraceString(e)));
    return delegate.onException(e, model, target, isFirstResource);
}
 
Example 14
Source File: ib.java    From letv with Apache License 2.0 5 votes vote down vote up
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 15
Source File: Timber.java    From RxJava2RetrofitDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Break up {@code message} into maximum-length chunks (if needed) and send to either
 * {@link Log#println(int, String, String) Log.println()} or
 * {@link Log#wtf(String, String) Log.wtf()} for logging.
 * <p>
 * {@inheritDoc}
 */
@Override
protected void log(int priority, String tag, String message, Throwable t) {
    if (message.length() < MAX_LOG_LENGTH) {
        if (priority == Log.ASSERT) {
            Log.wtf(tag, message);
        } else {
            Log.println(priority, tag, message);
        }
        return;
    }

    // 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);
            String part = message.substring(i, end);
            if (priority == Log.ASSERT) {
                Log.wtf(tag, part);
            } else {
                Log.println(priority, tag, part);
            }
            i = end;
        } while (i < newline);
    }
}
 
Example 16
Source File: LogUtils.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
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 17
Source File: L.java    From KakaCache-RxJava with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void print(int level, StackTraceElement element, String tag, Object msg) {
    String className = element.getClassName();
    className = className.substring(className.lastIndexOf(".") + 1);
    String codeLine = className+'.'+element.getMethodName()+'('+element.getFileName()+':'+element.getLineNumber()+')';
    Log.println(level, tag, codeLine);

    String message = toString(msg);
    Log.println(level, tag, "\t" + message);
}
 
Example 18
Source File: ALog.java    From ALog with Apache License 2.0 4 votes vote down vote up
private static void printBorder(final int type, final String tag, boolean isTop) {
    if (sConfig.mLogBorderSwitch) {
        Log.println(type, tag, isTop ? TOP_BORDER : BOTTOM_BORDER);
    }
}
 
Example 19
Source File: TraceEvent.java    From cronet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static void traceAndLog(int level, String message) {
    TraceEvent.instant("TraceEvent.LooperMonitor:IdleStats", message);
    Log.println(level, TAG, message);
}
 
Example 20
Source File: LogUtils.java    From CrawlerForReader with Apache License 2.0 4 votes vote down vote up
private static void printBorder(final int type, final String tag, boolean isTop) {
    if (sLogBorderSwitch) {
        Log.println(type, tag, isTop ? TOP_BORDER : BOTTOM_BORDER);
    }
}