-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stdout , stderr redirection and related issues #130
Comments
after fixing the issue with the permission the file is created - but println() still writes to syslog instead of writing to my file :( Any idea what did go wrong there or how to debug? |
after digging into it I am a bit surprised that the output of VAB apps goes into system logs at all. Stackoverflow and other places mention that stdout and stderr from NDK apps goes to /dev/null - which would be the behaviour I see with C.perror() |
Only thing I know is that we override printf in a macro |
On Wed, 13 Oct 2021 14:41:47 -0700 Larpon ***@***.***> wrote:
Only thing I know is that [we override printf in a
macro](https://github.com/vlang/v/blob/master/thirdparty/sokol/sokol_v.pre.h#L17)
thanks, that would explain almost everything. perror() isn't affected
by this macro so it outputs to /dev/null unless stderr is redefined
like in my code snippet.
After redirecting stderr the output of perror goes into the file as
expected, as well as the final panic message of the app and some other
messages - apparently not everything uses the printf macro.
But - if I want println and eprintln to use the "original" printf, what
would be the best way to undefine/redefine this overridden printf macro?
|
It was made initially to speed up development on Android - since otherwise I had to work "in the dark" which wasn't fun 😅 I'm still not sure what we should do to make a better solution. It's nice for developers to be able to use println and eprintln seamlessly on Android while developing apps. Maybe we can use some compiletime define to switch it off 🤔 |
Not sure either. Redirecting stdin and stderr to a file on /sdcard like I did is easy and has the advantage that the output can be examined without adb and all low-level io output routines work as well. To send stdout etc to syslog properly people do complicated things like https://codelab.wordpress.com/2014/11/03/how-to-use-standard-output-streams-for-logging-in-android-apps/ This has the advantage that it catches all output unlike the current macro hack and if someone like me wants to redirect it to a file it should work just like on Linux. The only disadvantage is complexity.. never tried it myself and not sure how robust that is. The current hack is good enough most of the time but it would be nice if it would switch real printf and android logging based for example on a global c variable. The way the macro interacts with the print definition in builtin/buitlin.c.v is fairly convoluted so I am not sure how to do it but perhaps something like
This would have the advantage that something would always work and is easy enough to revert to "normal" behavior. |
I did test the last variant - use a global c variable to switch between current redirect to log macro and normal stdout/stderr output which can be redirected as expected. So unless the developer does The patch bellow does that, the only little problem is that it generates an innocent warning which I haven't yet figured out how to fix. Please feel free to reuse and improve, no copyright considerations attached.
To redirect stdout/stderr from an app to a file on SDCARD you could do something like
|
@xandro0777 - I'm trying to figure out how we fix it the best way. My initial idea is to disable it in V itself and then enable it in vab per default - and then add a flag to vab: The reason for not disabling it per default is that it's used a lot by developers and is somewhat expected for end-users that Later I can add it as an ENV flag (maybe when I get to #125 ) and via |
Good enough for me. Having it switchable at runtime would be slightly better if something goes unexpectedly wrong during early initialization.
Was also thinking about automatic switching at runtime, in principle it is possible to check whether stdout has been recognized and either send output to log or the redefined stdout. However that would involve an extra syscall for every println operation and I didn't even check whether that syscall is available in the SDK.
|
Right. 🤔 let's start out with just the define/flag switch. I've PR'ed the initial changes to V - we'll see if anyone has any better ideas 👍 |
I tried to redirect stdout+stderr to a file like this:
Apparently that fails with EACCES because the app doesn't have the permission. not unexpected.
However, the C.perror() message doesn't come, while the println does its job. What could be the problem?
The text was updated successfully, but these errors were encountered: