1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef _INTEROP_LGGING_H 16 #define _INTEROP_LGGING_H 17 18 #ifdef __cplusplus 19 #include <cstdio> 20 #include <cstdint> 21 #include <cassert> 22 #else 23 #include <stdio.h> 24 #include <stdint.h> 25 #include <assert.h> 26 #endif 27 28 #if defined(KOALA_OHOS) 29 #include "oh_sk_log.h" 30 #define LOG(msg) OH_SK_LOG_INFO(msg); 31 #define LOGI(msg, ...) OH_SK_LOG_INFO_A(msg, ##__VA_ARGS__); 32 #define LOGE(msg, ...) OH_SK_LOG_ERROR_A(msg, ##__VA_ARGS__); 33 #define LOG_PUBLIC "{public}" 34 #else 35 #define LOG(msg) fprintf(stdout, msg "\n"); 36 #define LOGI(msg, ...) fprintf(stdout, msg "\n", ##__VA_ARGS__); 37 #define LOGE(msg, ...) fprintf(stderr, msg "\n", ##__VA_ARGS__); 38 #define LOG_PUBLIC "" 39 #endif 40 41 #if defined(KOALA_WINDOWS) 42 #define INTEROP_API_EXPORT __declspec(dllexport) 43 #else 44 #define INTEROP_API_EXPORT __attribute__((visibility("default"))) 45 #endif 46 47 #ifndef ASSERT 48 #define ASSERT(expression) assert(expression) 49 #endif 50 51 // Grouped logs. Keep consistent with type in ServiceGroupLogger 52 typedef struct GroupLogger { 53 void (*startGroupedLog)(int kind); 54 void (*stopGroupedLog)(int kind); 55 void (*appendGroupedLog)(int kind, const char* str); 56 const char* (*getGroupedLog)(int kind); 57 int (*needGroupedLog)(int kind); 58 } GroupLogger; 59 60 extern "C" INTEROP_API_EXPORT const GroupLogger* GetDefaultLogger(); 61 62 #endif // _INTEROP_LOGGING_H