Log
class Log
| kotlin.Any | |
| ↳ | android.util.Log |
API for sending log output.
Generally, you should use the Log.v(), Log.d(), Log.i(), Log.w(), and Log.e() methods to write logs. You can then view the logs in logcat.
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.
Tip: A good convention is to declare a TAG constant in your class:
private static final String TAG = "MyActivity";and use that in subsequent calls to the log methods.
Tip: Don't forget that when you make a call like
Log.v(TAG, "index=" + i);that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.
Summary
| Constants | |
|---|---|
| static Int |
Priority constant for the println method. |
| static Int |
Priority constant for the println method; use Log. |
| static Int |
Priority constant for the println method; use Log. |
| static Int |
Priority constant for the println method; use Log. |
| static Int |
Priority constant for the println method; use Log. |
| static Int |
Priority constant for the println method; use Log. |
| Public methods | |
|---|---|
| static Int |
Send a |
| static Int |
Send a |
| static Int |
Send an |
| static Int |
Send a |
| static String |
getStackTraceString(tr: Throwable?)Handy function to get a loggable stack trace from a Throwable |
| static Int |
Send an |
| static Int |
Send a |
| static Boolean |
isLoggable(tag: String?, level: Int)Checks to see whether or not a log for the specified tag is loggable at the specified level. |
| static Int |
Low-level logging call. |
| static Int |
Send a |
| static Int |
Send a |
| static Int |
Send a |
| static Int |
Send a |
| static Int |
Send a |
| static Int |
What a Terrible Failure: Report a condition that should never happen. |
| static Int |
What a Terrible Failure: Report an exception that should never happen. |
| static Int |
What a Terrible Failure: Report an exception that should never happen. |
Constants
ASSERT
static val ASSERT: Int
Priority constant for the println method.
Value: 7
DEBUG
static val DEBUG: Int
Priority constant for the println method; use Log.d.
Value: 3
ERROR
static val ERROR: Int
Priority constant for the println method; use Log.e.
Value: 6
INFO
static val INFO: Int
Priority constant for the println method; use Log.i.
Value: 4
VERBOSE
static val VERBOSE: Int
Priority constant for the println method; use Log.v.
Value: 2
WARN
static val WARN: Int
Priority constant for the println method; use Log.w.
Value: 5
Public methods
d
static fun d(
tag: String?,
msg: String
): Int
Send a DEBUG log message.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
d
static fun d(
tag: String?,
msg: String?,
tr: Throwable?
): Int
Send a DEBUG log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
e
static fun e(
tag: String?,
msg: String
): Int
Send an ERROR log message.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
e
static fun e(
tag: String?,
msg: String?,
tr: Throwable?
): Int
Send a ERROR log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
getStackTraceString
static fun getStackTraceString(tr: Throwable?): String
Handy function to get a loggable stack trace from a Throwable
| Parameters | |
|---|---|
tr |
Throwable?: An exception to log This value may be null. |
| Return | |
|---|---|
String |
This value cannot be null. |
i
static fun i(
tag: String?,
msg: String
): Int
Send an INFO log message.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
i
static fun i(
tag: String?,
msg: String?,
tr: Throwable?
): Int
Send a INFO log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
isLoggable
static fun isLoggable(
tag: String?,
level: Int
): Boolean
Checks to see whether or not a log for the specified tag is loggable at the specified level. The default level of any tag is set to INFO. This means that any level above and including INFO will be logged. Before you make any calls to a logging method you should check to see if your tag should be logged. You can change the default level by setting a system property: 'setprop log.tag.<YOUR_LOG_TAG> <LEVEL>' Where level is either VERBOSE, DEBUG, INFO, WARN, ERROR, or ASSERT. You can also create a local.prop file that with the following in it: 'log.tag.<YOUR_LOG_TAG>=<LEVEL>' and place that in /data/local.prop.
| Parameters | |
|---|---|
tag |
String?: The tag to check. This value may be null. |
level |
Int: The level to check. Value is android.util.Log#ASSERT, android.util.Log#ERROR, android.util.Log#WARN, android.util.Log#INFO, android.util.Log#DEBUG, or android.util.Log#VERBOSE |
| Return | |
|---|---|
Boolean |
Whether or not that this is allowed to be logged. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
is thrown if the tag.length() > 23 for Nougat (7.0) releases (API <= 23) and prior, there is no tag limit of concern after this API level. |
println
static fun println(
priority: Int,
tag: String?,
msg: String
): Int
Low-level logging call.
| Parameters | |
|---|---|
priority |
Int: The priority/type of this log message Value is android.util.Log#ASSERT, android.util.Log#ERROR, android.util.Log#WARN, android.util.Log#INFO, android.util.Log#DEBUG, or android.util.Log#VERBOSE |
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
| Return | |
|---|---|
Int |
The number of bytes written. |
v
static fun v(
tag: String?,
msg: String
): Int
Send a VERBOSE log message.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
v
static fun v(
tag: String?,
msg: String?,
tr: Throwable?
): Int
Send a VERBOSE log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
w
static fun w(
tag: String?,
msg: String
): Int
Send a WARN log message.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String: The message you would like logged. This value cannot be null. |
w
static fun w(
tag: String?,
msg: String?,
tr: Throwable?
): Int
Send a WARN log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
w
static fun w(
tag: String?,
tr: Throwable?
): Int
Send a WARN log message and log the exception.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. It usually identifies the class or activity where the log call occurs. This value may be null. |
tr |
Throwable?: An exception to log This value may be null. |
wtf
static fun wtf(
tag: String?,
msg: String?
): Int
What a Terrible Failure: Report a condition that should never happen. The error will always be logged at level ASSERT with the call stack. Depending on system configuration, a report may be added to the android.os.DropBoxManager and/or the process may be terminated immediately with an error dialog.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
wtf
static fun wtf(
tag: String?,
tr: Throwable
): Int
What a Terrible Failure: Report an exception that should never happen. Similar to wtf(java.lang.String,java.lang.String), with an exception to log.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. This value may be null. |
tr |
Throwable: An exception to log. This value cannot be null. |
wtf
static fun wtf(
tag: String?,
msg: String?,
tr: Throwable?
): Int
What a Terrible Failure: Report an exception that should never happen. Similar to wtf(java.lang.String,java.lang.Throwable), with a message as well.
| Parameters | |
|---|---|
tag |
String?: Used to identify the source of a log message. This value may be null. |
msg |
String?: The message you would like logged. This value may be null. |
tr |
Throwable?: An exception to log. May be null. This value may be null. |