This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Log Handler Properties After Creating the Handler  RSS feed

 
Shane Semanek
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to dynamically create a logger for an application from the following XML fragment:

<logger name="com.mypackage">
<level>INFO</level>
<filter></filter>
<handlers>
<handler>
<class>java.util.logging.FileHandler</class>
<properties>
<property name="java.util.logging.FileHandler.pattern">/var/myapp/log.xml</property>
<property name="java.util.logging.FileHandler.count">1</property>
<property name="java.util.logging.FileHandler.limit">5000</property>
<property name="java.util.logging.FileHandler.append">true</property>
</properties>
<level>INFO</level>
<filter></filter>
<formatter>java.util.logging.XMLFormatter</formatter>
</handler>
<handler>
<class>java.util.logging.SocketHandler</class>
<properties>
<property name="java.util.logging.SocketHandler.host">localhost</property>
<property name="java.util.logging.SocketHandler.port">8888</property>
</properties>
<level>INFO</level>
<filter></filter>
<formatter>java.util.logging.XMLFormatter</formatter>
</handler>
</handlers>
</logger>

The problem I am having is figuring out how to set the properties for the Handlers. It is easy to set the Level, Filter, and Formatter of the Handler but I don't see a way to set the handler properties except in the contructors, which will not work here. From reading the javadocs I am guessing this needs to be done using the LogManager class. The LogManager class has a getProperty() method but no setProperty() method. I understand how to use the logging.properties file but do not want to edit it on every machine the applications runs on. I also want the flexibility to create my own handlers and set the properties on them. Is it possible to set the properties of a Handler dynamically? For instance, if I use a FileHandler, I will not know the pattern until after it has been constructed so I need a way to dynamically set the java.util.logging.FileHandler.pattern property.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!