File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How get the Logger from a servlet?

 
Robert Paris
Ranch Hand
Posts: 585
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a method to get the Logger used in the server? Like:
Servlet.getLogger()? (I know that one doesn't exist)
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
two ways:
'getServletContext.log(String);' or just 'log(String);' witch is in 'GenericServlet'
Rene
 
Robert Paris
Ranch Hand
Posts: 585
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no, that's not what I asked. That's how you log something. I don't want that. I want the Logger itself. Like I asked:
Something like "getLogger()"
 
boyet silverio
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could probably look at the java.util.logging.Logger class it has a getLogger(String name) method which might be of use for your purposes.
 
Robert Paris
Ranch Hand
Posts: 585
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it won't. I want to get the logger from a servlet container. I'm thinking there must be something in the spec that says it's available through the API, right? It'd be dumb (in my opinion) not to make it available somewhere. i mean, put security on it if you want, but have an interface to get it.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would I, as a servlet container developer, want to give you, some programmer that I don't know from Adam, access to my logging object? You might do something to it that disables it. A logger logs. What else do you need it to do? I give you everything you need. You don't need direct access to the object. Principle of 'least privelege' and 'don't touch that you might break it!'.

But that's me as a servlet container programmer.

Me as a programmer also wonders: What do you need it for ? I'm just curious.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the spec, I've searched through the Servlet 2.3 spec and nowhere does it mention that a servlet container need give access to the logger, only that it provide a logging service.

If I anticipate correctly, and you are wanting to do some funky logging type things on conditions or certain events (change where the logger logs to if condition 'a' is met, etc...) then while searching through the spec I had a couple good hints... use Filters and/or Context lifecycle listeners. (SRV 6.1.1 and SRV 10.4, respectively)

And finally, if the built-in logger is just not going to do it for you... that's what log4j was made for.
 
Robert Paris
Ranch Hand
Posts: 585
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a DataSource implementation (it is a connection pool manager that works with a ConnectionPoolDataSource "a la" JDBC 2.0 Optional Extension Spec). I was hoping there would be an easy way for people to direct my DataSource to log to the servlet container's logger. However, if you're right, I have no idea how I'll do that. But it seems there must be a way because otherwise, everyone's going to have a different log file for every component plugged in to the container - ugh.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic