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) return;
19
20 va_list args;
21 va_start(args, format);
22 Log(tag, format, args);
23 va_end(args);
24 }
25
E(const char * tag,const char * format,...)26 void Logger::E(const char* tag, const char* format, ...)
27 {
28 if (level_ > ERROR) return;
29
30 va_list args;
31 va_start(args, format);
32 Err(tag, format, args);
33 va_end(args);
34 }
35
V(const char * tag,const char * format,...)36 void Logger::V(const char* tag, const char* format, ...)
37 {
38 if (level_ > VERBOSE) return;
39
40 va_list args;
41 va_start(args, format);
42 Log(tag, format, args);
43 va_end(args);
44 }
45
Log(const char * tag,const char * format,va_list args)46 void Logger::Log(const char* tag, const char* format, va_list args)
47 {
48 (void)printf("[%s]: ", tag);
49 (void)vprintf(format, args);
50 (void)printf("\n");
51 }
52
Err(const char * tag,const char * format,va_list args)53 void Logger::Err(const char* tag, const char* format, va_list args)
54 {
55 (void)fprintf(stderr, "[%s]: ", tag);
56 (void)vfprintf(stderr, format, args);
57 (void)fprintf(stderr, "\n");
58 }
59 } // namespace HDI
60 } // namespace OHOS