1 /*
2 * Copyright (c) 2024 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 "util/logger.h"
17 #include <cstdio>
18
19 namespace OHOS {
20 namespace Idl {
21 int Logger::level_ = DEBUG;
22
D(const char * tag,const char * format,...)23 void Logger::D(const char *tag, const char *format, ...)
24 {
25 if (level_ > DEBUG) {
26 return;
27 }
28
29 va_list args;
30 va_start(args, format);
31 Log(tag, format, args);
32 va_end(args);
33 }
34
E(const char * tag,const char * format,...)35 void Logger::E(const char *tag, const char *format, ...)
36 {
37 if (level_ > ERROR) {
38 return;
39 }
40
41 va_list args;
42 va_start(args, format);
43 Err(tag, format, args);
44 va_end(args);
45 }
46
V(const char * tag,const char * format,...)47 void Logger::V(const char *tag, const char *format, ...)
48 {
49 if (level_ > VERBOSE) {
50 return;
51 }
52
53 va_list args;
54 va_start(args, format);
55 Log(tag, format, args);
56 va_end(args);
57 }
58
Log(const char * tag,const char * format,va_list args)59 void Logger::Log(const char *tag, const char *format, va_list args)
60 {
61 (void)printf("[%s]: ", tag);
62 (void)vprintf(format, args);
63 (void)printf("\n");
64 }
65
Err(const char * tag,const char * format,va_list args)66 void Logger::Err(const char *tag, const char *format, va_list args)
67 {
68 (void)fprintf(stderr, "[%s]: ", tag);
69 (void)vfprintf(stderr, format, args);
70 (void)fprintf(stderr, "\n");
71 }
72 } // namespace Idl
73 } // namespace OHOS