• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <stdio.h>
20 
21 #include <keymaster/logger.h>
22 
23 #define LOG_TAG "trusty_keymaster"
24 #define KEYMASTER_LOG_LEVEL WARNING_LVL
25 
26 namespace keymaster {
27 
28 class TrustyLogger : public Logger {
29 public:
initialize()30     static void initialize() { set_instance(new (std::nothrow) TrustyLogger); }
31 
log_msg(LogLevel level,const char * fmt,va_list args)32     virtual int log_msg(LogLevel level, const char* fmt, va_list args) const {
33         if (level < KEYMASTER_LOG_LEVEL) {
34             return 0;
35         }
36 
37         int retval;
38         switch (level) {
39         case DEBUG_LVL:
40             retval = fprintf(stderr, "%s (debug): ", LOG_TAG);
41             break;
42         case INFO_LVL:
43             retval = fprintf(stderr, "%s (info): ", LOG_TAG);
44             break;
45         case WARNING_LVL:
46             retval = fprintf(stderr, "%s (warn): ", LOG_TAG);
47             break;
48         case ERROR_LVL:
49             retval = fprintf(stderr, "%s (err): ", LOG_TAG);
50             break;
51         case SEVERE_LVL:
52             retval = fprintf(stderr, "%s (severe): ", LOG_TAG);
53             break;
54         default:
55             retval = fprintf(stderr, "%s (critical): ", LOG_TAG);
56             break;
57         }
58         retval += vfprintf(stderr, fmt, args);
59         retval += fprintf(stderr, "\n");
60         return retval;
61     }
62 };
63 
64 }  // namespace keymaster
65