loggerjnicallback.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // This file implements the callback "bridge" between Java and C++ for
  7. // ROCKSDB_NAMESPACE::Logger
  8. #ifndef JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_
  9. #define JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_
  10. #include <jni.h>
  11. #include <memory>
  12. #include <string>
  13. #include "rocksjni/jnicallback.h"
  14. #include "port/port.h"
  15. #include "rocksdb/env.h"
  16. namespace ROCKSDB_NAMESPACE {
  17. class LoggerJniCallback : public JniCallback, public Logger {
  18. public:
  19. LoggerJniCallback(JNIEnv* env, jobject jLogger);
  20. ~LoggerJniCallback();
  21. using Logger::SetInfoLogLevel;
  22. using Logger::GetInfoLogLevel;
  23. // Write an entry to the log file with the specified format.
  24. virtual void Logv(const char* format, va_list ap);
  25. // Write an entry to the log file with the specified log level
  26. // and format. Any log with level under the internal log level
  27. // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be
  28. // printed.
  29. virtual void Logv(const InfoLogLevel log_level, const char* format,
  30. va_list ap);
  31. private:
  32. jmethodID m_jLogMethodId;
  33. jobject m_jdebug_level;
  34. jobject m_jinfo_level;
  35. jobject m_jwarn_level;
  36. jobject m_jerror_level;
  37. jobject m_jfatal_level;
  38. jobject m_jheader_level;
  39. std::unique_ptr<char[]> format_str(const char* format, va_list ap) const;
  40. };
  41. } // namespace ROCKSDB_NAMESPACE
  42. #endif // JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_