Commit graph

33 commits

Author SHA1 Message Date
Tom Cherry
f2c2746aba Remove the monotonic option for logging
This has been around for ~5 years but there has been roughly no
adoption, so remove this as we clean up the logging code.

Future efforts may track the monotonic timestamp in all cases.

Test: logging unit tests
Change-Id: I55ed565669f923988e741f6b384141bba893630d
2020-05-06 13:37:33 -07:00
Tom Cherry
53d301c29b Remove thread safety from libbase logging / liblog
There are no libbase users that require thread safety for SetLogger,
SetAborter, or SetDefaultTag  and the equivalent liblog symbols are
unreleased, thus have effectively no users.

It is hard to imagine a scenario where a user would need to use these
functions in a multi-threaded program, and it is unreasonable for all
users to pay for thread safety for a vast minority of potential
scenarios. Thread safety implies less efficiency and necessarily means
that these functions are neither fork safe nor async-signal safe, and
we do have users who depend on those characteristics.

It is always possible for users of the non-thread safe versions of
these functions to build thread safe versions on top of them.  For
example, if a user needs a thread safe SetLogger(), they can use the
non-thread safe SetLogger at the start of their program to register a
logger that has its own lock and pointer to a logger function.

Bug: 119867234
Test: logging unit tests
Change-Id: I8afffec1a6957d3bda95502a4c59493e0c5049ce
2020-04-22 13:12:11 -07:00
Tom Cherry
1ff17fcebb liblog: return -EPERM if a log_is_loggable() returns false
This was the previous behavior, so retain it.

Bug: 119867234
Test: logging unit tests
Change-Id: I088f760cc274a4a42d72477eb4e2e8d23c613a8a
2020-04-16 12:55:30 -07:00
Tom Cherry
ebf43ad2d8 liblog: correct new APIs per the API review
1) Rename __android_logger_data to __android_log_message and rename
   __android_log_write_logger_data to
   __android_log_write_log_message. Move the const char* message
   argument into __android_log_message.
2) Add @param, @return, and "Available since API level 30." to the
   documentation of new functions.
3) Document that the user defined aborter should but may not abort.
4) Document the line separation is the responsibility of the log
   function provided to __android_log_set_logger().

Bug: 150898477
Test: build, liblog and libbase unit tests
Change-Id: I07c41011ef25b3e7cc4943f3f1e240a2f6aa2802
2020-03-25 18:36:10 +00:00
Tom Cherry
f1a975bece liblog: use int32_t and uint32_t for new NDK APIs
As requested during the API review.

Bug: 150898477
Test: liblog and libbase unit tests
Change-Id: I0c1dd57f7499e432bb881e1da1beb55f1ff7de05
2020-03-12 11:11:24 -07:00
Tom Cherry
bbb16022c7 liblog: minimum_log_priority should be atomic
In case multiple threads try to reference this variable while it is
being set, it should be atomic so that all threads always see a valid
value.

Bug: 150898477
Test: liblog, libbase unit tests
Change-Id: If6c9e291f2471b96a752dc6e76e3e63458b71391
2020-03-09 12:43:18 -07:00
Tom Cherry
3574c37f98 liblog: add __attribute__((uninitialized)) to liblog buffers
These buffers are immediately written into with *printf() and are in
the hot path, so do not initialize them.  This saves ~70ns off of each
log message, which is ~14% of the overhead within
__android_log_print() when writing to a no-op logger.

Test: liblog benchmarks
Change-Id: I2b898e72c75b57bc63fee565b49a4e00e377ed1a
2020-02-21 16:37:43 -08:00
Tom Cherry
f48f685e60 liblog: do not allow loggers to write to binary buffers
Do not write to binary buffers, this was already done for logd,
but wasn't explicitly done for other loggers, so do that too.

Test: unit tests
Change-Id: Ia36e0d2e1b6c833780239a5ef459abea99bc4a1f
2020-01-28 13:07:11 -08:00
Tom Cherry
e2187bfbbc liblog: remove fake_log_device
This is now dead code as __android_log_stderr_logger() has superseded it.

Bug: 147496863
Test: build
Change-Id: Ibdea2961ec4fc093bf9e35581dc1c46db2cff06a
2020-01-28 10:42:02 -08:00
Tom Cherry
ff464b1288 liblog: always restore errno in logging functions
Some recent changes can have these logging functions potentially set
errno.  This change places android::base::ErrnoRestorer at the entry
point of the public functions where we want to guarantee errno is
restored to ensure this will not happen again.

