Log
Introduction
This sample shows how to use log APIs to print log information and save the information to the application installation directory.
APIs
import logger from '@ohos/log'
import { LogLevel } from '@ohos/log'
import { Configure } from '@ohos/log'
Usage Instruction
- Configure log printing parameters.
Configure = {
cheese: {
types: string[],
filename: string
}
defaults: {
appenders: string,
level: LogLevel
}
}
// If types is set to file, logs are saved to the file named by filename. appenders indicates the log tag, and level indicates the lowest log level.
- Initialize a logger instance.
logger.setConfigure(configure: Configure)
// configure indicates the parameter configuration.
- Print log information of the debug level.
logger.debug(value)
// value indicates the log content.
- Print log information of the info level.
logger.info(value)
// value indicates the log content.
- Print log information of the warn level.
logger.warn(value)
// value indicates the log content.
- Print log information of the error level.
logger.error(value)
// value indicates the log content.
- Print log information of the fatal level.
logger.fatal(value, bool)
// value indicates the log content.
Constraints
-
This sample requires API version 9 or later.
-
This sample requires DevEco Studio 3.1 Canary1 (Build Version: 3.1.0.100) to compile and run.