Brilliant :-)

If you are tired of creating LOGS text files as your PRG files are created and auto-renamed all the time....


Just create a BAT file (batch) in the LOGS directory with these line. Run it every time you load up a new PRG file to your device. You are welcome :-) Obviously run it from the LOGS directory, which is what happens when you double click on the BAT file from the folder.

What this does is remove existing TXT files, copies all your PRG files to the LOGS folder, renaming them to TXT files, and then zeros out the contents so the TXT files are empty.


PRG2TXT.BAT
===============================
del *.txt >nul 2>&1
copy ..\*.prg .\*.txt
for %%f in (*.txt) do break>%%f

  • I'd be a bit careful with this, as writing to the file system is an expensive operation.
    Some apps have Sys.println() calls in them, but are close to no-ops if the log file doesn't exist (they are only used for debugging a problem). But by creating all the possible log files, there could be a bunch of writing going on, switching to .bak files, etc and impact other apps.

    Log files should really only be used for debugging. If you want some history, look at using Application Store and add a way to view that in the app.
  • I'd be a bit careful with this, as writing to the file system is an expensive operation.
    Some apps have Sys.println() calls in them, but are close to no-ops if the log file doesn't exist (they are only used for debugging a problem). But by creating all the possible log files, there could be a bunch of writing going on, switching to .bak files, etc and impact other apps.

    Log files should really only be used for debugging. If you want some history, look at using Application Store and add a way to view that in the app.


    Oh good point Jim! Interesting. We call this a Heisenbug! :-) A play on the word Heisenberg.... from his Uncertainty Principle. In part that says the act of measuring something invalidates what you think you are measureing. In this case, writing to the log file in order to capture the battery drain stats.... is in fact, causing the battery drain analysis to be in error.
  • No, it's much more than that. Let's say there is a watchface that has a call to Sys.println() every minute or even every second at times. This bat file would enable that logging over head to happen.

    This bat file could result in "contact developer" messages to the WF developer about the battery impact of their watchface when it starts writing to the file system all the time. And they wouldn't have a clue as to the cause..

    In other words,using this bat file can impact apps other than yours, leaving those devs scratching their heads as to what happened.
  • As a tool for other devs this shouldn't be a problem, as they can watch and see if other log files keep growing, but for end users, they might not know to do that.

    I forget if in DOS you can do something like a search in the prg files for a specific string. If so, you could search for your app name in the .prg files and create the .txt based on the .prg it was found in if you want to have it for users.
  • Not sure if this is helpful, but you can use the following Windows batch file to create an empty log TXT file from the last modified PRG file.

    Name it logfile.bat -- or whatever -- and run from the APPS\LOGS\ folder:
    https://pastebin.com/HB9FHL3b

    Of course that doesn't handle the case when you load (multiple?) PRGs as a developer.

    Here's a different batchfile that you can place in the APPS\ folder. Sort by date modified (if you want), drag-and-drop multiple PRGs onto the batch file, and log TXT files will be created.
    https://pastebin.com/cz4nJhDf

    Sorry about the pastebin links, the forum is not cooperating, as usual.

    Credit:
    https://superuser.com/questions/659577/open-last-modified-file-from-a-folder-through-command-prompt
    https://stackoverflow.com/questions/3432851/dos-bat-file-equivalent-to-unix-basename-command/47487854#47487854
  • Again, prone to error, as if you get updates to apps with Garmin Express, you could get a bunch at one time (or more specifically, a user could). The "update" option in GCM would also be a false flag. That's why you need to look at the .prg and see what it is. I do that today with my store installed apps with a file viewer. Look for the app name and create the corresponding .txt log file for that prg.
  • Hmm, I guess perfect isn't the enemy of good, after all.

    Okay, here's a batch file you can run from the command line, which takes multiple keywords as arguments. Place it in the APPS/ folder.

    - Deletes all TXT files in the LOGS\ folder
    - Finds all apps matching any one of the keywords and creates the corresponding text files.

    If you run it with zero keywords, it just deletes all the TXT files in the LOGS\folder

    Usage:
    logfile.bat [KEYWORDS]

    e.g. logfile.bat myapp1 myapp2

    https://pastebin.com/LTRUfzvx

    If you want to deploy to an end-user, just comment-out/uncomment the appropriate lines as indicated in the source, and change "myapp1 myapp2" to whatever keywords you want.
  • Again, there's an unintended side effect by deleting of all txt files in logs. That could include log files the user purposely created, as well as the general ciq_log.txt file from CIQ1/CIQ2. (in CIQ3 it's ciq_log.yml)
  • jim_m_58 Fair enough, thanks! Well, any of the batch files in this thread can be easily modified as necessary to not delete any files (*), and I personally thought of the OP as offering a tool for the use of devs and not necessarily to deploy to end users.

    (*) In that case, "COPY" needs to be changed to "COPY /Y" in order to suppress prompting to overwrite an existing file.
  • note that the batch file will only work on usb based watches, it won't work on music devices since they're mtp based (and the dos copy command won't work on mtp devices)