logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wilfong, Paul" <paul.wilf...@ngc.com>
Subject RE: Log4j - Invoking log4j from C++ via JNI?
Date Tue, 27 Nov 2007 23:55:26 GMT
A couple of things about log4j and JNI...

First, I didn't realize that one of the log4j appenders,
NTEventLogAppender, uses JNI!  However, it does Java calling C++, and I
was interested in the other way around.

Second, I got an email from another source that I thought would be if
interest regarding the use of JNI - see below. I asked if it would be Ok
to post to the log4 email list.

It looks like it might not be a good idea to try using JNI for
logging...

------------------------------------------------------------------------
--------
From: Roedy Green 
Sent: Tuesday, October 09, 2007 5:31 PM
To: Wilfong, Paul
Subject: Re: JNI web page questions

At 08:32 AM 2007-10-09, Paul Wilfong wrote:

1.  You have a paragraph about how slow a JNI call is:  "A JNI call is
very slow, in the order of .5 to 1.0 microseconds..."  I was wondering
if there is a source for this timing?  Not a big deal but it would be
nice to see.  Is there a Sun site with this info?  (I have been googling
around for an hour and your statement is the only thing I have found
along these lines so far.)

It would have come from some discussion in the newsgroups.  Machines are
faster now, so properly I should concoct a benchmark and publish it
along with the config.  I just wanted people to understand that the call
is a big deal and you must try to avoid frequent calls over the blood
brain barrier.

2.  I am actually more interested in going the other way - C programs
calling Java routines.  Is JNI also slow in that direction?
(Specifically, my company wants to use log4j for our java programs, and
log4cxx for our c programs, and it occurred to me to consider just using
log4j for both, with JNI in the c programs.)

It is worse. Since you have the Java overhead of reflection on top.  It
wont kill you if you call and stay in the method doing some substantial
hunk of work.  What kills you are zillions of tiny calls.  In other
words, you want to use high level interfaces over the barrier.



-----Original Message-----
From: Wilfong, Paul [mailto:paul.wilfong@ngc.com] 
Sent: Thursday, October 04, 2007 11:38 AM
To: log4j-user@logging.apache.org
Subject: Log4j - Invoking log4j from C++ via JNI?

I plan to support logging in an environment with C++ programs and Java
programs.  I've been successful, I believe, in figuring out what I want
to do using log4j and log4cxx.

But now logback is coming along, and it occurred to me that there might
be another way - use JNI to invoke log4j (or logback) from the C++
programs.

So - Question:  Has anyone used log4j with JNI from C++ programs?  Or
would anyone have any advice about it?

I would expect reactions like "Complicated, Lots of overhead, etc".  But
I think that it would be nice not to have to worry about using the
XMLSocketReceiver plugin anymore.

Thanks much for any input.

By the way, it seems that using Java to invoke C++ via JNI is commonly
known.  But documentation I have seen (e.g.,  <tut-native1dot1.zip> in
<http://java.sun.com/docs/books/tutorial/information/download.html>
says it can do it the other way too.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message