public final class HiLog extends Object
HiLog logs.
Before outputting logs, you must define the log type, service domain, and tag in HiLogLabel,
use the interface specific to the specified log level, and specify the privacy identifier.
Log level: debug, info, warn, error, and fatal
Parameter format: printf format string, which starts with a % character, including a parameter type identifier and a variable parameter.
Privacy identifier: {public} or {private} added between the % character and the parameter type identifier in each parameter.
Example code:
Defining a label:
static final HiLogLabel label = new HiLogLabel(HiLog.LOG_APP, MY_MODULE, "MY_TAG"); //MY_MODULE=0x00201
Code:
HiLog.warn(label, "Failed to visit %{private}s, reason:%{public}d.", url, errno);
Result: 05-26 11:01:06.870 1051 1051 W 00201/test: Failed to visit
<private>, reason:503.
Note: Each parameter has a privacy identifier. If no privacy identifier is added, the parameter is considered to be private.
HiLogLabel| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static int |
DEBUG |
Indicates the debug-level log.
|
static int |
ERROR |
Indicates the error-level log.
|
static int |
FATAL |
Indicates the fatal-level log.
|
static int |
INFO |
Indicates the info-level log.
|
static int |
LOG_APP |
Indicates the application log type.
|
static int |
WARN |
Indicates the warn-level log.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static int |
debug(HiLogLabel label,
String format,
Object... args) |
Outputs debug-level logs.
|
static int |
error(HiLogLabel label,
String format,
Object... args) |
Outputs error-level logs.
|
static int |
fatal(HiLogLabel label,
String format,
Object... args) |
Outputs fatal-level logs.
|
static String |
getStackTrace(Throwable tr) |
Obtains the method-call stack from the
Throwable object. |
static int |
info(HiLogLabel label,
String format,
Object... args) |
Outputs info-level logs.
|
static boolean |
isLoggable(int domain,
String tag,
int level) |
Checks whether logs of the specified service domain, tag, and level can be printed.
|
static int |
warn(HiLogLabel label,
String format,
Object... args) |
Outputs warn-level logs.
|
public static final int DEBUG
Value: 3
public static final int ERROR
Value: 6
public static final int FATAL
Value: 7
public static final int INFO
Value: 4
public static final int LOG_APP
Value: 0
public static final int WARN
Value: 5
public static int debug(HiLogLabel label, String format, Object... args)
label - Identifies the log type, service domain, and tag.format - Indicates a constant format string, including the parameter type and privacy identifier.
If no privacy identifier is added, the parameter is considered to be private.args - Indicates the parameter list corresponding to the parameter type in the format string.
The number and type of parameters must be mapped onto the identifier in the format string.0 or an int greater than 0 if the operation is successful;
returns an int less than 0 otherwise.public static int info(HiLogLabel label, String format, Object... args)
label - Identifies the log type, service domain, and tag.format - Indicates a constant format string, including the parameter type and privacy identifier.
If no privacy identifier is added, the parameter is considered to be private.args - Indicates the parameter list corresponding to the parameter type in the format string.
The number and type of parameters must be mapped onto the identifier in the format string.0 or an int greater than 0 if the operation is successful;
returns an int less than 0 otherwise.public static int warn(HiLogLabel label, String format, Object... args)
label - Identifies the log type, service domain, and tag.format - Indicates a constant format string, including the parameter type and privacy identifier.
If no privacy identifier is added, the parameter is considered to be private.args - Indicates the parameter list corresponding to the parameter type in the format string.
The number and type of parameters must be mapped onto the identifier in the format string.0 or an int greater than 0 if the operation is successful;
returns an int less than 0 otherwise.public static int error(HiLogLabel label, String format, Object... args)
label - Identifies the log type, service domain, and tag.format - Indicates a constant format string, including the parameter type and privacy identifier.
If no privacy identifier is added, the parameter is considered to be private.args - Indicates the parameter list corresponding to the parameter type in the format string.
The number and type of parameters must be mapped onto the identifier in the format string.0 or an int greater than 0 if the operation is successful;
returns an int less than 0 otherwise.public static int fatal(HiLogLabel label, String format, Object... args)
label - Identifies the log type, service domain, and tag.format - Indicates a constant format string, including the parameter type and privacy identifier.
If no privacy identifier is added, the parameter is considered to be private.args - Indicates the parameter list corresponding to the parameter type in the format string.
The number and type of parameters must be mapped onto the identifier in the format string.0 or an int greater than 0 if the operation is successful;
returns an int less than 0 otherwise.public static boolean isLoggable(int domain,
String tag,
int level)
domain - Indicates the service domain of logs.tag - Indicates the log tag.level - Indicates the log level.true if the logs can be printed; returns false otherwise.public static String getStackTrace(Throwable tr)
Throwable object.tr - Indicates the Throwable object or the object of any of its subclasses.
Throwable is the superclass of all errors and exceptions in the Java language.Throwable object.