ZeppOS Visual Logger: On-Screen Logs on Your Device #237
silver-zepp
started this conversation in
Blog
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
ZeppOS Visual Logger: On-Screen Logs on Your Device
Examples
ⓘ Example 1: Switch logger's position in real-time with a single click.
With Visual Logger, you get exactly what you expect – all the logs you asked for, displayed directly on your emulator or physical device. Plus, with a built-in filter for repeated messages, Visual Logger shines in its ability to deliver the insights you need, exactly where you need them. Here are some key features that make Visual Logger stand out:
Visual Logger feature examples
You’ve seen the first example in the gif above, so let’s quickly walk through the rest of them and then dive deeper into their implementation.
ⓘ Example 2: The repeated messages do not clog the screen.
ⓘ Example 3: Show it only when you need it, hide all the other times.
ⓘ Example 4: Change its looks, to better cater to your app's theme.
How to use Visual Logger
You start by simply including it in your project:
And then using it the usual console.log(...) or logger.log(...) style:
Here's the result: You get clean logs on your device, and also they are mirrored with a help of a built-in log instance, which gives us colorful console logs with filtered levels.
Ready to give it a try?
We have prepared a sample project for you to play with, which you can download Example or clone the repository.
You can install the Visual Logger into your ongoing project from the NPM repository or download it directly from GitHub.
Visual Logger for ZeppOS 2.0+ GitHub
Visual Logger for ZeppOS 1.0 GitHub
Customizing your logger
Let’s have a closer look at some of the most important settings
[line_count] : specifies the number of messages (lines) before recycling them. If you’re planning to use a larger font size you might consider lowering the amount of lines visible. Or in case you want to have a logger that barely takes any screen space, you can just put it to 1.
[timeout_enabled] : will make messages disappear after a timeout. Disable it when you don’t want to miss a message by going AFK for a minute.
[log_from_top] : by default the logger stays on top of the screen and logs messages towards the bottom. Disable this if you want your messages to come from bottom to top.
[prefix_enabled] : this is mostly self-explanatory but you can disable it if you, for example, want to integrate the chat app inside your actual mini-app. This can be easily achieved with Visual Logger.
[padding_multiplier] & [margin] : you want to play with these values (mostly increase) in case your app is designed for a “designWidth” that is not equal to 480. By default, the margin is enabled only when Visual Logger is run on a round-shaped screen, and its value is equal to the text size.
The rest of the settings are not that important but you can read more about what they do just by looking at hints provided by your IntelliSense, they all are explained with JSDoc.
Here are all the default settings of your logger, they are already applied so you don’t have to specify any of these for the logger to work out of the box.
Note: To change the text_style, make sure to import the hmUI namespace or assign the enum values manually. Here are their numerical values for reference:
So if you want to change the text style you can go with one of these approaches
Real-World use case scenario
Here’s an example case where Visual Logger already played a key role, helping with the development of the Mini Chess game. We can observe how the AI thinks right on the screen of the physical device!
*current example shows its work on the Bip 5 Emulator. And is running a debug version of the game that looks different than the end product.
Beta Was this translation helpful? Give feedback.
All reactions