Android Question Remove log() code lines?

Midimaster

Active Member
Licensed User
Is there a chance to auto-remove all log() command lines from Code-Modules and Activity-Modules as a first step of the compiling process?

I often write log() commands in my code to observe the app during execution. They contain readable strings with sensitiv informations. I want to keep all log() lines in my code for future development. This makes the development very comfortable for me.

But now my development of the current app reaches the final, where I want to publish my app. Now I want to remove all (~1000) lines with log() for security reasons before compiling starts.

I know how to do this with a VB-Script. But this needs to make Backups of each module, then run the script on each module-file. Then start B4A again and compile the manipulated files and afterwards I have to replace the module with the backups.

now I have two questions:
Is there a compiler-option to remove certain line types automatically during the comping process?

Or is there a chance to insert an EXE as a first step in the compiling process to manipulate code files temporary and offer these files to the compiler?

How do you handle logs() lines?
 

toby

Well-Known Member
Licensed User
Longtime User
You don't have to remove them. Just simply make a release build which ignores logging.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
One way could be using conditional compilation.
Something like #If DEBUG...

See here.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Just simply make a release build which ignores logging.
Not true. If you do not exlude LOG Commands using Conditional Compiling then the LOGs are still there. Even in Release...
See answer from @udg
 
Upvote 0

Midimaster

Active Member
Licensed User
But this means to set a #If FINAL... individual around each line with log() command, or?

This is no comfortable solution. I would search for a general compiler option, that ignores all log()-lines automatically.

I think there must be already something similar for comment lines, or?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Midimaster

Active Member
Licensed User
Thanks for your ideas, but... No, I dont want to stop the logging... I need to remove the strings from the code. They contain a lot of information about what is happening in my subs. As long as the content of the logs()-lines keeps in the code, any obfuscating would not help anything!
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Then you may use #iderun (or something like that) to call a command line grep text replace utility to put ' single quote before all log( lines.

I use similar technology in my XBase compilation batch files, for final and beta exe.

Regards

Anand
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But this means to set a #If FINAL... individual around each line with log() command, or?

This is no comfortable solution. I would search for a general compiler option, that ignores all log()-lines automatically.
Yes, it would be a pain to add a conditional flag around EVERY log statement, but why not just add a conditional flag around just the log entries that include confidential info?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Upvote 0

Midimaster

Active Member
Licensed User
Then you may use #iderun (or something like that) to call a command line grep text replace utility to put ' single quote before all log( lines.
...Anand

This sounds interesting! Will this be able start an exe that changes the code line only during the compiling process? Or are the code line afterwards also changed in the IDE? Can you show my how such a toll call looks like? And you put this line only once on top of your code?
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Why don't you just replace (Ctrl+H) all the log with 'log (REM) and then do the opposite when you need it again. F.e.

B4X:
Log("Something")

'Log("Something")

This way it will not be included in compilation.
 
Upvote 0

Midimaster

Active Member
Licensed User
This is my plan B of course. But I did not know, whether there is perhaps a more elegant way to force the compiler to ignore log() lines. So I asked...
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
You can use #CustomBuildAction, see

Here you can call a command line text replace exe (instead of robocopy) and pass your .b4a file with the regex command to replace the text.

Regards,

Anand
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…