Logging within flow

Post your questions and help other users.

Moderator: Martin

Post Reply
User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Logging within flow

Post by digitalstone » 28 Apr 2019 17:39

I have a question about writing log information to a txt-file.
There is this flow i'm working on and i want to create log info around each corner in an efficient way.
The goal is to make it absolutely sure the info is being written (in case the flow unexpectedly stops), while at the same time being efficient in writing to the storage.

I can't decide to either:
1. Create variables in script-actions along the flow, and collect all info at the end to write a logfile all at once.
2. Write pieces of the logfile along the flow.

I'm thinking method #1 is the easiest, but still...
Pros: It's faster because AM does not need to do all the things like read-to-append and write text and such.
It's better for the the storage device to have it not being written to about 7 times in a row each time this flow runs (SSD commonly known writing-shenanigans).
Cons: Log security isn't optimal. Once the flow suddenly would stop due to whatever reason, no log info will be written at all.
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Logging within flow

Post by Desmanto » 28 Apr 2019 18:19

Don't write to file, it need to execute another write to file action. Using log is also not efficient, the info quickly lost (hard to scan) in case of error.

Create a glovar list, examplet global_logging. Then in each part of the script, add

Code: Select all

addElement(global_logging, "01. " + variableyouwanttolog)
In another part, put 02, 03, 04 and so on. This helps you to identify the value at each breakpoint. Without the numbering, you can still identify it by the element index. You can clean up the global_logging after each execution, by having another script

Code: Select all

global_logging = newList();
and execute it manually from script.

If the variable you are logging is map or list type, you can simply add it without the "01. " so the variable stay as list/map.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Logging within flow

Post by digitalstone » 28 Apr 2019 18:52

Thanks for the very quick response.

So you're saying not to use ANY write-to-file method at all, but instead to keep everything just inside the glovar?
I don't really understand your first sentence: "Don't write to file, it need to execute another write to file action."
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Logging within flow

Post by Desmanto » 28 Apr 2019 18:58

Yes, using glovar is much faster, everything is logged directly to the variable and stay after the execution. (unlike local variable which have destroyed after flow execution finished).

If you need to save to text file, you need to use Action Write to file. You can't use it inside the script. You have use script - write to file - script - write to file - script - ....... So inefficient.
I know you can use log(), but as I point out, when error, it is very difficult to spot the variable value, to dig out the source of problem.

While using glovar, every logging is done within the same script action. You simply add it in between every breakpoint you want to log. To remove the logging, simply comment it out by using double slash //
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: Logging within flow

Post by digitalstone » 28 Apr 2019 19:39

That's very clear now, thanks :D
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

Post Reply