Log Management in FruitsApp in HarmonyOS

Shiddalingeshwar M S
3 min readOct 14, 2021

In this article, we will learn about Log Management in HarmonyOS sample application called FruitsApp. It provides the HiLog capability for your applications to output logs based on the specified type, level, and format string. Such logs helps you learn the running status of applications and better debug programs.

Introduction

In this article, we will learn about Log Management in HarmonyOS sample application called FruitsApp. It provides the HiLog capability for your applications to output logs based on the specified type, level, and format string. Such logs helps you learn the running status of applications and better debug programs.

HiLog class has five methods to get logs. Before calling methods, you must call the methods in the auxiliary class HiLogLabel to define log labels.

Defining Log Labels

Call the constructor HiLogLabel(int type, int domain, String tag) to define log labels, including the log type, service domain and tag. Sample code:

  • type: type of output logs. Only the log type LOG_APP is available for this method.
  • domain: service domain of logs. The value ranges from 0x0 to 0xFFFFF. You can define the value as required.
  • tag: log identifier. You are advised to use this parameter to identify a particular service behaviour or the class holding ongoing method.

You can search for desired logs based on the domain and tag you have defined.

Outputting Logs

HiLog class has five log levels:

  1. DEBUG
  2. INFO
  3. WARN
  4. ERROR
  5. FATAL

You can call the method specific to a particular log level to obtain your intended logs, as detailed in the following table.

Development Overview

You need to install DevEcho studio IDE and I assume that you have prior knowledge about the Harmony OS and java.

Hardware Requirements

  • A computer (desktop or laptop) running Windows 10.
  • A Harmony OS phone (with the USB cable), which is used for debugging.

Software Requirements

  • Java JDK installation package.
  • Latest DevEcho studio installed.

Steps:

Step 1: Create HarmonyOS Application.

Let’s start coding

Result

Tips and Tricks

  • Add required dependencies without fail
  • Add required images in resources > rawfile
  • Add custom strings in resources > base > element > string.json
  • Define supporting devices in config.json file.
  • Add required permissions in config,json.
  • Define Log Label before using HiLog methods.
  • Do not log the sensitive data.
  • Use respective Log methods to print logs.

Conclusion

In this article, we have learnt to use Log management using HiLog class and its different methods allows us to output logs based on the specified type, level, and format string. Such logs helps you to learn the running status of applications and better debug programs. Hope this article helps you to understand the working of Log Management in HarmonyOS. More details you can refer below link.

Thank you so much for reading article and please provide your valuable feedback and like.

Reference

Log Management in HarmonyOS

Checkout in forum

--

--