1.. _module-pw_log_android: 2 3============== 4pw_log_android 5============== 6.. pigweed-module:: 7 :name: pw_log_android 8 9``pw_log_android`` is a ``pw_log`` backend for Android. 10 11-------- 12Overview 13-------- 14``pw_log_android`` is a ``pw_log`` backend that directs logs to the `Android 15logging system <https://developer.android.com/tools/logcat>`_ (``liblog``). 16It's the default logging backend selected by the ``pw_android_common_backends`` 17rule. See :ref:`module-pw_build_android-common-backends`. 18 19.. _module-pw_log_android-stderr: 20 21Logging to standard error 22========================= 23By default, logs are written to ``logd`` (the logger daemon) and can be viewed 24using the ``logcat`` command-line tool. This is useful for system services. 25 26Logs can alternatively be written directly to *standard error* (stderr), which 27is useful for short-lived command-line utilities. Pigweed facilitates this by 28providing the ``pw_log_android_stderr`` library. Include it in your executable 29via ``whole_static_libs`` as seen here: 30 31.. code-block:: javascript 32 33 cc_binary { 34 name: "my_app", 35 host_supported: true, 36 vendor: true, 37 defaults: [ 38 "pw_android_common_backends", 39 ], 40 srcs: [ 41 "main.cc", 42 ], 43 whole_static_libs: [ 44 "pw_log_android_stderr", 45 ], 46 } 47 48.. warning:: 49 50 ``pw_log_android_stderr`` should only be used in executables 51 (``cc_binary``). 52 53 Using it with a library would affect the logging behavior for all consumers 54 of that library. 55 56 57Log level mapping 58================= 59This table shows the mapping of Pigweed log levels to 60`Android log levels <https://developer.android.com/ndk/reference/group/logging>`_. 61 62.. list-table:: Log level mapping 63 :align: left 64 :header-rows: 1 65 66 * - Pigweed level 67 - Android level 68 * - DEBUG 69 - ``ANDROID_LOG_DEBUG`` 70 * - INFO 71 - ``ANDROID_LOG_INFO`` 72 * - WARN 73 - ``ANDROID_LOG_WARN`` 74 * - ERROR 75 - ``ANDROID_LOG_ERROR`` 76 * - CRITICAL 77 - ``ANDROID_LOG_ERROR`` 78 * - FATAL 79 - ``ANDROID_LOG_FATAL`` 80