Test: build
Change-Id: Iab4170ab16b9c7301474a509ee42d38b370b91a4
2020-01-27 13:50:44 -08:00
Tom Cherry
2ec6a53a46 liblog: use default tag for loggability checks if no tag is provided
Bug: 116329414
Bug: 119867234
Test: new unit tests
Change-Id: I92a3f4f95e5f482f6fe20f17ed83c8ed367b06dc
2020-01-27 09:38:54 -08:00
Tom Cherry
69ee5dde99 Move default tag from libbase to liblog
Bug: 119867234
Test: log tags look right, libbase/liblog unit tests
Change-Id: I3670c3fdce3d0238a23a53bba2877ffed1291f9c
2020-01-23 08:39:31 -08:00
Tom Cherry
96e7ef5ec1 liblog: check loggability before formatting
Only print logs with priority >= INFO on host, as fake_log_device
does.

This fixes a regression in host builds where loggability wasn't
checked at all.

Bug: 69935292
Test: ART host tests don't print extraneous logs
Change-Id: I885b794da6f24bd905192252925e4a9f88b06674
2020-01-22 08:49:59 -08:00
Tom Cherry
0391a879f7 Move minimum log priority from libbase to liblog
See the previous commit moving SetLogger and SetAborter to liblog for
motivation.

This creates more harmony between the two mechanisms in libbase and
liblog for checking loggability.
Currently:
1) libbase filters all messages based on its minimum log priority. For
   example, if minimum log priority in libbase remained at its
   default, but a tag was specifically opted into DEBUG logs via
   log.tag.<tag>, libbase would not print this log.
2) liblog ignores libbase's minimum log priority.  For example if a
   process called SetMinimumLogPriority(WARNING) but used a library
   that logged via liblog's ALOGI macro, that log would still be
   printed even though the process intends on filtering out those INFO
   messages.

With this change:
1) If both a minimum log priority and a priority through log.tag.<tag>
   are set, then the lower of the two values is used.
2) If only one or the other is set, then that value is used.  This
   fixes the two issues described above.
3) If neither of these values are set, then the default of using INFO
   is unchanged.

Bug: 116329414
Bug: 119867234
Test: libbase and liblog minimum log priority tests
Change-Id: Icb49b30b9d93bf797470e23730ae9e537931bb6c
2020-01-21 12:14:43 -08:00
Tom Cherry
349b0c43ad 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
2020-01-21 11:05:24 -08:00
Tom Cherry
121292dd81 liblog: use libbase_headers for TEMP_FAILURE_RETRY
Test: build
Change-Id: Id3b57ff0327d4632e91960e5e70f3aa21992ed15
2020-01-14 09:56:25 -08:00
Tom Cherry
b47aa2a592 liblog: remove more unused code
Cleanup the headers; we really don't want to encourage any more
cutils/list.h usage...

Remove __android_log_uid() since the only remaining users are built
for device, so they can just use getuid() directly.

Test: build
Change-Id: I62be2c1e43d83807deaa9342afcc72459947cf15
2020-01-08 17:11:09 -08:00
Tom Cherry
21bb36c66a liblog: remove the last of the transport structs
Test: build, liblog unit tests
Change-Id: I292662fc64e3163b570c5daeaa8f912fb6ca74e8
2020-01-08 17:11:06 -08:00
Tom Cherry
06e0fced63 liblog: have writers handle their own state
Remove the transport available and open functions since the writers
are able to manage their own state.  Remove the initialization dance
with write_to_log, since it is unneeded once this is removed as well.

Remove the global lock around the close() functions as correct locking
has been added to the writers in a previous change.

Test: logging works, liblog-unit-tests
Change-Id: If7fa11e773763d0b5fcb2e696ad1c88ff4a4cfdf
2019-12-12 16:19:08 -08:00
Tom Cherry
49a8af7dff liblog: do not check loggability of event logs before sending to logd
This code was introduced to help performance by skipping sending these
messages to logd when logd would later drop them.  However it has
multiple flaws:

1) Event logs aren't super common and non-loggable event logs are even
   less common, so it would be a trivial benefit if any.
2) This code is not particularly safe as written, which is even
   acknowledged in the comments.
3) This forces processes that write event logs to allocate a rather
   sizable amount of memory.

Therefore, it's better to simply remove this and let logd drop these
messages when it receives them.

