java.util.logging + Glassfish v3 + Per-Application Logging
After reading a lot of stuff on the web ... java.util.logging in Glassfish (up to at least v3.1)...per application logging (ie: server.log captures all logs, then individual app1.log, app2.log etc logs capture logging just from app1, app2 etc.) is not possible (using just the /config/logging.properties) to configure. See the following (in a roughly chronological order over the last few years):
http://www.java.net/node/666057 http://www.java.net/node/684267 http://old.nabble.com/Configuring-java.util.logging-per-Web-Application-in-Glassfish-td19689665.html http://stackoverflow.com/questions/3394416/glassfish-logging-to-multiple-log-files http://forums.java.net/node/803338
SLF4J + Glassfish v3 + Per-Application Logging
SLF4J Rocks! Everything I read about it rocks! The ideas and concepts (ie: parameterised log statements, greater speed + everything from Log4J that was good...thanks Ceki Gülcü) rock! Its the successor to Log4J which also rocked...so SLF4J is even more 'rock-in'! So lets use that for per-application logging in Glassfish. Right? Not so fast...that'd be frankly too damn easy. What you think you can use the greatest logging framework out there and just get per-application logging working. No...of course you cant. Nothings that easy. But why? Well again its all to do with classloaders (in particular Glassfish's), although in a slightly different way to the java.util.logging issues mentioned earlier.
Turns out that Glassfish uses WELD internally (WELD being the implementation of: JSR-299: Java Contexts and Dependency Injection for the Java EE platform (CDI)). So what you say .... well turns out that the WELD implementation in Glassfish (at least up to v3.1 when I last checked) includes SLF4J internally. This means that when you deploy your app with its SLF4J libs and config ... errr .... well Glassfish ignores them cos the beauty of classloaders is we go up the tree via the parents as far as we can to get our implementation (which in this case means that we end up using the WELD SLF4J version) and hence we ignore our own per-application logging SLF4J properties file. Beautiful ... screwed again!!!
Again ... known issue and in fact has/had the 2nd largest amount of votes for a fix in Glassfish JIRA bug tracker. But that doesnt help people stuck on a non-bleeding edge version of Glassfish for the foreseeable future...even if there was a fix implemented....which at present (July 2011) there is not.
Yay!!! Or....in the immortal words of John McClane/Bruce Willis(Die Hard) .... YippeeKaaayey Motherf*cker.
I mean seriously ... Im not asking for the world here....per-application seperated out log files....surely given this was possible back in the 70's using a couple of shell scripts I should be able to achieve it today ? Considering were so technologically advanced and all after all. (Oh and in case it doesnt come across through text so well....insert a heavy dose of SARCASM right here).
So what next?
Turns out that Glassfish uses WELD internally (WELD being the implementation of: JSR-299: Java Contexts and Dependency Injection for the Java EE platform (CDI)). So what you say .... well turns out that the WELD implementation in Glassfish (at least up to v3.1 when I last checked) includes SLF4J internally. This means that when you deploy your app with its SLF4J libs and config ... errr .... well Glassfish ignores them cos the beauty of classloaders is we go up the tree via the parents as far as we can to get our implementation (which in this case means that we end up using the WELD SLF4J version) and hence we ignore our own per-application logging SLF4J properties file. Beautiful ... screwed again!!!
Again ... known issue and in fact has/had the 2nd largest amount of votes for a fix in Glassfish JIRA bug tracker. But that doesnt help people stuck on a non-bleeding edge version of Glassfish for the foreseeable future...even if there was a fix implemented....which at present (July 2011) there is not.
Yay!!! Or....in the immortal words of John McClane/Bruce Willis(Die Hard) .... YippeeKaaayey Motherf*cker.
I mean seriously ... Im not asking for the world here....per-application seperated out log files....surely given this was possible back in the 70's using a couple of shell scripts I should be able to achieve it today ? Considering were so technologically advanced and all after all. (Oh and in case it doesnt come across through text so well....insert a heavy dose of SARCASM right here).
So what next?
Log4J + Glassfish v3 + Per-Application Logging (+ Me Screaming If This Fails Like java.util.logging & SLF4J Above...)
So what fun things did I discover with Log4J. Well for starters the classloader hierarchy and associated configuration of Log4J properties works in reverse to something like JUL. The lowest classloader in the hierarchy overrides the config from any higher classloaders. So if you setup a properties file in /config/log4j.properties using the system property added (-Dlog4j.configuration=file:///${com.sun.aas.instanceRoot}/config/log4j.properties) as described in this guys blog:
http://weblogs.java.net/blog/2007/08/28/hell-jdk-logging-ii
and the log4j.properties looks like:
log4j.logger.xxx.yyy.zzz=DEBUG,stdout,GF_XXX_FILE
.....and then later in your app you do :
log4j.logger.xxx.yyy.zzz=DEBUG,stdout
...you will only get the stdout appender added to this logger not both of stdout,GF_XXX_FILE that server property file had defined.
Whats more things arent cumulative as I found out so defining the GF_XXX_FILE appended in the glassfish server log4j.properties and then attempting to use it from the application log4j.properties wont work (which is to be expected i guess). I initially wanted to have a server level properties file that I could use to define appenders to at least seperate files and perhaps to standard out as well and then assign those appenders to loggers. This would've been great as you go to the single log4j.properties file and modify that for each app in the domain. However, as always this wasnt so simple for me. Since I already had some apps that defined their own props files within the app deploy these would over-ride the domain level prop file and Id end up with config in two places (server level for some apps and app level for the rest).
So i decided to finally only use application-level log4j.properties and package them up with the deployed modules per application with the config for seperate file logging within each prop file.
And.....this works for us!!! A little anti-climactic after that entire spiel but hey....
And so now, 3 days later, Ive spent probably an order of magnitude longer on this than I should've .... frustrating .... but on the other hand I know everything about every known logging framework and their quirks. Hmmmm....I wonder how I can use that on a CV ??? :-)
Notes:
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/helpers/Loader.html#getResource%28java.lang.String%29 http://logging.apache.org/log4j/1.2/manual.html
Nice post. It was helpful form me. Thanks.
ReplyDeleteIsparta
ReplyDeleteTunceli
Yozgat
Çorum
Konya
R5DMQW
Aksaray
ReplyDeleteAydın
Kütahya
Rize
Bingöl
K5WDEİ
düzce
ReplyDeletesakarya
tunceli
van
bayburt
PJMC
bitlis
ReplyDeletekastamonu
çorum
van
sakarya
61WLP
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
HFE72A
C0086
ReplyDeleteKayseri Evden Eve Nakliyat
Çerkezköy Koltuk Kaplama
Rize Şehirler Arası Nakliyat
Batıkent Boya Ustası
Çerkezköy Kurtarıcı
Probit Güvenilir mi
Kırklareli Şehir İçi Nakliyat
Isparta Şehir İçi Nakliyat
Bibox Güvenilir mi
CE698
ReplyDeleteBayburt Parça Eşya Taşıma
Şırnak Lojistik
Nevşehir Evden Eve Nakliyat
Denizli Şehirler Arası Nakliyat
Altındağ Boya Ustası
Balıkesir Parça Eşya Taşıma
Erzincan Şehirler Arası Nakliyat
Osmaniye Parça Eşya Taşıma
Nevşehir Şehir İçi Nakliyat
7422E
ReplyDeleteTrabzon Evden Eve Nakliyat
Denizli Şehir İçi Nakliyat
Kayseri Parça Eşya Taşıma
Tesla Coin Hangi Borsada
Sakarya Şehirler Arası Nakliyat
Kayseri Lojistik
Ankara Lojistik
Çerkezköy Motor Ustası
Karabük Parça Eşya Taşıma
EA120
ReplyDeletereferans kodu %20
3F291
ReplyDeletekızlarla canlı sohbet
bartın görüntülü sohbet uygulamaları ücretsiz
van kadınlarla sohbet
yabancı canlı sohbet
kars canlı sohbet ücretsiz
nevşehir telefonda kızlarla sohbet
telefonda canlı sohbet
giresun rastgele sohbet
kırıkkale canlı sohbet siteleri
3AC53
ReplyDeletebalıkesir görüntülü sohbet uygulama
sesli sohbet siteleri
osmaniye canlı görüntülü sohbet
bilecik canli sohbet bedava
sesli sohbet sesli chat
antep canli goruntulu sohbet siteleri
canli sohbet bedava
manisa rastgele canlı sohbet
aksaray canlı görüntülü sohbet odaları
2EB6D
ReplyDeleteGörüntülü Sohbet
Threads Takipçi Hilesi
Spotify Dinlenme Satın Al
Coin Oynama
Binance Hesap Açma
Coin Madenciliği Nedir
Fuckelon Coin Hangi Borsada
Hexa Coin Hangi Borsada
Instagram Beğeni Satın Al