• R/O
  • SSH
  • HTTPS

senna-java: Commit


Commit MetaInfo

Revision7 (tree)
Time2008-12-19 18:32:06
Authormir

Log Message

* src/java/senna/SennaLogger.java: appear
* src/jni/senna_SennaLogger.h: appear
* src/jni/senna_SennaLogger.c: appear
* src/jni/Makefile: add SennaLogger
* src/java/senna/Senna.java: add sen_log_xxx flags
* src/jni/senna_Senna.h: add sen_log_xxx flags
* build.xml: add SennaLogger

Change Summary

Incremental Difference

--- trunk/ChangeLog (revision 6)
+++ trunk/ChangeLog (revision 7)
@@ -1,3 +1,12 @@
1+2008-12-19 Tetsuro IKEDA <ikdttr@gmail.com>
2+ * src/java/senna/SennaLogger.java: appear
3+ * src/jni/senna_SennaLogger.h: appear
4+ * src/jni/senna_SennaLogger.c: appear
5+ * src/jni/Makefile: add SennaLogger
6+ * src/java/senna/Senna.java: add sen_log_xxx flags
7+ * src/jni/senna_Senna.h: add sen_log_xxx flags
8+ * build.xml: add SennaLogger
9+
110 2008-12-18 Tetsuro IKEDA <ikdttr@gmail.com>
211 * build.xml: add DB API classes for javah
312 * src/jni/senna_SennaContext.h: appeared
--- trunk/src/jni/senna_SennaLogger.c (revision 0)
+++ trunk/src/jni/senna_SennaLogger.c (revision 7)
@@ -0,0 +1,100 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+#include "senna_java.h"
20+#include "senna_SennaLogger.h"
21+
22+static const char* log_file_path;
23+static int log_level;
24+static FILE *fp = NULL;
25+
26+void senna_logger_func(int level, const char *time, const char *title,
27+ const char *msg, const char *location, void *func_arg)
28+{
29+ const char slev[] = " EACewnid-";
30+ if (fp)
31+ {
32+ fprintf(fp, "%s|%c|%s %s %s\n", time, *(slev + log_level), title, msg, location);
33+ fflush(fp);
34+ }
35+}
36+
37+sen_logger_info senna_logger = {
38+ sen_log_notice,
39+ SEN_LOG_TIME|SEN_LOG_MESSAGE,
40+ senna_logger_func,
41+ NULL
42+};
43+
44+/*
45+ * Class: senna_SennaLogger
46+ * Method: open
47+ * Signature: (Ljava/lang/String;I)V
48+ */
49+JNIEXPORT void JNICALL
50+Java_senna_SennaLogger_open(JNIEnv *env, jclass clazz, jstring path_str, jint level)
51+{
52+ log_file_path = (*env)->GetStringUTFChars(env, path_str, NULL);
53+ log_level = level;
54+
55+ if (!fp)
56+ {
57+ fp = fopen(log_file_path, "a");
58+ }
59+
60+ senna_logger.max_level = (sen_log_level) log_level;
61+ sen_logger_info_set(&senna_logger);
62+}
63+
64+/*
65+ * Class: senna_SennaLogger
66+ * Method: close
67+ * Signature: ()V
68+ */
69+JNIEXPORT void JNICALL
70+Java_senna_SennaLogger_close(JNIEnv *env, jclass clazz)
71+{
72+ if (fp)
73+ {
74+ fclose(fp);
75+ fp = NULL;
76+ }
77+}
78+
79+/*
80+ * Class: senna_SennaLogger
81+ * Method: getLevel
82+ * Signature: ()I
83+ */
84+JNIEXPORT jint JNICALL
85+Java_senna_SennaLogger_getLevel(JNIEnv *env, jclass clazz)
86+{
87+ return (jint) log_level;
88+}
89+
90+/*
91+ * Class: senna_SennaLogger
92+ * Method: setLevel
93+ * Signature: (I)V
94+ */
95+JNIEXPORT void JNICALL
96+Java_senna_SennaLogger_setLevel(JNIEnv *env, jclass clazz, jint level)
97+{
98+ log_level = level;
99+ senna_logger.max_level = (sen_log_level) log_level;
100+}
--- trunk/src/jni/Makefile (revision 6)
+++ trunk/src/jni/Makefile (revision 7)
@@ -1,4 +1,4 @@
1-CC = gcc
1+]CC = gcc
22 OPT = -Wall -fPIC
33 INCLUDES = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
44 LIBS = -lsenna
@@ -5,7 +5,8 @@
55
66 all: libsennajava.so
77
8-libsennajava.so: senna_java.o senna_Senna.o senna_Index.o senna_Records.o senna_Snippet.o
8+libsennajava.so: senna_java.o senna_Senna.o senna_Index.o senna_Records.o senna_Snippet.o \
9+ senna_SennaLogger.o
910 $(CC) $(OPT) $(INCLUDES) $(LIBS) -shared -o $@ $^
1011
1112 senna_java.o: senna_java.c senna_java.h
@@ -23,6 +24,9 @@
2324 senna_Snippet.o: senna_Snippet.c senna_Snippet.h
2425 $(CC) $(OPT) $(INCLUDES) -o $@ -g -c $<
2526
27+senna_Logger.o: senna_SennaLogger.c senna_SennaLogger.h
28+ $(CC) $(OPT) $(INCLUDES) -o $@ -g -c $<
29+
2630 clean:
2731 rm -f *.so *.o
2832
--- trunk/src/jni/senna_Senna.h (revision 6)
+++ trunk/src/jni/senna_Senna.h (revision 7)
@@ -53,6 +53,26 @@
5353 #define senna_Senna_SEN_CTX_USE_QL 3L
5454 #undef senna_Senna_SEN_CTX_BATCH_MODE
5555 #define senna_Senna_SEN_CTX_BATCH_MODE 4L
56+#undef senna_Senna_SEN_LOG_NONE
57+#define senna_Senna_SEN_LOG_NONE 0L
58+#undef senna_Senna_SEN_LOG_EMERG
59+#define senna_Senna_SEN_LOG_EMERG 1L
60+#undef senna_Senna_SEN_LOG_ALERT
61+#define senna_Senna_SEN_LOG_ALERT 2L
62+#undef senna_Senna_SEN_LOG_CRIT
63+#define senna_Senna_SEN_LOG_CRIT 3L
64+#undef senna_Senna_SEN_LOG_ERROR
65+#define senna_Senna_SEN_LOG_ERROR 4L
66+#undef senna_Senna_SEN_LOG_WARNING
67+#define senna_Senna_SEN_LOG_WARNING 5L
68+#undef senna_Senna_SEN_LOG_NOTICE
69+#define senna_Senna_SEN_LOG_NOTICE 6L
70+#undef senna_Senna_SEN_LOG_INFO
71+#define senna_Senna_SEN_LOG_INFO 7L
72+#undef senna_Senna_SEN_LOG_DEBUG
73+#define senna_Senna_SEN_LOG_DEBUG 8L
74+#undef senna_Senna_SEN_LOG_DUMP
75+#define senna_Senna_SEN_LOG_DUMP 9L
5676 /*
5777 * Class: senna_Senna
5878 * Method: init
--- trunk/src/jni/senna_SennaLogger.h (revision 0)
+++ trunk/src/jni/senna_SennaLogger.h (revision 7)
@@ -0,0 +1,45 @@
1+/* DO NOT EDIT THIS FILE - it is machine generated */
2+#include <jni.h>
3+/* Header for class senna_SennaLogger */
4+
5+#ifndef _Included_senna_SennaLogger
6+#define _Included_senna_SennaLogger
7+#ifdef __cplusplus
8+extern "C" {
9+#endif
10+/*
11+ * Class: senna_SennaLogger
12+ * Method: open
13+ * Signature: (Ljava/lang/String;I)V
14+ */
15+JNIEXPORT void JNICALL Java_senna_SennaLogger_open
16+ (JNIEnv *, jclass, jstring, jint);
17+
18+/*
19+ * Class: senna_SennaLogger
20+ * Method: close
21+ * Signature: ()V
22+ */
23+JNIEXPORT void JNICALL Java_senna_SennaLogger_close
24+ (JNIEnv *, jclass);
25+
26+/*
27+ * Class: senna_SennaLogger
28+ * Method: getLevel
29+ * Signature: ()I
30+ */
31+JNIEXPORT jint JNICALL Java_senna_SennaLogger_getLevel
32+ (JNIEnv *, jclass);
33+
34+/*
35+ * Class: senna_SennaLogger
36+ * Method: setLevel
37+ * Signature: (I)V
38+ */
39+JNIEXPORT void JNICALL Java_senna_SennaLogger_setLevel
40+ (JNIEnv *, jclass, jint);
41+
42+#ifdef __cplusplus
43+}
44+#endif
45+#endif
--- trunk/src/java/senna/Senna.java (revision 6)
+++ trunk/src/java/senna/Senna.java (revision 7)
@@ -96,6 +96,36 @@
9696 /** SEN_CTX_BATCH_MODE */
9797 public static final int SEN_CTX_BATCH_MODE = 0x0004;
9898
99+ /** sen_log_none */
100+ public static final int SEN_LOG_NONE = 0;
101+
102+ /** sen_log_emerg */
103+ public static final int SEN_LOG_EMERG = 1;
104+
105+ /** sen_log_alert */
106+ public static final int SEN_LOG_ALERT = 2;
107+
108+ /** sen_log_crit */
109+ public static final int SEN_LOG_CRIT = 3;
110+
111+ /** sen_log_error */
112+ public static final int SEN_LOG_ERROR = 4;
113+
114+ /** sen_log_warning */
115+ public static final int SEN_LOG_WARNING = 5;
116+
117+ /** sen_log_notice */
118+ public static final int SEN_LOG_NOTICE = 6;
119+
120+ /** sen_log_info */
121+ public static final int SEN_LOG_INFO = 7;
122+
123+ /** sen_log_debug */
124+ public static final int SEN_LOG_DEBUG = 8;
125+
126+ /** sen_log_dump */
127+ public static final int SEN_LOG_DUMP = 9;
128+
99129 /**
100130 * call sen_init().
101131 *
--- trunk/src/java/senna/SennaLogger.java (revision 0)
+++ trunk/src/java/senna/SennaLogger.java (revision 7)
@@ -0,0 +1,69 @@
1+/*
2+ * Copyright(C) 2008 Tetsuro IKEDA <ikdttr@gmail.com>
3+ *
4+ * This library is free software; you can redistribute it and/or
5+ * modify it under the terms of the GNU Lesser General Public
6+ * License as published by the Free Software Foundation; either
7+ * version 2.1 of the License, or (at your option) any later version.
8+ *
9+ * This library is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+ * Lesser General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public
15+ * License along with this library; if not, write to the Free Software
16+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+ */
18+
19+package senna;
20+
21+/**
22+ * senna.log management
23+ */
24+public class SennaLogger {
25+ /**
26+ * <pre>
27+ * open log file with below values.
28+ * path: senna.log
29+ * level: sen_log_notice
30+ * </pre>
31+ *
32+ * @throws SennaException
33+ */
34+ public static void open() throws SennaException {
35+ open("senna.log", Senna.SEN_LOG_NOTICE);
36+ }
37+
38+ /**
39+ * open log file.
40+ *
41+ * @param path log file path
42+ * @param level log level
43+ * @throws SennaException
44+ */
45+ public static native void open(String path, int level) throws SennaException;
46+
47+ /**
48+ * close log file.
49+ *
50+ * @throws SennaException
51+ */
52+ public static native void close() throws SennaException;
53+
54+ /**
55+ * get current log level.
56+ *
57+ * @return current log level
58+ * @throws SennaException
59+ */
60+ public static native int getLevel() throws SennaException;
61+
62+ /**
63+ * set log level.
64+ *
65+ * @param level log level
66+ * @throws SennaException
67+ */
68+ public static native void setLevel(int level) throws SennaException;
69+}
--- trunk/build.xml (revision 6)
+++ trunk/build.xml (revision 7)
@@ -67,6 +67,9 @@
6767 <javah classpath="${build.dest}"
6868 class="senna.Cursor"
6969 outputfile="${jni.source}/senna_Cursor.h" />
70+ <javah classpath="${build.dest}"
71+ class="senna.SennaLogger"
72+ outputfile="${jni.source}/senna_SennaLogger.h" />
7073 </target>
7174 <target name="jni" depends="jar">
7275 <exec dir="${jni.source}" executable="make" />
Show on old repository browser