Bug: 139705697
Test: logging works, liblog-unit-tests
Change-Id: Ide01574112e173d4922137b3d3868cf8c2c09086
2019-12-11 15:46:47 -08:00
Tom Cherry
990852ff7d liblog: remove superfluous checks
More checks in static functions where all callers always satisfy them.

Test: build
Change-Id: I3c9bd1fd4e5c55a2f9f2c42d5259c5cdd8f8a853
2019-10-02 14:27:04 -07:00
Tom Cherry
97ec4eecd4 liblog: don't set transports to nullptr when they close
The old code did not free the transports, just unlink their nodes from
the linked list, so there was no race condition between close() and
other threads writing to the logs.  By settings these to nullptr, I
introduced a race condition, but setting them to nullptr isn't
necessary, so let's simply not do that.

Test: liblog-unit-tests
Change-Id: Iec0b680addd13b5d30bd91ccef5bdeab6bf797b0
2019-10-02 14:22:07 -07:00
Tom Cherry
2187a41586 liblog: fix prio and tag validation code
These checks are not needed; all callers are in this file and there's
only one possible situation: that we have valid pointers and sizes.

Test: liblog-unit-tests, log.tag.* properties still work
Change-Id: I8b385d5124c2d93cd99a352e30f745b075c8bd09
2019-10-01 17:13:43 -07:00
Tom Cherry
2beabe5c26 liblog: remove config_write.cpp/.h
Now that we only have one transport in a given build configuration,
there is no need to have these lists.

Test: liblog-unit-tests
Change-Id: I3fdcdc33c1224a9522080ea06f36f14c83d946ac
2019-10-01 13:05:58 -07:00
Tom Cherry
9d35034437 liblog: remove log/log_transport.h
There are no users; future versions will need to be more generic to
support the libbase style Logger/Aborter options.

Test: build, liblog-unit-tests
Change-Id: Ia4571cd39d3e499f18306920ecbf40ea8878fb81
2019-10-01 08:14:40 -07:00
Tom Cherry
2238ce2d7f liblog: remove stderr logger
There are no users of the liblog stderr logger, but 66 users of
android::base::StderrLogger.  We'll prefer that format and work to
merge it into liblog.

Test: liblog-unit-tests
Change-Id: Ifad24b27ac0f51379b925f6644caa1f6f3d9ad81
2019-09-30 13:51:09 -07:00
Tom Cherry
7d045f6b74 liblog: add -Wall,-Wextra and do related clean-up.
Test: build
Change-Id: I3b33f2b896cb8bf7ad9edf110d1739d559028282
2019-09-30 12:58:55 -07:00
Tom Cherry
f7e1b1ebd4 liblog: only allow one transport for reading
liblog has left over code from local_logger that allows for reading
from multiple sources and merging the contents.  Since we've already
removed local_logger, this change removes the rest of this code.

Test: liblog-unit-tests
Change-Id: I5685ad6c1e7cbcaa0a660ed10f47714784a40791
2019-08-26 19:50:32 -07:00
Elliott Hughes
de3ad1d718 Remove an ancient spam-busting hack from logd.
We have real spam detection and suppression now anyway.

Bug: 20143912
Test: build
Change-Id: I7bd4bb189373569fd1e5a7b3f2b90ce816abe864
2019-07-08 11:10:11 -07:00
Yi Kong
dd2ea5fd68 Suppress -Wstring-plus-int warning
The code section is already marked as to be removed, simply suppress
the -Wstring-plus-int warning.

Test: m checkbuild
Bug: 128878287
Change-Id: I95a03aca90dbb5d27db49f5baf534cbaacf9b830
2019-03-18 22:16:14 -07:00
Tom Cherry
2d9779e87b liblog: remove visibility macros
Visibility is managed through version scripts now.

Bug: 123349183
Test: build
Change-Id: Ia388611a2ec14d0ff9c3896cfe97ccdce17dbb8b
2019-02-08 11:48:19 -08:00
Tom Cherry
6f6ef39b48 Remove liblog/uio.c and <log/uio.h>
readv() isn't used by anyone, writev() has one easily replaced user.
uio.h can be left as a private header for windows compatibility with
struct iovec.

Test: build
Change-Id: I33d4c6bdee6fd818271f78ae06abdd2aa09430f2
2019-01-16 14:26:36 -08:00
Tom Cherry
71ba16488b liblog: convert to C++
Bug: 119867234
Test: liblog, logcat, logd unit tests

Change-Id: I2a33b6fc37f9860c0041e3573bfb59ea389f623c
2019-01-15 15:57:33 -08:00
Renamed from liblog/logger_write.c (Browse further)