1 /*
2 * Copyright (c) 2024, The OpenThread Authors.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of the copyright holder nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <openthread-core-config.h>
30 #include <openthread/config.h>
31
32 #include <assert.h>
33 #include <stdarg.h>
34 #include <stdint.h>
35 #include <stdio.h>
36
37 #include <openthread/platform/logging.h>
38
39 #include <log/log.h>
40
41 #if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
otPlatLog(otLogLevel aLogLevel,otLogRegion aLogRegion,const char * aFormat,...)42 void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
43 {
44 OT_UNUSED_VARIABLE(aLogRegion);
45
46 va_list args;
47 android_LogPriority priority;
48
49 switch (aLogLevel)
50 {
51 case OT_LOG_LEVEL_NONE:
52 priority = ANDROID_LOG_SILENT;
53 break;
54 case OT_LOG_LEVEL_CRIT:
55 priority = ANDROID_LOG_FATAL;
56 break;
57 case OT_LOG_LEVEL_WARN:
58 priority = ANDROID_LOG_WARN;
59 break;
60 case OT_LOG_LEVEL_NOTE:
61 case OT_LOG_LEVEL_INFO:
62 priority = ANDROID_LOG_INFO;
63 break;
64 case OT_LOG_LEVEL_DEBG:
65 priority = ANDROID_LOG_DEBUG;
66 break;
67 default:
68 assert(false);
69 priority = ANDROID_LOG_DEBUG;
70 break;
71 }
72
73 va_start(args, aFormat);
74 __android_log_vprint(priority, LOG_TAG, aFormat, args);
75 va_end(args);
76 }
77
platformLoggingInit(const char * aName)78 void platformLoggingInit(const char *aName)
79 {
80 otPlatLog(OT_LOG_LEVEL_INFO, OT_LOG_REGION_PLATFORM, "OpenThread logs");
81 otPlatLog(OT_LOG_LEVEL_INFO, OT_LOG_REGION_PLATFORM, "- Program: %s", aName);
82 }
83 #else
platformLoggingInit(const char * aName)84 void platformLoggingInit(const char *aName) { OT_UNUSED_VARIABLE(aName); }
85 #endif // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
86
platformLoggingSetFileName(const char * aName)87 void platformLoggingSetFileName(const char *aName) { OT_UNUSED_VARIABLE(aName); }
platformLoggingDeinit(void)88 void platformLoggingDeinit(void) {}
89