DEV Community

wei chang
wei chang

Posted on

A Detailed explanation of the log printing issues in the HarmonyOS Cangjie development language

In the early stage of a new development language’s birth, due to its own characteristics and the relatively small number of users, it is prone to some problems that are not easy for people to understand, or there are some pitfalls. Today, I will share in detail the relevant content about log printing in the Cangjie development language and help you get through the pitfalls.
AppLog
In the newly created project, the click event of the Button writes a line of code for printing the log:

Image description

Unlike ArkTs, there is no console.log in the Cangjie language. Here, AppLog.info is used.
At this point, a problem emerged. Many students found that nothing was printed after clicking the button, and You LAN Jun was no exception. At that time, he was troubled by this problem for a long time

Image description

Ultimately, it was found that the content printed by AppLog could only be seen on the real device and not on the emulator.

Image description

So, what exactly is AppLog and why does this problem occur?
The Cangjie language cannot be accessed through command to view the code. We have no information about AppLog at all. However, Youlan Jun still caught a hint from the code prompt:

Image description

It can be seen that AppLog is still based on the encapsulation of Hilog, and the console of DevEco prints the content of Hilog. Moreover, as the recommended printing method in the initialization code, it cannot be printed in the simulator. I can only understand this as a pitfall.

Image description

Hilog
As mentioned earlier, AppLog is an encapsulation based on Hilog. Therefore, in Cangjie, you can still use Hilog, which is the most fundamental printing method in HarmonyOS. Both console and AppLog are encapsulated from Hilog. Students without real machine equipment can use this method:

Hilog.info(0x0000, 'hello hilog', 'this is an info level log');

At this point, logs can be printed normally in the simulator.

Image description

print
Let me tell you a secret. The Cangjie projects created with VSCode are quite different from those created with DevEco. Moreover, the default way to print logs is println:

Image description

This method can be printed normally in vscode. println is an encapsulation based on print, so using print here is equally effective.
println and print can also be written in DevEco, but they cannot be printed because DevEco can only print the content of Hilog, and print has no relation to Hilog.
The above is the log printing in the Cangjie development language. I hope it will be helpful to everyone.

Top comments (0)