1 /*
2 * Copyright (c) 2022 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 BT_VENDOR_LOG_H
16 #define BT_VENDOR_LOG_H
17 #include <stdarg.h>
18 #include <stdio.h>
19 #include "hilog/log.h"
20 #include "time.h"
21
22 #ifdef VENDOR_DEBUG_2_FILE
Print(const char * fmt,...)23 static void Print(const char *fmt, ...)
24 {
25 FILE *fp = fopen("/data/btvendor.log", "a+");
26
27 int nFileLen = ftell(fp);
28
29 int ret;
30 char buf[1024] = {0};
31 if (fp != 0) {
32 time_t timep;
33 time(&timep);
34
35 struct tm *p;
36 p = gmtime(&timep);
37 ret = sprintf(
38 buf, "%04d-%02d-%02d %02d:%02d:%02d VENDOR:", 0X76C + p->tm_year,
39 1 + p->tm_mon, p->tm_mday, 0X8 + p->tm_hour, p->tm_min, p->tm_sec);
40 fwrite(buf, 1, ret, fp);
41
42 va_list ap;
43 va_start(ap, fmt);
44 ret = vsprintf(buf, fmt, ap);
45 va_end(ap);
46
47 buf[ret] = '\n';
48 fwrite(buf, 1, ret + 1, fp);
49 }
50 fclose(fp);
51 }
52
53 #define HILOGD(...) Print(__VA_ARGS__)
54 #define HILOGI(...) Print(__VA_ARGS__)
55 #define HILOGW(...) Print(__VA_ARGS__)
56 #define HILOGE(...) Print(__VA_ARGS__)
57
58 #else
59
60 #define HILOGD(...) \
61 HiLogPrint(LOG_CORE, LOG_DEBUG, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__)
62 #define HILOGI(...) \
63 HiLogPrint(LOG_CORE, LOG_INFO, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__)
64 #define HILOGW(...) \
65 HiLogPrint(LOG_CORE, LOG_WARN, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__)
66 #define HILOGE(...) \
67 HiLogPrint(LOG_CORE, LOG_ERROR, LOG_DOMAIN, "BTVENDOR", __VA_ARGS__)
68 #endif
69
70 #endif // #define BT_VENDOR_LOG_H