[Toybox] [PATCH] new Android toy: log

enh enh at google.com
Tue Jun 21 15:29:09 PDT 2016


On Tue, Jun 21, 2016 at 2:13 PM, Rob Landley <rob at landley.net> wrote:
> 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().)

i just checked, and liblog (i.e. the choke point for all logging) will
silently truncate. i did consider writing this with xmprintf and just
leaving the guilt at liblog's door...

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

there's no public constant for that, and it's an implementation
detail, but, yeah, it's been 1024 for a long time.

> 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.

like i say each time this comes up :-) --- i need to be able to "make"
on the host to be able to run all your stuff to generate the generated
files. we could add bogus implementations to portability, but then you
end up with quite a lot of fake android crap in there...

(right now, half the toys/android directory has #if __ANDROID__, and
the other half is SELinux stuff that is likely to be useful to some
non-Android folks.)

> 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?)

yeah, i sincerely doubt anyone's ever used that. i was brave enough to
not document it, but not brave enough to remove it. maybe we should
just remove it and wait until someone notices instead?

> 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



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.



More information about the Toybox mailing list