This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Asynchronous logging in tomcat8: how?  RSS feed

 
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks
I have found many tutorials to use asynchronous logging in tomcat7 but I'm not finding to tomcat8.
How do I use asynchronous logging in tomcat8? It seems to me that is setting by default?
Best Regards.
 
Bartender
Posts: 20766
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "asynchronous logging"?

When you write a message to the log, it's supposed to be essentially just a text string and a few qualifiers such as severity level, logger ID, and so forth. Nothing heavy enough to need to be asynchrous - we're talking microseconds or less here.

The backend for the logger, now that's another matter. You can have all sorts of backends, some of which may write to files, some to databases, some to email, and some in batches. But the app doing the logging isn't supposed to be aware of what's on the backend.

Incidentally, I trust that you are aware that the logging facility used by Tomcat is not that which is used by the webapps? Each webapp is responsible for its own logging. The Tomcat docs, alas, don't make that clear. The "Tomcat logging" is the logging done by the components of Tomcat itself, not the apps deployed within it.
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What do you mean by "asynchronous logging"?



7. Asynchronous Logging
Tomcat 7 now includes an asynchronous file logger (AsyncFileHandler). AsyncFileHandler extends FileHandler and can be used in place of FileHandler. To use AsyncFileHandler, simply replace all occurrences of FileHandler with AsyncFileHandler in the CATALINA_HOME/conf/logging.properties file. The application must use java.util.Logging; asynchronous logging does not work with Log4j.

When a log message is sent to the AsyncFileHandler, the log message is added to a queue(java.util.concurrent.LinkedBlockingDeque) and the method invocation to log a message returns immediately without waiting for the I/O to disc. A separate thread is started when the AsyncFileHandler is loaded by the class loader. This thread reads log messages from the queue and writes them to the disc.

The advantage of this approach is that if the I/O to disc is slow (e.g. log files on a remote drive), logging will not slow request processing.

AsyncFileHandler employs a producer/consumer relationship with the queue to store log messages. The default queue size is 10000. In case of overflow, the default behavior is to drop the last message. Both the default size and overflow behavior can be configured using startup system properties.

Source - http://www.developer.com/java/web/article.php/10935_3904871_2/Top-7-Features-in-Tomcat-7-The-New-and-the-Improved.htm
 
Tim Holloway
Bartender
Posts: 20766
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cheated and looked at the Tomcat 8 source. There is still an AsyncFileHandler log backend in Tomcat 8. The actual juli extension appears to be something that was shared between both Tomcat and Geronimo.

If you can't find configuration information in the Tomcat 8 docs, look at the Tomcat 7 docs. Should be about the same.

Actual logging is done via a thread spawned by the AsyncFileHandler. Configuring the queue is probably done by a sub-property, since I didn't see anything about it in the class itself. Didn't look too close, however.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!