is it possible to use an SLF4J adapter in GWT to wrap java.util.logging ?

1,871 views
Skip to first unread message

zixzigma

unread,
Feb 24, 2011, 10:04:12 PM2/24/11
to google-we...@googlegroups.com
is it possible to use an SL4J adapter in GWT to wrap java.util.logging ?

I would like to be able to use logging.properties file to define formatting,
which I believe is not possible with java.util.logging.

Thank You

Juan Pablo Gardella

unread,
Feb 24, 2011, 10:06:08 PM2/24/11
to google-we...@googlegroups.com
+1

2011/2/24 zixzigma <zixz...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Thomas Broyer

unread,
Feb 25, 2011, 6:50:41 AM2/25/11
to google-we...@googlegroups.com


On Friday, February 25, 2011 4:04:12 AM UTC+1, zixzigma wrote:
is it possible to use an SL4J adapter in GWT to wrap java.util.logging ?

I started working on something like that at work, and we will eventually open source it.

For now, I can use Slf4J in my client code. In DevMode, it will use whatever Slf4j implementation it finds in the classpath (which means that it will write to the console, not to the DevMode window), and it compiles out in prod mode.
I've been thinking recently about just wrapping java.util.logging (and using jul-to-slf4j.jar to format my logs using logback) instead of my default, emulated NOPLoggerFactory (used in web mode only), but we actually don't use it that much in client code (and overall), so I didn't invest any more time in it for now.

There's also a project on GitHub: https://github.com/derjan1982/slf4gwt more like gwt-log than JUL integration in GWT though, IIRC.
 
I would like to be able to use logging.properties file to define formatting,
which I believe is not possible with java.util.logging.

I believe you can (at least in DevMode I mean, or when using a RemoteLogHandler), though you might have to make your own Formatter class (or pick a third-party one).

Richard Allen

unread,
Feb 25, 2011, 7:54:25 AM2/25/11
to google-we...@googlegroups.com
I'm also currently working on an emulation of org.slf4j.Logger and org.slf4j.LoggerFactory. The emulated LoggerFactory class simply calls java.util.logging.Logger.getLogger(String) to create a logger, and the emulation of org.slf4j.Logger that is returned from LoggerFactory wraps the java.util.logging.Logger. I didn't bother emulating the Marker methods because we aren't using them. The org.slf4j.Logger emulation is loosely based on org.slf4j.impl.JDK14LoggerAdapter.

Palo G.

unread,
Feb 25, 2011, 9:52:33 AM2/25/11
to Google Web Toolkit
May I ask why do you need something like that? Basically everything
what you need is inside of gwt-user package.

Let's look what is actually SLF4J. It's just an interface for many
logging frameworks [java.lang, apache.logger , etc]. So when you have
plenty of libraries using different logging frameworks and want to
collect all these logs, you will use SLF4J for agregating these logs
to same format.

Now let's look what is inside gwt. There is pack with loggers to
firebug, jsconsole, system.out for dev mode, logger with remoteservice
to send logs to server. When you instantiate logger and make a log,
enabled frameworks are used. I agree thet format of log is horrible,
but inheriting this loggers and setting up own log formatter solve
this problem.

SO you just need familiar use of gwt logging. Make a class
LoggerFactory.getLogger ane one Logger class , make a mapping from
java.lang levels to SLF4J logger . - 2 classes and 1 class per log
channel.

Make it yourself.

Adligo

unread,
Feb 26, 2011, 12:52:27 PM2/26/11
to Google Web Toolkit
In short NO, this is why I wrote i_log.

The main problem with all log libraries is their static initialization
(log4j, slf4j exc)
and synchronous loading of the log config file. These were the two
huge issues that I had to over come
porting apache commons logging to gwt which I renamed as i_log.

http://cvs.adligo.org/viewvc/i_log/
http://www.adligo.com

I haven't tried directing (wrapping) it to java.util.logging in GWT
but it does work server side (also I did log4j).

I immagine it wouldn't be two much work to get i_log wrapping
java.util.logging on the client in GWT working,
probably just a addition to
http://cvs.adligo.org/viewvc/i_log4utilLog/
so that it has a .gwt.xml module file.

I would suggest dropping slf4j and using i_log,
slf4j also doesn't work on JME (Java Micro Edition),
i_log works everywhere you could use a .java souce code file to
my knowledge.

Cheers,
Scott

Adligo

unread,
Feb 26, 2011, 12:54:39 PM2/26/11
to Google Web Toolkit
Why didn't you use i_log, as I already finished it and open sourced it
several years ago?

http://cvs.adligo.org/viewvc/i_log/
common logging api anywhere you could use a .java source file.
JSE, JME and GWT

Cheers,
Scott

Adligo

unread,
Feb 26, 2011, 1:03:49 PM2/26/11
to Google Web Toolkit
To respond to the question....
May I ask why do you need something like that? Basically everything
what you need is inside of gwt-user package.

I did it before the GWT project had java.util.Logging and
some people do NOT like the java.util.Logging package,
I see a lot more people using log4j (as it was the original logging
library in java).

It gives your project developers options of which logging
implementation they want to use.

For instance I develop a widget A, and it is used by two projects one
uses log4j the other uses java.util.logging.
If I use java.util.logging in my widget A, then the project that uses
log4j will need to configure logging twice,
which is a pain in the butt.
Also vice versa.

If my widget uses i_log, you can simply delegate the i_log message
calls to log4j or java.util.logging
so you only have one common logging config file to configure your
logging implementation.

Also for some code I can write it so that it will work on JSE, JME and
GWT so I can keep some core logic shared rather than written more than
once (and maintained more than once).

Cheers,
Scott

steen....@gmail.com

unread,
Feb 26, 2011, 1:10:03 PM2/26/11
to google-we...@googlegroups.com

Sent from my LG phone

Adligo <sc...@adligo.com> wrote:

Richard Allen

unread,
Feb 28, 2011, 8:23:39 AM2/28/11
to google-we...@googlegroups.com
I never knew of i_log until now. I suggest you write some documentation and provide a website if you want to attract users.

Anyway, we aren't using JME, and SF4J/Logback with a simple GWT emulation is working fine for us.

-Richard

Adligo

unread,
Mar 1, 2011, 10:11:41 AM3/1/11
to Google Web Toolkit
So you don't get logging when GWT is actually compiled into javascript
(so you can't diagnose issues in the javascript that you actually
ship, you can only diagnose issues in emulated code (which isn't
javascript but actual java)).

Kelsey Francis

unread,
Mar 5, 2011, 10:26:24 PM3/5/11
to google-we...@googlegroups.com
No, it works in web mode too. What Rich means -- I'm on his team -- by emulated is that he wrote an implementation of org.slf4j.Logger and org.slf4j.LoggerFactory, much the same way that GWT itself emulates the java.util.logging classes. In fact, all the "emulated" classes do for now is delegate to java.util.logging. So, we have the much nicer API that slf4j offers, but get all the functionality of GWT's logging (including logging in web mode).
Reply all
Reply to author
Forward
0 new messages