• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CONSCRYPT_LOGGING_H_
18 #define CONSCRYPT_LOGGING_H_
19 
20 #include <conscrypt/macros.h>
21 
22 #define LOG_TAG "NativeCrypto"
23 
24 #ifndef CONSCRYPT_UNBUNDLED
25 
26 #include <log/log.h>
27 
28 #define CONSCRYPT_LOG(priority, tag, ...) ALOG(priority, tag, __VA_ARGS__)
29 #define CONSCRYPT_LOG_ERROR(...) ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)
30 #define CONSCRYPT_LOG_INFO(...) ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)
31 #if LOG_NDEBUG
32 #define CONSCRYPT_LOG_VERBOSE(...) ((void)0)
33 #else
34 #define CONSCRYPT_LOG_VERBOSE(...) ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
35 #endif  // LOG_DEBUG
36 
37 #elif defined(ANDROID) && !defined(CONSCRYPT_OPENJDK)  // !CONSCRYPT_UNBUNDLED
38 
39 #include <android/log.h>
40 #ifndef ALOG
41 #define ALOG(priority, tag, ...) __android_log_print(ANDROID_##priority, tag, __VA_ARGS__)
42 #endif
43 
44 #define CONSCRYPT_LOG(priority, tag, ...) ALOG(priority, tag, __VA_ARGS__)
45 #define CONSCRYPT_LOG_ERROR(...) ALOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)
46 #define CONSCRYPT_LOG_INFO(...) ALOG(LOG_INFO, LOG_TAG, __VA_ARGS__)
47 #if LOG_NDEBUG
48 #define CONSCRYPT_LOG_VERBOSE(...) ((void)0)
49 #else
50 #define CONSCRYPT_LOG_VERBOSE(...) ALOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
51 #endif
52 
53 #else  // !ANDROID
54 
55 // LOG_NDEBUG is an Android property that turns off verbose logging
56 #ifndef LOG_NDEBUG
57 #define LOG_NDEBUG 1
58 #endif
59 
60 #include <stdio.h>
61 
62 #define CONSCRYPT_LOG(priority, tag, ...) CONSCRYPT_##priority(__VA_ARGS__)
63 
64 #define CONSCRYPT_LOG_ERROR(...) {   \
65     fprintf(stderr, __VA_ARGS__);    \
66     fprintf(stderr, "\n");           \
67 }
68 #define CONSCRYPT_LOG_INFO(...) {    \
69     fprintf(stderr, __VA_ARGS__);    \
70     fprintf(stderr, "\n");           \
71 }
72 #if LOG_NDEBUG
73 #define CONSCRYPT_LOG_VERBOSE(...) ((void)0)
74 #else
75 #define CONSCRYPT_LOG_VERBOSE(...) { \
76     fprintf(stderr, __VA_ARGS__);    \
77     fprintf(stderr, "\n");           \
78 }
79 #endif  // LOG_NDEBUG
80 
81 #endif  // !ANDROID
82 
83 #endif  // CONSCRYPT_LOGGING_H_
84