1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 *
4 * HDF is dual licensed: you can use it either under the terms of
5 * the GPL, or the BSD license, at your option.
6 * See the LICENSE file in the root of this repository for complete details.
7 */
8
9 #include "util/logger.h"
10 #include <cstdio>
11
12 namespace OHOS {
13 namespace HDI {
14 int Logger::level_ = DEBUG;
15
D(const char * tag,const char * format,...)16 void Logger::D(const char *tag, const char *format, ...)
17 {
18 if (level_ > DEBUG) {
19 return;
20 }
21
22 va_list args;
23 va_start(args, format);
24 Log(tag, format, args);
25 va_end(args);
26 }
27
E(const char * tag,const char * format,...)28 void Logger::E(const char *tag, const char *format, ...)
29 {
30 if (level_ > ERROR) {
31 return;
32 }
33
34 va_list args;
35 va_start(args, format);
36 Err(tag, format, args);
37 va_end(args);
38 }
39
V(const char * tag,const char * format,...)40 void Logger::V(const char *tag, const char *format, ...)
41 {
42 if (level_ > VERBOSE) {
43 return;
44 }
45
46 va_list args;
47 va_start(args, format);
48 Log(tag, format, args);
49 va_end(args);
50 }
51
Log(const char * tag,const char * format,va_list args)52 void Logger::Log(const char *tag, const char *format, va_list args)
53 {
54 (void)printf("[%s]: ", tag);
55 (void)vprintf(format, args);
56 (void)printf("\n");
57 }
58
Err(const char * tag,const char * format,va_list args)59 void Logger::Err(const char *tag, const char *format, va_list args)
60 {
61 (void)fprintf(stderr, "[%s]: ", tag);
62 (void)vfprintf(stderr, format, args);
63 (void)fprintf(stderr, "\n");
64 }
65 } // namespace HDI
66 } // namespace OHOS