[Toybox] [PATCH] new Android toy: log

Rob Landley rob at landley.net
Tue Jun 21 14:13:50 PDT 2016


On 06/20/2016 07:41 PM, enh wrote:
> the logging library will actually silently truncate long strings, so
> it might make sense to have something like "if (strlen(toybuf) > 1024)
> break;" in the main loop. but i doubt anyone will ever notice the
> difference...

It seems to me like the break should emit a warning to stderr that it
was truncated. (Silent loss of data makes me uncomfortable. That said,
failure to log because string too long also seems wrong, which is what
xstrncat() will do at 4k when it calls error_exit().)

Is 1024 the specific value the logging library will truncate at, or an
approximation?

Let's see, cleanup comments:

Don't #ifdef ANDROID on something that already depends on
TOYBOX_ON_ANDROID, we only compile it when it's buildable (compile-time
probes set the symbol). Typing "make log" at the command line assumes
you know what you're doing, and building an empty command isn't an
improvement.

Re-wordwrapped help text and added *. (If we recognize it, we should
document it, although don't you have to quote * to avoid shell
wildcarding it?)

Turned the case statement into a stridx and array dereference. Made the
error message say what string we got rather than "?".

Added  the above "truncate and warn" behavior at 1024. Had the error
message say "cut" rather than "truncate" because non-english speakers
and up-goer 5. :)

That said, I can't test this so it's entirely possible I broke it. (I
REALLY need to set up an android dev environment to properly participate
in "N"...)

Rob



More information about the Toybox mailing list