57 virtual void Post(
const CNcbiToolkit_LogMessage&
msg);
60 jobject
GetLevel(JNIEnv*
env, CNcbiToolkit_LogMessage::ESeverity severity);
95 "CJavaLogHandler ctor: could not create global logger object reference");
100 clazz =
env->FindClass(
"java/util/logging/Logger");
102 "CJavaLogHandler ctor: java Logger class could not be found");
106 "CJavaLogHandler ctor: could not create global Logger reference");
109 m_Logger_logId =
env->GetMethodID(clazz,
"log",
"(Ljava/util/logging/LogRecord;)V");
111 "CJavaLogHandler ctor: java Logger method log(LogRecord) ID could not be returned");
113 env->DeleteLocalRef(clazz);
116 clazz =
env->FindClass(
"java/util/logging/LogRecord");
118 "CJavaLogHandler ctor: java LogRecord class could not be found");
122 "CJavaLogHandler ctor: could not create global LogRecord reference");
126 "(Ljava/util/logging/Level;Ljava/lang/String;)V");
128 "CJavaLogHandler ctor: java LogRecord constructor ID could not be returned");
131 "([Ljava/lang/Object;)V");
133 "CJavaLogHandler ctor: java LogRecord setParameters ID could not be returned");
135 env->DeleteLocalRef(clazz);
138 clazz =
env->FindClass(
"java/util/logging/Level");
140 "CJavaLogHandler ctor: java Level class could not be found");
144 "CJavaLogHandler ctor: could not create global Level reference");
147 "SEVERE",
"Ljava/util/logging/Level;");
149 "CJavaLogHandler ctor: Level.SEVERE not found");
152 "WARNING",
"Ljava/util/logging/Level;");
154 "CJavaLogHandler ctor: Level.WARNING not found");
157 "INFO",
"Ljava/util/logging/Level;");
159 "CJavaLogHandler ctor: Level.INFO not found");
162 "CONFIG",
"Ljava/util/logging/Level;");
164 "CJavaLogHandler ctor: Level.CONFIG not found");
167 "FINE",
"Ljava/util/logging/Level;");
169 "CJavaLogHandler ctor: Level.FINE not found");
172 "FINER",
"Ljava/util/logging/Level;");
174 "CJavaLogHandler ctor: Level.FINER not found");
177 "FINEST",
"Ljava/util/logging/Level;");
179 "CJavaLogHandler ctor: Level.FINEST not found");
182 clazz =
env->FindClass(
"java/lang/String");
184 "CJavaLogHandler ctor: java String class could not be found");
188 "CJavaLogHandler ctor: could not create global String reference");
190 env->DeleteLocalRef(clazz);
199 jobject level =
NULL;
232 jstring jstr =
env->NewStringUTF(
msg.Message().c_str());
239 jstr =
env->NewStringUTF(
"1");
240 env->SetObjectArrayElement(params, 0, jstr);
243 env->SetObjectArrayElement(params, 1, jstr);
246 env->SetObjectArrayElement(params, 2, jstr);
249 env->SetObjectArrayElement(params, 3, jstr);
251 jstr =
env->NewStringUTF(
msg.File().c_str());
252 env->SetObjectArrayElement(params, 4, jstr);
255 env->SetObjectArrayElement(params, 5, jstr);
282 JAVA_ABORT(
"Requested Java version not supported");
294 JAVA_ABORT(
"Unknown return code from g_GetJNIEnv");
305 jclass newExcCls =
env->FindClass(clsName);
307 env->ThrowNew(newExcCls,
msg);
309 JAVA_FATAL_ERROR(
"CJniUtil::ThrowJavaException(): requested exception class not found");
315 env->ExceptionDescribe();
322 env->ExceptionDescribe();
339 int argc =
env->GetArrayLength(argArray);
340 argv =
new char* [argc+1];
342 const char *cn =
env->GetStringUTFChars(
progName, 0);
343 argv[0] =
new char[strlen(cn) + 1];
346 for(
int i = 0;
i < argc; ++
i)
348 jstring s = (jstring)
env->GetObjectArrayElement(argArray,
i);
349 const char* p =
env->GetStringUTFChars(s, 0);
350 argv[
i+1] =
new char[strlen(p) + 1];
351 strcpy(argv[
i+1], p);
355 for(
int i = 0;
i < argc; ++
i)
357 jstring s = (jstring)
env->GetObjectArrayElement(argArray,
i);
358 env->ReleaseStringUTFChars(s, argv[
i+1]);
367 jobject props =
NULL;
370 jmethodID midSetProp;
373 propsClass =
env->FindClass(
"java/util/Properties");
374 if( propsClass ==
NULL )
377 midCtor =
env->GetMethodID(propsClass,
"<init>",
"()V");
378 if( midCtor ==
NULL )
381 props =
env->NewObject(propsClass, midCtor);
385 midSetProp =
env->GetMethodID(propsClass,
"setProperty",
386 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;");
387 if( midSetProp ==
NULL )
392 vector<CRef<CArgValue> >::iterator
i = ncbiArgs.begin();
393 for( ;
i != ncbiArgs.end(); ++
i )
395 string name = (*i)->GetName();
396 jstring
key =
env->NewStringUTF(name.c_str());
398 if( (*i)->HasValue() )
399 val =
env->NewStringUTF((*i)->AsString().c_str());
401 env->CallObjectMethod(props, midSetProp,
key,
val);
412 (JNIEnv *
env, jclass, jobject logger)
420 (JNIEnv *
env, jclass, jobjectArray argArray, jstring
progName)
427 int argc =
env->GetArrayLength(argArray);
433 for(
int i = 0;
i < argc + 1; ++
i)
447 (JNIEnv *
env, jclass, jstring s)
449 const char* p =
env->GetStringUTFChars(s, 0);
452 env->ReleaseStringUTFChars(s, p);
458 JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *jvm,
void *reserved)
jmethodID m_LogRecord_ctorId
CJavaLogHandler(jobject logger)
virtual ~CJavaLogHandler()
jfieldID m_Level_SevereId
jfieldID m_Level_WarningId
virtual void Post(const CNcbiToolkit_LogMessage &msg)
jfieldID m_Level_FinestId
jobject GetLevel(JNIEnv *env, CNcbiToolkit_LogMessage::ESeverity severity)
jmethodID m_LogRecord_setParametersId
jfieldID m_Level_ConfigId
static char ** CreateCStyleArgs(JNIEnv *env, jstring progName, jobjectArray argArray)
static INcbiToolkit_LogHandler * GetLogHandler()
static void SetJVM(JavaVM *vm)
static JNIEnv * GetEnv(void)
static void ThrowJavaException(const char *clsName, const char *msg)
static jobject GetArgsFromNcbiApp(JNIEnv *env, CNcbiApplication *app)
static INcbiToolkit_LogHandler * sm_logHandler
static void SetLogHandler(jobject logger)
static void DescribeJavaException(void)
static void JavaFatalError(const char *msg)
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
vector< CRef< CArgValue > > GetAll(void) const
Get all available arguments.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
@ eDiag_Trace
Trace message.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
@ eDiag_Critical
Critical error message.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define USING_NCBI_SCOPE
For using NCBI namespace code.
static string Int8ToString(Int8 value, TNumToStringFlags flags=0, int base=10)
Convert Int8 to string.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
const struct ncbi::grid::netcache::search::fields::KEY key
JNIEXPORT void JNICALL Java_org_ncbi_toolkit_NcbiToolkit_attachNcbiLogHandler0(JNIEnv *env, jclass, jobject logger)
JNIEXPORT void JNICALL Java_org_ncbi_toolkit_NcbiToolkit_testLog(JNIEnv *env, jclass, jstring s)
JNIEXPORT void JNICALL Java_org_ncbi_toolkit_NcbiToolkit_init0(JNIEnv *env, jclass, jobjectArray argArray, jstring progName)
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved)
Defines JNI specific macros and includes.
#define JAVA_CHECK_EXCEPTION(env)
#define JAVA_CURRENT_VERSION
#define JAVA_FATAL_ERROR(msg)
#define JAVA_VALIDATE(val, msg)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
static SLJIT_INLINE sljit_ins lr(sljit_gpr dst, sljit_gpr src)