1 /*
2 * Copyright 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <keymaster/logger.h>
18
19 namespace keymaster {
20
21 Logger* Logger::instance_ = nullptr;
22
23 /* static */
24 // NOLINTNEXTLINE(cert-dcl50-cpp)
Log(LogLevel level,const char * fmt,va_list args)25 int Logger::Log(LogLevel level, const char* fmt, va_list args) {
26 if (!instance_) return 0;
27 return instance_->log_msg(level, fmt, args);
28 }
29
30 /* static */
31 // NOLINTNEXTLINE(cert-dcl50-cpp)
Log(LogLevel level,const char * fmt,...)32 int Logger::Log(LogLevel level, const char* fmt, ...) {
33 va_list args;
34 va_start(args, fmt);
35 int result = Log(level, fmt, args);
36 va_end(args);
37 return result;
38 }
39
40 /* static */
41 // NOLINTNEXTLINE(cert-dcl50-cpp)
Debug(const char * fmt,...)42 int Logger::Debug(const char* fmt, ...) {
43 va_list args;
44 va_start(args, fmt);
45 int result = Log(DEBUG_LVL, fmt, args);
46 va_end(args);
47 return result;
48 }
49
50 /* static */
51 // NOLINTNEXTLINE(cert-dcl50-cpp)
Info(const char * fmt,...)52 int Logger::Info(const char* fmt, ...) {
53 va_list args;
54 va_start(args, fmt);
55 int result = Log(INFO_LVL, fmt, args);
56 va_end(args);
57 return result;
58 }
59
60 /* static */
61 // NOLINTNEXTLINE(cert-dcl50-cpp)
Warning(const char * fmt,...)62 int Logger::Warning(const char* fmt, ...) {
63 va_list args;
64 va_start(args, fmt);
65 int result = Log(WARNING_LVL, fmt, args);
66 va_end(args);
67 return result;
68 }
69
70 /* static */
71 // NOLINTNEXTLINE(cert-dcl50-cpp)
Error(const char * fmt,...)72 int Logger::Error(const char* fmt, ...) {
73 va_list args;
74 va_start(args, fmt);
75 int result = Log(ERROR_LVL, fmt, args);
76 va_end(args);
77 return result;
78 }
79
80 /* static */
81 // NOLINTNEXTLINE(cert-dcl50-cpp)
Severe(const char * fmt,...)82 int Logger::Severe(const char* fmt, ...) {
83 va_list args;
84 va_start(args, fmt);
85 int result = Log(SEVERE_LVL, fmt, args);
86 va_end(args);
87 return result;
88 }
89
90 } // namespace keymaster
91