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 
9 #ifndef JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_
10 #define JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_
11 
12 #include <jni.h>
13 #include <memory>
14 #include <string>
15 #include "rocksjni/jnicallback.h"
16 #include "port/port.h"
17 #include "rocksdb/env.h"
18 
19 namespace ROCKSDB_NAMESPACE {
20 
21 class LoggerJniCallback : public JniCallback, public Logger {
22  public:
23   LoggerJniCallback(JNIEnv* env, jobject jLogger);
24   ~LoggerJniCallback();
25 
26   using Logger::SetInfoLogLevel;
27   using Logger::GetInfoLogLevel;
28   // Write an entry to the log file with the specified format.
29   virtual void Logv(const char* format, va_list ap);
30   // Write an entry to the log file with the specified log level
31   // and format.  Any log with level under the internal log level
32   // of *this (see @SetInfoLogLevel and @GetInfoLogLevel) will not be
33   // printed.
34   virtual void Logv(const InfoLogLevel log_level, const char* format,
35                     va_list ap);
36 
37  private:
38   jmethodID m_jLogMethodId;
39   jobject m_jdebug_level;
40   jobject m_jinfo_level;
41   jobject m_jwarn_level;
42   jobject m_jerror_level;
43   jobject m_jfatal_level;
44   jobject m_jheader_level;
45   std::unique_ptr<char[]> format_str(const char* format, va_list ap) const;
46   };
47   }  // namespace ROCKSDB_NAMESPACE
48 
49 #endif  // JAVA_ROCKSJNI_LOGGERJNICALLBACK_H_
50