Specify handler for a logger in properties file

Hello All,
Is there a way of specifying a specific handler for a specific logger within the logging.properties file? I have not been able to find any documentation on the logging.properties file settings. I am looking for something like this:
com.eric.program.handlers = java.util.logging.ConsoleHandler
com.frank.handlers = java.util.logging.FileHandler
I would rather keep all my settings within this properties file instead of coding it. If you know where I can find some documentation, please let me know. I am using J2SE 1.4.1.
Thanks.

Well, after failing to assign a handler to a specific logger, I checked the LogManager source code and, alas, it only supports assigning handlers to the root logger.
What a bummer ... I think this is a real flaw in the LogManager design, especially since log4j supports assigning appenders to specific logger.
The (more or less) good news is that LogManager is designed for subclassing (by j2ee container apps, but hey) ... so you can try to add this functionality to your own LogManager and use that through the system property java.util.logging.manager.
import java.io.*;
import java.security.*;
import java.util.*;
import java.util.logging.*;
* All properties whose names end with ".handlers" are assumed to define a
* whitespace separated list of class names for handler classes to load and
* register as handlers on the logger (whose name corresponds to the property
* prefix). Each class name must be for a Handler class which has a default
* constructor.
public class CustomLogManager extends LogManager
    public CustomLogManager()
        super();
     * Overwritten to also add handlers
    public synchronized boolean addLogger(Logger logger)
        final boolean res = super.addLogger(logger);
        final String property = logger.getName() + ".handlers";
        if ( null != getProperty(property) )
            setHandlers(logger, property);
        return res;
    // Taken from java/util/logging/LogManager.java#initializeGlobalHandlers()
    private void setHandlers(final Logger logger, final String property)
        // We need to raise privilege here.  All our decisions will
        // be made based on the logging configuration, which can
        // only be modified by trusted code.
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                // Add new global handlers.
                String names[] = parseClassNames(property);
                for (int i = 0; i < names.length; i++) {
                    String word = names;
try {
Class clz = ClassLoader.getSystemClassLoader().loadClass(word);
Handler h = (Handler) clz.newInstance();
try {
// Check if there is a property defining the
// handler's level.
String levs = getProperty(word + ".level");
if (levs != null) {
h.setLevel(Level.parse(levs));
} catch (Exception ex) {
System.err.println("Can't set level for " + word);
// Probably a bad level. Drop through.
logger.addHandler(h);
} catch (Exception ex) {
System.err.println("Can't load log handler \"" + word + "\"");
System.err.println("" + ex);
ex.printStackTrace();
return null;
// Taken from java/util/logging/LogManager.java
// get a list of whitespace separated classnames from a property.
private String[] parseClassNames(String propertyName) {
String hands = getProperty(propertyName);
if (hands == null) {
return new String[0];
hands = hands.trim();
int ix = 0;
Vector result = new Vector();
while (ix < hands.length()) {
int end = ix;
while (end < hands.length()) {
if (Character.isWhitespace(hands.charAt(end))) {
break;
if (hands.charAt(end) == ',') {
break;
end++;
String word = hands.substring(ix, end);
ix = end+1;
word = word.trim();
if (word.length() == 0) {
continue;
result.add(word);
return (String[]) result.toArray(new String[result.size()]);
On the other hand, it might be possible to write a reusable config class which does that kind of initialization, too.

Similar Messages

  • How Can i specify multiple server names in rwservlet.properties  file?

    How Can i specify multiple server names in rwservlet.properties file without clustering?
    I am using oracle 10g Application server. we have 3 servers Repsvr1, RepSvr2 and RepSvr3. Now i need to configure rwservlet.properties file to point to these servers based on any running report. i got 3 keymap files with reports info.
    Sample entry in the key map file is:
    key1: server=Repsvr1 userid=xxx/yyy@dbname report=D:\Web\path1\path2\reports\Report1.rdf destype=cache desformat=PDF %*
    key2: server=Repsvr2 userid=xxx/yyy@dbname report=D:\Web\path1\path3\reports\Report2.rdf destype=cache desformat=PDF %*
    rwservlet.properties file letting me to enter only one servername. Even though i merged all 3 keymap files into 1, still i have the server name issue. If i leave the server to the default name still i am getting the below error.
    REP-51002: Bind to Reports Server Repsvr1 failed. However, i know the default rep_<servername> would be used incase we dont have SERVER=<value> parameter in the rwservlet.properties file.
    If i specify the servername in the rwservlet.properties file then only Repsvr1 reports are working fine and other 2 server reports are giving the same error like
    REP-51002: Bind to Reports Server <<Server Name>> failed.
    how can i configure the info which will work all 3 reports. 2 Port servers are invoking using oracle forms and report server is invoking using ASP pages.
    If i specify Server name & Key map file in rwservlet.properties one at a time, all the reports are working without any error, whenever i am trying to integrate all 3 to workable i am getting binding error. if i exclude the server from rwservlet.properties still i am getting the same error.

    My RELOAD_KEYMAP setting is YES only.As i said If i specify Server name & Key map file in rwservlet.properties one at a time, all the reports are working without any error.
    keymap file entries
    key1: server=Repsvr1 userid=xxx/yyy@dbname report=D:\Web\path1\path2\reports\Report1.rdf destype=cache desformat=PDF %*
    key2: server=Repsvr2 userid=xxx/yyy@dbname report=D:\Web\path1\path3\reports\Report2.rdf destype=cache desformat=PDF %*
    If i use http://server.domain:port/reports/rwservlet? cmdkey = key1 should bring the report from Repsvr1 and http://server.domain:port/reports/rwservlet? cmdkey = key2 should bring the report from Repsvr2, but i am getting an error from Repsvr2 saying that REP-51002: Bind to Reports Server repsvr2 failed.
    Only Servername Repsvr1 is in rwservlet.properties file. Now what is the best option to by pass the server from rwservlet.properties file and should be from keymap file. if i comment server name in rwservlet.properties file still i am getting REP-51002: Bind to Reports Server <<Server Name>> failed error for both keys.

  • Specifying a path to loada properties file

    I'm trying to load a properties file in java, the properties file is located in
    META-INF/sample.properties
    the class that loads the properties is in
    WEB-INF/classes/com/pkg1/pkg2/pkg3/pkg4/samplepgm.java
    how do I specify the path to load the properties file...

    you can only add images by using the place-function
    so you need to address the rectangle where the image is placed in.
    you can use use scriptlabels and then you can use something in the terms of
    document.Rectangles.Item("image").place(linktoyourfile)

  • Environment Variable Properties file

    Using log4j and creating a log4j properties file. "log4j.properties".. How do I specify the home directory in the properties file ? On command line I might use $HOME but I don't think that works in a properties file. I'd like any log file generated to be placed in a directory under the home directory. So the log4j.properties file needs to contain the line..
    log4j.appender.A2.File=$HOME/foo/log.txt
    But I'm seeing FNFE set file failed...

    Or, do what I should have done in the first place:
    read the API documentation for PropertyConfigurator
    where it says
    "All option values admit variable substitution. The
    syntax of variable substitution is similar to that of
    Unix shells. The string between an opening "${" and
    closing "}" is interpreted as a key. The value of the
    substituted variable can be defined as a system
    property or in the configuration file itself. The
    value of the key is first searched in the system
    properties, and if not found there, it is then
    searched in the configuration file being parsed. The
    corresponding value replaces the ${variableName}
    sequence. For example, if java.home system property
    is set to /home/xyz, then every occurrence of the
    sequence ${java.home} will be interpreted as
    /home/xyz."
    So your guess was close.Good to know I can do that with all variable names. I should have know to look at the API too. Thanks again :o)

  • Reading values from properties file

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

    Hi All,
    I am in need of a help from you all.I have a login.jsp which gets username and password as user input and checks in the servlet that if it was admin and admin it will take to index.jsp and if it was other than admin and other users it should take to index1.jsp.For now i am using an if condition to check the values and to dispatch the request.I need to use a properties file for this and need to check by getting the values from the properties file.And also it should check for each entry in properties file and if it finds any matches it should take to the corresponding page.
    Please help me in achieving this.
    Thanks,
    laxmi

  • How to use properties file

    Hi,
    I want to use properties file in my application. I have kept properties file inside a directory called properties which is inside myProject(which is the parent directory of my project) i.e "myProject/properties".
    My java file where i want to call this properties file is inside the myProject/WEB-INF/src/java.
    How can i call the properties file from myProject/WEB-INF/src/java/PropertyReader.java
    I wrote java program in myProject/WEB-INF/src/java/PropertyReader.java like:::::
    ResourceBundle resBun = ResourceBundle.getBundle("Test", Locale.getDefault()); // Test.properties is inside myProject/properties
    resBun..getString("name");
    After running the program i am getting the following errors:::::
    Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name Test, locale en_US
    at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:836)
    at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:805)
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:576)
    at PropertiesReader.main(PropertiesReader.java:4)
    What is the issue? How to use properties file?
    Waiting for reply.
    Thanks

    Still getting same exception. As you explained i tried like the below:::
    1. I am using ant as build tool.
    2. My properties file is for database configuration
    My properties file is::
    database.properties (inside myProject/properties)
    JDBCDriver=org.gjt.mm.mysql.Driver
    JDBCConnectionURL=jdbc:mysql://pmdbmysql:3306/bandwidthshaper?user=admin&password=admin
    My java package structure is
    WEB-INF/src/java
    WEB-INF/src/classes
    For build WEB-INF is the base directory and build.xml is inside the src directory
    In my build.xml i wrote the following lines for compilation::
              <target name="compile" >
                   <javac srcdir="src" destdir="src/classes" debug="true" debuglevel="lines,vars,source">
                        <classpath refid="class.path"/>
                   </javac>
    <copy todir = "src/classes" >
    <fileset dir = "../properties" />
    </copy>
                   <jar jarfile="lib/${project.jar.file}" basedir="src/classes"/>
              </target>
    I am copying properties file to the classes directory.
    Now in java file which is inside /WEB-INF/src/java, I wrote::
    try {
    Properties programProps = new Properties();
    InputStream is = getClass().getResourceAsStream("/database.properties");
    if(is == null)
    throw new IllegalStateException("Properties file missing ");
    programProps.load(is);
    System.out.println("driver name::::::: "+programProps.getProperty("JDBCDriver"));
    is.close();
    } catch(Exception e) {
    e.printStackTrace();
    After compilation in my classes directory i am getting database.properties file and my java file with package.
    At the time of running i am getting "java.lang.IllegalStateException: Properties file missing"
    Now tell me where is the fault. Why again i am getting exception.
    Thanks

  • Format Text in properties File

    I have a large amount of text for an element in the properties file that I'd like to format. I'm retrieving this value and displaying it in the tip of a panelLabelAndMessage ADF component. For example, in the properties file I have the following:
    displayparagraph=This is the first paragraph.This is a second paragraph I'd like on a new line.
    I'd like this text to be broken apart onto new lines when it displays in the tip element, like this:
    This is the first paragraph.
    This is the second paragraph I'd like on a new line.
    I'm not sure how to go about doing this or if it's even possible. I've tried placing \n, \\n, \r, \r\n, etc...inbetween the "." and "This" but this doesn't appear to work.
    I'd also like to a portion of that same message be underlined as a link...not sure if that is possible either.
    I have to keep the text in the properties file for translation purposes and I can't really break up the sentences into seperate elements to ensure that translations doesn't lose the meaning of the tip.

    Hi,
    If you set the escape property to false on your output components you can put HTML code in your properties file for the components that you want to format differently.
    Not all components can do this but the key ones like OutputText do.
    regards,
    Brenden

  • Setting up .properties file

    Hello
    I would like to know if theres any particular rules for setting up the .properties file. Like in my application i have four *.properties files
    1)log4j.properties 2) mapping.properties and so on
    the mapping.properties file have jsps mapping..so basically it says
    (key) add.project.param = (value)add_project.jsp
    project = project.jsp
    I am trying to understand how response.sendRedirect sends the appropriate link to project.jsp (view page) from add_project.jsp
    In add_project.jsp, response.sendRedirect is simply written as
    response.sendRedirect("tsaa.go?param=view&oid=" + parent + "&type=" + ptype);in my servlet dispatcher class; there are various functions two of them are
    1) void processRequest(HttpServletRequest request, HttpServletResponse response) { }
    2) String getForwardPage(HttpServletRequest request, HttpServletResponse response) { }
    and i think these classes take care of forwarding the request to appropriate page.
    If there are certain rules for setting up the mapping.properties file, do i have to set my new jsp pages in mapping.properties file as:
    quality.control.param = quality_control.jsp
    quality.control.results = quality_control_results.jsp
    (rite now i am using qc.results = quality_control_results.jsp and that doesnt seem to work)
    somehow response.sendRedirect("tsaa.go?param=view&oid=" + parent + "&type=" + ptype) doesn't seem to work in my quality_control.jsp page. Without the above line i can atleast move till quality_control.jsp page from home.jsp....but with response.sendRedirect().....i am on home.jsp after a refresh.
    if u know any links where i can read abt .properties file please let me know. googling gave me build.properties file but nothing for jsp mappings
    Any help is appreciated
    Thanx

    i got the solution
    please ignore the posting
    thanx

  • ServletContext Vs Properties file

    Dear Friends,
    My question is related to optimization.
    In our Servlet application, We have to read some values
    from properties files. In this which one is better from the following
    or is there any better way of doing?
    1. Reading from the Properties file everytime required. (So for each user the Properties file have to be accessed)
    or
    2. Reading from the Properties file once in the init method of the servlet and store those in the Servlet Context variables and use it whenever required.
    Please suggest me the best way.
    Thanks in advance.
    Regards,
    Goudham

    I think the best way would be to read the property
    file one time and store it as a hashtable and the last
    modified date, stored as a Long, should be stored up
    in a Hashtable, keyed on the filename. The Properties
    should be loaded from the file only if the last
    modified time in the Hashtable is less than the last
    modified time of the file, or if the filename isn't
    found. This insures that a modification check is done
    for each Properties file individually, and that they
    are all continually up to date. Also on server
    restart, all files are reloaded since they aren't
    initially listed in the Hashtable.
    Just a opinion
    -AsheeshThanks!
    If I understand correctly, Read the Properties file once and store the Key Value pairs in a Hashtable then maintain this Hashtable in ServletContext? Is this correct?
    - Goudham

  • Fuego.io.properties file

    I would like to know how to implement the properties file.I have the code for the properties file(key,value pairs defined) .In a process ,I have a global automatic activity where I am getting the values for the keys in properties file .My question is under what activity do I need to write the code for the properties file.How do I hook it up with the process that is using this properties file.Please help me as I am new to this tool.

    As per my understanding about your question let me reply for this.
    You can access the property file in any activity in the process. if the property values need to be accessed across the process then write the code once and assign the value to some instance variable where you dont need to write the code every where.
    Let me know if you have some specific scenario

  • Essbase Properties file

    Hi,
    We have essbase properties file in Essbase server and APS server. I am going to modify the essbase properties file in APS server to fix the excel time out issues. If I modify the properties file in APS,  Whether I need to modify the properties file in Essbase server also ? Just I want to know the difference between these files.
    Thanks,
    Aravindh K

    Hi Celvin,
    We have tried this method. But still we are getting time out issues. That's why we have planned to modify the properties file.
    But I have a question. The Essbase.cfig file in the essbase server and essbase.properties in the APS has the same parameters as shown below. Whether both files are used to set the time out properties for smart view?
      Properties file in APS
      Essbase.cfg 
      olap.server.netConnectRetry=3 
      netConnectRetry=30
      olap.server.netDelay=200 
      netDelay=2000
      olap.server.netSocketTimeOut=200 
      netSocketTimeOut=20000
      netRetryCount=6000
    Thanks,
    Aravindh K

  • Where to put properties files in EJB?

    is there a good standard place to put properties files for EJB?

    files. i wanted to jar everything together in a single
    ejb jar, and need to know if there is a standard or
    good place to keep those properties files so that
    whenever i move the ejb jar i dont have to worry about
    the paths to find those properties files.??? Both of my suggestions allow what you want. Neither one requires knowing any kind of file path. For example, packaging a properties files as my/fancy/data.properties entry in a jar will allow loading it as Properties ps = new Properties();
    ps.load (getClass().getResource("/my/fancy/data.properties").openStream(); (better code would also close() the stream in a finally block)
    The above depends on how the jar was packaged, not on its actual disk location.
    What's more, Class.getResource() also allows for package name-relative resource lookup which is convenient sometimes: http://www.javaworld.com/javaworld/javaqa/2002-11/02-qa-1122-resources.html

  • Unused log file using FileHandler for two Logger

    Hi,
    I'm having some troubles with the using java.util.logging classes. To demontrate my problem I prepared the following code:
    package org.prove.system;
    import java.util.logging.Logger;
    public class Child
         private static final Logger LOG = Logger.getLogger("org.prove.system");
         public static void main(String[] args)
              Child.LOG.info("I'm ready too!!!");
    package org.prove.logging;
    import java.io.IOException;
    import java.util.logging.FileHandler;
    public class ParentFileHandler extends FileHandler {
         public ParentFileHandler() throws IOException, SecurityException {
              super();
    package org.prove.logging;
    import java.io.IOException;
    import java.util.logging.FileHandler;
    public class ChildFileHandler extends FileHandler {
         public ChildFileHandler() throws IOException, SecurityException {
              super();
    }and the following is the configuration inside my logging.properties file
    # Loggers configuration
    org.prove.handlers = org.prove.logging.ParentFileHandler
    org.prove.level = ALL
    org.prove.useParentHandlers = false
    org.prove.system.handlers = org.prove.logging.ChildFileHandler
    org.prove.system.level = ALL
    org.prove.logging.ParentFileHandler.pattern = %h/logs/Parent.%u.log
    org.prove.logging.ParentFileHandler.formatter = java.util.logging.SimpleFormatter
    org.prove.logging.ParentFileHandler.append = true
    org.prove.logging.ChildFileHandler.pattern = %h/logs/Child.%u.log
    org.prove.logging.ChildFileHandler.formatter = java.util.logging.SimpleFormatter
    org.prove.logging.ChildFileHandler.append = trueNow, if you try my example you can find, inside the "logs" directory specified in the configuration file, some files:
    - Child.0.log, which is the file for the org.prove.logging.ChildFileHandler;
    - Parent.0.log, which is the file for the org.prove.logging.ParentFileHandler.
    but you can also find:
    - Parent.1.log;
    - Parent.1.log.lck.
    In particular the last two files are generated by the initialization of the org.prove.logging.ParentFileHandler, because inside the method addLogger of the LogManager class, after the initialization of the demanded logger there is a cycle to identify the parent of the logger itself.
    Inside that cycle is invoked again the method demandLogger that, if not already initialized, creates the Logger, and after instantiates the handlers of that logger, generating the Parent.1.log and its lock file Parent.1.log.lck. This files are not used and at the end of the execution the lock file is not deleted as the others.
    I hope my problem is clear and someone can help me to identify how to resolve it.
    Thanks in advance
    Alessandro Cristiani

    It is not possible to redirect the two different type of logs by using same log level. you have to use to different log levels for both and then in your code you have to mark specifically.
    to do this you can use log levels ERROR (for exceptions) and FATAL (for errors).
    First define your own logger class that will be using the log4j API's
    import org.apache.log4j.Logger;
    public class MyLogger {
       static Logger log = Logger.getLogger(MyLogger.class);
       public static logThrowable(Throwable th){
           if(th instanceof Exception) {
              log.error(th.getMessage());
           } else {
               log.fatal(th.getMessage());
    }and for your log4j.xml
    change the level for your ERROR_FILE to FATAL
    in your LogExample
    remove:
    static Logger log = Logger.getLogger(LogExample.class);change:
    }catch(Exception e){
    log.error("Exception e");
    }to
    }catch(Throwable e){
    MyLogger.logThrowable(e);
    }Hope this helps. Or if you do not want to do in this way then you can also create your own log levels. It is not advisable but you can certainly do that.
    Please visit [Log4j Manual|http://logging.apache.org/log4j/1.2/manual.html] for more on this.

  • "The system cannot find the file specified" - error reading properties file

    I have packaged a class file and a .properties file in the same folder as a ejb-jar file and in the class file i try reading the properties file and it throws me the error - "The system cannot find the file specified". But when I put the complete path, it has no problem finding the file.
    I know that this must be the problem with classpath, but can anybody tell me why it is not finding the properties file even if they are in the same folder. How do I make class files find .properties file which are in a folder.
    Any help will be greatly appreciated.

    Hi,
    I am not sure if your question is realted to the Oracle Application Server - anyway, if you are packaging a class file and a properties file in a JAR File, you need to read the contents in a different manner...something like this... :
    URL url = new URL("jar:file:/home/duke/duke.jar!/");
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    You might want to have a look at this link for more information :
    http://java.sun.com/docs/books/tutorial/index.html
    You may also get better responses if you post your question in one of the Java Forums.
    Regards,
    Sandeep

  • URGENT!!! can I borrow a valid jserv.properties file for a JSP application ?

    Hi there !
    I'm running Oracle enterprise edition on NT with oracle http server under apache.
    I created a JSP application using jdeveloper
    and deployed it to the web server.
    Now I'm still getting getting nullPointer exceptions after I have modified the jserv.properties file according to the documentation
    Can someone give me a file that is working for her/him under the above described circumstances ?
    Many Thanaks in advance
    Tony
    null

    laredotornado wrote:
    Hi,
    This might not be a JSF question, but I thought I'd start here as I'm building a JSF application. Upon startup of my Weblogic 9.2.2 server, I see these error messages
    log4j:WARN No appenders could be found for logger (org.apache.myfaces.webapp.StartupServletContextListener).
    log4j:WARN Please initialize the log4j system properly.
    One complication, my log4j.properties file is actually called "my.properties" (bizarre company reason). Is there somewhere in my faces-config.xml file or an equivalent where I can indicate what log4j properties file I'd like to use?Your company policy is to use non-standard names so that things must be configured manually? Interesting.
    In the past people created a servlet those sole purpose was to configure log4j in the initialization sequence and then do nothing.

Maybe you are looking for

  • How do I input a specific color value for a shape?

    I've been trying to figure out why I cannot input a specific color that I want for a shape. I'm not just choosing a color that looks nice, I'm trying to match it to a solid color in the next clip. Ive tried to use the eye dropper to get the color fro

  • Airport Express has stopped working

    Hi. My AE has just stopped working and now can't connect to the network.  I have tried a harware reset and all I get is the amber light and now and again it flashes then turns green and then back to amber.  It looks to me as if the something has dama

  • Legal control--- legal regulation.

    Hi Can anyone please give the difference between legal control and legal regulation. I have little bit confusion between these two. please provide some examples.

  • Trying to default a cost plan for PS from a CRM contract?

    I am trying to default a cost plan (akin to a budget maintained in IM) onto CJ40. This cost plan will be defaulted via a CRM table maintained especially for the appropriation/budget. Has anyone defaulted a cost plan onto CJ40 and if so how? Thanks in

  • Index/Search Question

    Hello all, Can someone tell me how I would go about and set up my Index OR search criteria so that whenever I perform a search that only file names are searched and not the actual contents of the documents? For example, as it is setup right now, if I