What's the console.log() of java?

JavaAndroid

Java Problem Overview


I'm working on building an Android app and I'm wondering what the best approach is to debugging like that of console.log in javascript

Java Solutions


Solution 1 - Java

The Log class:

> API for sending log output. > > Generally, use the Log.v() Log.d() Log.i() Log.w() and Log.e() > methods. > > The order in terms of verbosity, from least to most is ERROR, WARN, > INFO, DEBUG, VERBOSE. Verbose should never be compiled into an > application except during development. Debug logs are compiled in but > stripped at runtime. Error, warning and info logs are always kept.

Outside of Android, System.out.println(String msg) is used.

Solution 2 - Java

Use the Android logging utility.

http://developer.android.com/reference/android/util/Log.html

Log has a bunch of static methods for accessing the different log levels. The common thread is that they always accept at least a tag and a log message.

Tags are a way of filtering output in your log messages. You can use them to wade through the thousands of log messages you'll see and find the ones you're specifically looking for.

You use the Log functions in Android by accessing the Log.x objects (where the x method is the log level). For example:

Log.d("MyTagGoesHere", "This is my log message at the debug level here");
Log.e("MyTagGoesHere", "This is my log message at the error level here");

I usually make it a point to make the tag my class name so I know where the log message was generated too. Saves a lot of time later on in the game.

You can see your log messages using the logcat tool for android:

adb logcat

Or by opening the eclipse Logcat view by going to the menu bar

> Window->Show View->Other then select the Android menu and the LogCat view

Solution 3 - Java

console.log() in java is System.out.println(); to put text on the next line

And System.out.print(); puts text on the same line.

Solution 4 - Java

public class Console {

    public static void Log(Object obj){
        System.out.println(obj);
    }
}

to call and use as JavaScript just do this:

Console.Log (Object)

I think that's what you mean

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBenView Question on Stackoverflow
Solution 1 - JavanhaarmanView Answer on Stackoverflow
Solution 2 - JavaJohn O'ConnorView Answer on Stackoverflow
Solution 3 - JavaTimooboberView Answer on Stackoverflow
Solution 4 - JavaBunnyCoderView Answer on Stackoverflow