1 /*
2 * Copyright (c) 2020-2021 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
16 #include "ace_log.h"
17 #include <stdarg.h>
18 #include <stdio.h>
19 #if defined(TARGET_SIMULATOR) && (TARGET_SIMULATOR == 1)
20 #include <string>
21
22 namespace OHOS {
23 namespace ACELite {
24 using namespace std;
ReplaceHiLogPrivacyKeyWords(string & original,const string & toBeReplaced,const string & targetStr)25 void ReplaceHiLogPrivacyKeyWords(string &original, const string &toBeReplaced, const string &targetStr)
26 {
27 string::size_type toBeReplacedLen = toBeReplaced.length();
28 do {
29 string::size_type foundPos = original.find(toBeReplaced);
30 if (foundPos == string::npos) {
31 // replace all end
32 break;
33 }
34 // replace to target
35 original.replace(foundPos, toBeReplacedLen, targetStr);
36 } while (1);
37 }
38
PrintInfo(const char * format,va_list args)39 void PrintInfo(const char *format, va_list args)
40 {
41 string originalStr(format);
42 string toBeReplacedStr("{public}");
43 string emptyStr("");
44 ReplaceHiLogPrivacyKeyWords(originalStr, toBeReplacedStr, emptyStr);
45 vprintf(originalStr.c_str(), args);
46 printf("\n");
47 }
48
HILOG_FATAL(HiLogModuleType mod,const char * msg,...)49 void HILOG_FATAL(HiLogModuleType mod, const char *msg, ...)
50 {
51 (void)(mod);
52 printf("[ACELite][FATAL]:");
53 va_list args;
54 va_start(args, msg);
55 PrintInfo(msg, args);
56 va_end(args);
57 }
58
HILOG_ERROR(HiLogModuleType mod,const char * msg,...)59 void HILOG_ERROR(HiLogModuleType mod, const char *msg, ...)
60 {
61 (void)(mod);
62 printf("[ACELite][ERROR]:");
63 va_list args;
64 va_start(args, msg);
65 PrintInfo(msg, args);
66 va_end(args);
67 }
68
HILOG_INFO(HiLogModuleType mod,const char * msg,...)69 void HILOG_INFO(HiLogModuleType mod, const char *msg, ...)
70 {
71 (void)(mod);
72 printf("[ACELite][INFO]:");
73 va_list args;
74 va_start(args, msg);
75 PrintInfo(msg, args);
76 va_end(args);
77 }
78
HILOG_WARN(HiLogModuleType mod,const char * msg,...)79 void HILOG_WARN(HiLogModuleType mod, const char *msg, ...)
80 {
81 (void)(mod);
82 printf("[ACELite][WARN]:");
83 va_list args;
84 va_start(args, msg);
85 PrintInfo(msg, args);
86 va_end(args);
87 }
88
HILOG_DEBUG(HiLogModuleType mod,const char * msg,...)89 void HILOG_DEBUG(HiLogModuleType mod, const char *msg, ...)
90 {
91 (void)(mod);
92 printf("[ACELite][DEBUG]:");
93 va_list args;
94 va_start(args, msg);
95 PrintInfo(msg, args);
96 va_end(args);
97 }
98 } // namespace ACELite
99 } // namespace OHOS
100 #endif // TARGET_SIMULATOR
101