logger.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <keymaster/logger.h>
  17. namespace keymaster {
  18. Logger* Logger::instance_ = nullptr;
  19. /* static */
  20. int Logger::Log(LogLevel level, const char* fmt, va_list args) {
  21. if (!instance_)
  22. return 0;
  23. return instance_->log_msg(level, fmt, args);
  24. }
  25. /* static */
  26. int Logger::Log(LogLevel level, const char* fmt, ...) {
  27. va_list args;
  28. va_start(args, fmt);
  29. int result = Log(level, fmt, args);
  30. va_end(args);
  31. return result;
  32. }
  33. /* static */
  34. int Logger::Debug(const char* fmt, ...) {
  35. va_list args;
  36. va_start(args, fmt);
  37. int result = Log(DEBUG_LVL, fmt, args);
  38. va_end(args);
  39. return result;
  40. }
  41. /* static */
  42. int Logger::Info(const char* fmt, ...) {
  43. va_list args;
  44. va_start(args, fmt);
  45. int result = Log(INFO_LVL, fmt, args);
  46. va_end(args);
  47. return result;
  48. }
  49. /* static */
  50. int Logger::Warning(const char* fmt, ...) {
  51. va_list args;
  52. va_start(args, fmt);
  53. int result = Log(WARNING_LVL, fmt, args);
  54. va_end(args);
  55. return result;
  56. }
  57. /* static */
  58. int Logger::Error(const char* fmt, ...) {
  59. va_list args;
  60. va_start(args, fmt);
  61. int result = Log(ERROR_LVL, fmt, args);
  62. va_end(args);
  63. return result;
  64. }
  65. /* static */
  66. int Logger::Severe(const char* fmt, ...) {
  67. va_list args;
  68. va_start(args, fmt);
  69. int result = Log(SEVERE_LVL, fmt, args);
  70. va_end(args);
  71. return result;
  72. }
  73. } // namespace keymaster