commit | 1bfa8ab185f33039e91b0ba3f88290a3eea74ae6 | [log] [tgz] |
---|---|---|
author | Tom Cherry <tomcherry@google.com> | Wed Jan 08 14:47:42 2020 -0800 |
committer | Tom Cherry <tomcherry@google.com> | Tue Jan 21 11:05:24 2020 -0800 |
tree | f4b2a63563a6df374d136555957c843d40ec2060 | |
parent | a66b8e37ba24b27470c5e9a41bd3054ca34c3917 [diff] |
Move SetLogger and SetAborter from libbase to liblog libbase is copied into each APEX module which requires it, meaning that there may be multiple instances of libbase running within a single process with their own copy of libbase's globals. This means that SetLogger() and SetAborter() will only impact logs from the instance of libbase that calls it. This change moves this state to liblog, since it will only ever have one instance in a single process. One major side-effect here is that now both ALOGE style and LOG(...) style logs will be handled through the same logger function. For example, a logger specified through libbase's SetLogger() will now see logs sent to liblog through ALOGE(). This is intended behavior. A second side-effect is that libbase's stderr logger is used for all host logging now. It's simply a better logging default than the fake_log_device logger in liblog currently and makes ALOGE and LOG(...) logs on host follow the same format. Bug: 119867234 Test: libbase and liblog unit tests; logging works Change-Id: Ib52cbfb4e43749e50910ed19a993dffae19ace86
This library is a collection of convenience functions to make common tasks easier and less error-prone.
In this context, "error-prone" covers both "hard to do correctly" and "hard to do with good performance", but as a general purpose library, libbase's primary focus is on making it easier to do things easily and correctly when a compromise has to be made between "simplest API" on the one hand and "fastest implementation" on the other. Though obviously the ideal is to have both.
The intention is to cover the 80% use cases, not be all things to all users.
If you have a routine that's really useful in your project, congratulations. But that doesn't mean it should be here rather than just in your project.
The question for libbase is "should everyone be doing this?"/"does this make everyone's code cleaner/safer?". Historically we've considered the bar for inclusion to be "are there at least three unrelated projects that would be cleaned up by doing so".
If your routine is actually something from a future C++ standard (that isn't yet in libc++), or it's widely used in another library, that helps show that there's precedent. Being able to say "so-and-so has used this API for n years" is a good way to reduce concerns about API choices.
Unlike most Android code, code in libbase has to build for Mac and Windows too.
Code here is also expected to have good test coverage.
By its nature, it's difficult to change libbase API. It's often best to start using your routine just in your project, and let it "graduate" after you're certain that the API is solid.