Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
logging-support.cc
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "util/logging-support.h"
16 
17 #include "common/logging.h"
18 
19 #include "common/names.h"
20 
21 using namespace impala;
22 
23 DEFINE_int32(non_impala_java_vlog, 0, "(Advanced) The log level (equivalent to --v) for "
24  "non-Impala Java classes (0: INFO, 1 and 2: DEBUG, 3: TRACE)");
25 
26 // Requires JniUtil::Init() to have been called. Called by the frontend and catalog
27 // service to log messages to Glog.
28 extern "C"
29 JNIEXPORT void JNICALL
31  JNIEnv* env, jclass caller_class, int severity, jstring msg, jstring file,
32  int line_number) {
33 
34  // Mimic the behaviour of VLOG(N) by ignoring verbose log messages when appropriate.
35  if (severity == TLogLevel::VLOG && !VLOG_IS_ON(1)) return;
36  if (severity == TLogLevel::VLOG_2 && !VLOG_IS_ON(2)) return;
37  if (severity == TLogLevel::VLOG_3 && !VLOG_IS_ON(3)) return;
38 
39  // Unused required argument to GetStringUTFChars
40  jboolean dummy;
41  const char* filename = env->GetStringUTFChars(file, &dummy);
42  const char* str = "";
43  if (msg != NULL) str = env->GetStringUTFChars(msg, &dummy);
44  int log_level = google::INFO;
45  switch (severity) {
46  case TLogLevel::VLOG:
47  case TLogLevel::VLOG_2:
48  case TLogLevel::VLOG_3:
49  log_level = google::INFO;
50  break;
51  case TLogLevel::INFO:
52  log_level = google::INFO;
53  break;
54  case TLogLevel::WARN:
55  log_level = google::WARNING;
56  break;
57  case TLogLevel::ERROR:
58  log_level = google::ERROR;
59  break;
60  case TLogLevel::FATAL:
61  log_level = google::FATAL;
62  break;
63  default:
64  DCHECK(false) << "Unrecognised TLogLevel: " << log_level;
65  }
66  google::LogMessage(filename, line_number, log_level).stream() << string(str);
67  if (msg != NULL) env->ReleaseStringUTFChars(msg, str);
68  env->ReleaseStringUTFChars(file, filename);
69 }
70 
71 namespace impala {
72 
74  JNIEnv* env = getJNIEnv();
75  JNINativeMethod nm;
76  jclass native_backend_cl = env->FindClass("com/cloudera/impala/util/NativeLogger");
77  nm.name = const_cast<char*>("Log");
78  nm.signature = const_cast<char*>("(ILjava/lang/String;Ljava/lang/String;I)V");
79  nm.fnPtr = reinterpret_cast<void*>(::Java_com_cloudera_impala_util_NativeLogger_Log);
80  env->RegisterNatives(native_backend_cl, &nm, 1);
81  EXIT_IF_EXC(env);
82 }
83 
84 TLogLevel::type FlagToTLogLevel(int flag) {
85  switch (flag) {
86  case 0: return TLogLevel::INFO;
87  case 1: return TLogLevel::VLOG;
88  case 2: return TLogLevel::VLOG_2;
89  case 3:
90  default: return TLogLevel::VLOG_3;
91  }
92 }
93 
94 }
TLogLevel::type FlagToTLogLevel(int flag)
#define EXIT_IF_EXC(env)
Definition: jni-util.h:85
JNIEXPORT void JNICALL Java_com_cloudera_impala_util_NativeLogger_Log(JNIEnv *env, jclass caller_class, int severity, jstring msg, jstring file, int line_number)
void InitJvmLoggingSupport()
DEFINE_int32(periodic_counter_update_period_ms, 500,"Period to update rate counters and"" sampling counters in ms")
int64_t flag
Definition: cpu-info.cc:51
JNIEnv * getJNIEnv(void)
C linkage for helper functions in hdfsJniHelper.h.