- 创建sharedLibrary共享hsp包commonLib:功能工具类。
javascript
复制代码
import hilog from '@ohos.hilog';
class Logger {
private DOMAIN: number = 0x0000;
private APP_NAME: string = 'Myapplication';
public info(tag: string, ...args: string[]) {
hilog.info(this.DOMAIN, `[${this.APP_NAME}.${tag}]`, '%{public}s', args.join(''));
}
public error(tag: string, ...args: string[]) {
hilog.error(this.DOMAIN, `[${this.APP_NAME}.${tag}]`, '%{public}s', args.join(''));
}
}
export const logger = new Logger();
javascript
复制代码
export { logger } from "./utils/Logger";
javascript
复制代码
"devDependencies": {
"@ohos/commonLib": "file:./commonLib"
}
javascript
复制代码
import { logger } from '@ohos/commonLib';
logger.info(TAG, 'Ability onCreate');