Commit graph

23 commits

Author SHA1 Message Date
Elliott Hughes
1be0d1481b Add StdioLogger for command-line tools.
Bug: N/A
Test: ran tests
Change-Id: If366a4ea25aea1becdd3e443eba225e9bd52ebba
2018-05-23 10:06:20 -07:00
Andreas Gampe
1923e768ef Base: Add default tag manipulation
Allow the default tag (the program name) to be overwritten.

Bug: 34867873
Test: m
Test: logging_test
Test: manual
Change-Id: I4ef32bad413a7cc82e46ce16a2f26212925964b1
2018-03-06 14:45:11 -08:00
Dan Willemsen
528f144e77 Fix / suppress new unused warnings for mingw+clang
Bug: 69933068
Test: mmma system/core
Change-Id: I089166a979d3d8c5ada38a7745d507b555048499
2017-11-29 21:37:28 -08:00
Yabin Cui
0c68953778 base: support logging before enter main function.
Bug: http://b/30974760
Test: run libbase_test.

Change-Id: I3f45fc21e8fe6301b5fef027728ea91f2188911d
2017-01-25 15:50:47 -08:00
Wei Wang
8c176302e6 Move CapturedStderr to test_util library
Bug: 32181382
Test: run /data/nativetest(64)/binderTextOutputTest
Change-Id: Ifb2e1f6af2c3f57b5cbed7dde65efb31253c52a2
2016-10-22 10:35:21 -07:00
Andreas Gampe
b4e32f3b33 Base: Hand complete log message to aborter
Undo zero-termination-substitution for linebreaks when logging.
This results in handing the complete log message to the aborter.
Add a test.

Bug: 31893081
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I2ef6c6351db2fd494a02985f634f439104136227
2016-10-04 19:19:59 -07:00
Andreas Gampe
1f5fb43047 Base: Remove LOG_S variants.
Partially reverts commit 436f5a031f.

Remove the variants taking a fully qualified LogSeverity. Instead
use a lambda with "using" statements to translate both qualified
and unqualified names into valid expressions.

Compile-time regression was measured as 0.1s for a thousand LOG
statements on a z840.

Update tests.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I36fdf30a9d535b19543307b85d1b3c19a97f20dd
2016-09-24 10:18:38 -07:00
Andreas Gampe
19ff8f1e57 Base: Check severity in destructor
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: Ic077822bcfd591bd11f4fa9d4b6e440b461c70c1
2016-09-23 13:31:52 -07:00
Andreas Gampe
436f5a031f Base: Add more log macros
Add WOULD_LOG to determine whether a given severity would be logged.

Add LOG_STREAM to have direct access to a logging stream.

Add LOG_S variants that take a fully qualified severity. This allows
complex expressions as parameters, e.g., ternaries for conditional
severity levels.

Add tests.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I242b960594e68caff6db9cd8aaa4ce8aaf90474c
2016-09-22 12:47:40 -07:00
Andreas Gampe
d8f26e2ac9 Base: Fix dangling-else in CHECK_STROP
Follow-up to commit 2527628eda.

Bug: 26962895
Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: Ifd71314e146ebf3957cc053ee95ef85002c909b4
2016-09-13 14:16:37 -07:00
Andreas Gampe
2691e335fe Base: Add AbortFunction for logging
Add a hook to modify FATAL behavior. Add a test.

Bug: 31338270
Test: m
Test: mmma system/core/base && $ANDROID_HOST_OUT/nativetest64/libbase_test/libbase_test64
Change-Id: I966da319cda613738b3f2ccdac8c21900d6a5c72
2016-09-08 15:33:27 -07:00
Andreas Gampe
550829d84b Base: Add INTERNAL_FATAL to logging severity
Add the INTERNAL_FATAL level. It will print 'F' like FATAL, but
does not abort after logging.

Add a test to logging_test.

Bug: 31338270
Test: m
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: Idf74c08e8516881efccaefc58fa3f41d57e56396
2016-09-07 18:19:42 -07:00
Elliott Hughes
13d78e440a Clean up the libbase logging test.
Use ECMAscript regex syntax (the default!) for a simpler regex.

