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