What I’m trying to do:
I’m trying to open or save the text file I’ve printed a log of variables for debugging, normally I scan the the text from console but after a while of developing the console get’s too long but I need to see the history of what method is passing what. So I tried saving to the /tmp/debug.txt file,
I can only view it in a UI using the text area component, but I don’t want to expose sensitive apik key information publishing that UI for me to access it, which all my users can access. Is there a way to access a UI form privately?
Also I tried to download the /tmp/debug.txt from the database but it doesn’t seem to update the file and it’s the original file that was uploaded. So is there a better way to download it? or is it a bug not updating the file in the database?
print()
writes to your App instance’s log. So if you use that, then you can look there, in the IDE, without exposing it to the browser’s console.
That said, if you have sensitive data anywhere in the browser, someone will find it eventually, whether it’s printed or not.
You could make the text area only visible to you, not to other users. Better if the form with the text area is only visible to you.
The form should call a server function to show the content in the text area. That server function should check that the user is you. Don’t trust the user checks done on the form, because any respectable hacker could bypass any check done on the form and call that server function. No hacker (without your credentials) will be able to call that function pretending to be you.
Another way, that I use often, is to create a Log table and append your log messages to that table instead of to a text file. (Text files can disappear whenever the server does some housekeeping, so no, don’t rely on them.)
Now you have a Log table and you can use it to show its content on that text area, or you can use a second app that shares the same table to explore the log.
Well. I guess this could be a work around.
Is there a feature request for me to just “CTRL-A” to select all in the running app console.
I can do CTRL-A in the app session, but selects everything with CTRL-A
If i can CTRL-A while looking at server code that would at least speed up what I want to do and copy that to a notepad++ and quickly search what I need.
I just tried to go to logs and CTRL-A the running app console but this case, i can scan only the stuff in running app console but CTRL-C or right click copy is disabled.
I’ve noticed that too, but u can still copy it if you right-click it and then select copy.
weird, must be my mouse cause when I right click on it, the scanned selection disappears, and the copy menu comes up,
usually i have to manually scan from the beginning and when you have long logs, I have to wait a couple of minutes 2 to maybe 5 min to scan then copy, it starts to add up after running after a few times to debug something.
I did find a work around, as the console is executing you can scan it, then let go of the click, it will continue to scan , and it will scan to the end when the process is done executing. then ctrl-c
This is odd! If you’re updating the Media object in the database, then downloading it from the viewer ought to work! Can you describe more about how you’re generating this debug.txt
, or provide a cloneable example showing what’s going wrong here?
Here’s the code, I can save and view it in the text area but can’t download the file from tmp/debug.txt with updated logs, I restart to keep saving it but it does show in UI, just not saving in tmp/debug.txt
I had a quick look a your app, and it seems to be writing to a file in the tmp folder, which has nothing to do with the database.
If you want to work with a file-like object in the database, you need to follow these instructions: Anvil Docs | Files on Disk
If you want to work with an actual file in the tmp folder, you need to consider that the file will be eventually deleted (as I mentioned in my previous post).
Reading your posts I have the feeling that you are going to write a large amount of data in that log file. If this is the case, I wouldn’t work with a file-like object in the database, because that would mean that you keep reading the whole content from the database into a string, append something to it and write the whole string back to the database. This would be very slow if it happens often.
A better approach would be what I have mentioned earlier: add one row to a Log table. This way you only write (no need to read and append) and every transaction is smaller (it’s just the size of the current write rather than the full size of the log).
Ah, the thing you’re encountering is that Data Files is read-only by default! If you want to upload changes, you’ll want to do it explicitly (because of the reasons @stefano.menci talks about): write to the filesystem, then use anvil.media.from_file()
to turn it into a blob you can store in a database row.
An approach that might work, given that I believe you’re talking about a background task, would be to:
- For each background task execution, create a new temporary file (with a random name so that concurrent executions don’t collide)
- Write the data incrementally to that file
- At the end of the background task, read the file into a Media object with
anvil.media.from_file()
and add it as a new row to a logs table (perhaps with some other columns indicating information about the run, so you can find the right log later)
That way, you can log large amounts of information and organise it sensibly.
ok, i’ll try it out and report back