Also test the cartesian product of logging options, with less copy & paste
than the previous test of a subset.

Change-Id: I7aae91d276dbbb8de6173d18b5c1ceb01c1dff73
2016-09-07 16:22:40 -07:00
Andreas Gampe
7c1cdd7700 Base: Fix logging_test
Update the expected logging pattern.

Bug: 31338270
Test: mmma system/core/base && adb sync && adb shell /data/nativetest/libbase_test/libbase_test32
Change-Id: I299620669126bc0258cad6e30d5b40bff5ea92ad
2016-09-07 11:39:59 -07:00
Elliott Hughes
4f71319df0 Track rename of base/ to android-base/.
Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
2015-12-04 22:00:26 -08:00
Elliott Hughes
c96de0d36e Fix lseek argument order.
Change-Id: I12feed2de8a4e0782f90609254a3e2ec66d7d98e
2015-10-20 13:18:22 -07:00
Spencer Low
765ae6bcfc base logging: fix errno restoring, severity conditionality, dangling ifs
Fix LOG() to properly save and restore errno. Test this properly.

Only do logging if severity is >= the minimum.

Fix dangling if statements in CHECK(), CHECK_STR{EQ,NE}(). Test this
properly.

Fix base logging tests on Windows. All libbase_tests now pass on
Windows.

Change place to lock, so the lock can protect logging of all data in
LogMessage.

Change-Id: I7ff531c67ae10a99ef0a2bbfe279aa77282d5ae9
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-09-21 12:46:12 -07:00
Elliott Hughes
2e5ae0044a Fix the Mac libbase build.
Change-Id: I34224fa66850915ef47c88ef4c79efbc53f3f38e
2015-08-13 20:09:29 -07:00
Spencer Low
bdab59a861 libbase: logging fixes
Win32:

- getprogname(): call basename() which is available in mingw's crt.
  Don't potentially go recursive with DCHECK_GT().

- Use Win32 critical section instead of mutex.

Other:

- Change log_characters check to compile-time.

- Fix code that gets the basename of __FILE__. The previous code was not
  setting _file, so it didn't work.

- Save and restore errno for LOG calls. Inspired by similar Chromium code.

Change-Id: Ie7bb700918be726fa81d60177d1894d2daeff296
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2015-08-13 14:08:31 -07:00
Alex Vallée
47d67c96ec Write mkdirs in more idiomatic C++ style.
~ Rewrote mkdirs to be in C++ style.
~ Replaced adb_dir{start,stop} with std::string params and (r)find.
+ Added test for mkdirs.

Also make base/test_utils.h public and support temporary directories
as well as files.

Change-Id: I6fcbdc5e0099f3359d3aac6b00c436f250ca1329
2015-07-30 15:08:53 -07:00
Dan Albert
5c19040b06 Support base::logging on Windows.
libc++ doesn't support std::mutex and friends for Windows yet, so we
just use a compatibility wrapper for now.

Change-Id: I2413d4c089e7d0fb232444043c6b772153035dab
2015-04-29 18:01:53 -07:00
Dan Albert
b547c85b5b Support arbitrary loggers.
While the defaults (logd or stderr) make sense for most use cases,
there are places that can only log to the kernel, or need to log to a
file, etc.

Allow the user to pass in an arbitrary logging object, and provide
LogdLogger and StderrLogger as defaults.

Change-Id: I62368acc795ff313242bb205d65017404bf64e88
2015-04-03 16:22:39 -07:00
Dan Albert
58310b49fc Add google3 style logging to libbase.
ART already had a flavor of this, but it was specialized for their use
case a bit.

Note that the logging.* tests are currently disabled for the device
because there is no good way to capture the output of liblog. We can
make something that will execute logcat and then then scan the output,
but that's messy. Since we know it at least works on the host, we can
add better device tests later.

Change-Id: I47acd87a3312c0a5285b03f9c8dadef0c669f06a
2015-03-20 14:04:35 -07:00