Java.util.logging.XMLFormatter - need advise

Hi all,
I have this class which suppose to write some message into the custom log file (in XML). Problem is, after the first time of writing it into the same file, it will append additional XML header :
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
Worse, it will always append below.
For example, the original XML file contains:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
  <date>2010-10-20T18:18:33</date>
  <millis>1287569913671</millis>
  <sequence>0</sequence>
  <logger>atm.controller.Log_Controller</logger>
  <level>INFO</level>
  <class>atm.controller.Log_Controller</class>
  <method>writeInfoLog</method>
  <thread>10</thread>
  <message>message inside thia standard data</message>
</record>
</log>when I write additional message into the same file using logger.info("some message"); on the second rounds, it will append additional XML header* info and become like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
  <date>2010-10-20T18:18:33</date>
  <millis>1287569913671</millis>
  <sequence>0</sequence>
  <logger>atm.controller.Log_Controller</logger>
  <level>INFO</level>
  <class>atm.controller.Log_Controller</class>
  <method>writeInfoLog</method>
  <thread>10</thread>
  <message>message inside thia standard data</message>
</record>
</log>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
  <date>2010-10-20T18:21:25</date>
  <millis>1287570085050</millis>
  <sequence>0</sequence>
  <logger>atm.controller.Log_Controller</logger>
  <level>INFO</level>
  <class>atm.controller.Log_Controller</class>
  <method>writeInfoLog</method>
  <thread>10</thread>
  <message>message inside thia standard data</message>
</record>
</log>--------------------------------------------------
Below is the code.
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.XMLFormatter;
public class Log_Controller
    private static Logger logger = Logger.getLogger( Log_Controller.class.getName() );
    private boolean allowAppend = true;
    public Log_Controller()
        try
            XMLFormatter formatterTxt = new XMLFormatter();
            FileHandler fileTxt = new FileHandler( "test.xml", allowAppend );
            fileTxt.setFormatter( formatterTxt );
            logger.addHandler( fileTxt );
        catch ( IOException ioe )
            ioe.printStackTrace();
    public void writeInfoLog( String message )
        logger.info("message inside thia standard data");  //THIS IS THE PART WHERE IT WRITE SOME MESSAGE INTO THE FILE
//        logger.info( message );
}This is something new to me, appreciate if someone can point me what the mistake that I have done.
Thanks thanks.
Edited by: 803699 on 20-Oct-2010 04:15
Edited by: 803699 on 20-Oct-2010 08:45

you cannot append to an xml file using the standard formatter because it makes the log file a "complete xml document" (header and root wrapper tags). if you want to be able to append to an existing xml log file, you will need to roll your own formatter.

Similar Messages

  • Can't create log file with java.util.logging

    Hi,
    I have created a class to create a log file with java.util.logging
    This class works correctly as standalone (without jdev/weblogic)
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.*;
    public class LogDemo
         private static final Logger logger = Logger.getLogger( "Logging" );
         public static void main( String[] args ) throws IOException
             Date date = new Date();
             DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
             String dateStr = dateFormat.format(date);
             String logFileName = dateStr + "SEC" + ".log";
             Handler fh;          
             try
               fh = new FileHandler(logFileName);
               //fh.setFormatter(new XMLFormatter());
               fh.setFormatter(new SimpleFormatter());
               logger.addHandler(fh);
               logger.setLevel(Level.ALL);
               logger.log(Level.INFO, "Initialization log");
               // force a bug
               ((Object)null).toString();
             catch (IOException e)
                  logger.log( Level.WARNING, e.getMessage(), e );
             catch (Exception e)
                  logger.log( Level.WARNING, "Exception", e);
    }But when I use this class...
    import java.io.File;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.FileHandler;
    import java.util.logging.Handler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.logging.XMLFormatter;
    public class TraceUtils
      public static Logger logger = Logger.getLogger("log");
      public static void initLogger(String ApplicationName) {
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateStr = dateFormat.format(date);
        String logFileName = dateStr + ApplicationName + ".log";
        Handler fh;
        try
          fh = new FileHandler(logFileName);
          fh.setFormatter(new XMLFormatter());
          logger.addHandler(fh);
          logger.setLevel(Level.ALL);
          logger.log(Level.INFO, "Initialization log");
        catch (IOException e)
          System.out.println(e.getMessage());
    }and I call it in a backingBean, I have the message in console but the log file is not created.
    TraceUtils.initLogger("SEC");why?
    Thanks for your help.

    I have uncommented this line in logging.properties and it works.
    # To also add the FileHandler, use the following line instead.
    handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandlerBut I have another problem:
    jdev ignore the parameters of the FileHandler method .
    And it creates a general log file with anothers log files created each time I call the method logp.
    So I play with these parameters
    fh = new FileHandler(logFileName,true);
    fh = new FileHandler(logFileName,0,1,true);
    fh = new FileHandler(logFileName,10000000,1,true);without succes.
    I want only one log file, how to do that?

  • Java.util.logging question

    'Lo all -
    I'm new to Java, so bear with me on this question - I'm sure it has a simple answer.
    I am using the following code to create a new Logger object:
    public class TAGLogging {
        private Logger oLog;
        private FileHandler oLogFile;
        private String sLoggingFolder = "AppLogs";
        private String sFormattedDateTime = String.format("%1$tY%1$tm%1$td_%1$tH%1$tM%1$tS",Calendar.getInstance());
        private String sCallingClass = new Throwable().fillInStackTrace().getStackTrace()[1].getClassName();
        private String sCallingMethod = new Throwable().fillInStackTrace().getStackTrace()[1].getMethodName();
        /** Constructors */
        public TAGLogging(String sLogFileName) throws IOException {
            this.initialSetup(sLogFileName);
        public TAGLogging() throws IOException {
            String sLogFileName = sLoggingFolder + File.separator + sFormattedDateTime + ".xml";
            this.initialSetup(sLogFileName);
        /** Methods */
        private void initialSetup(String logFileName) throws IOException {
            oLogFile = new FileHandler(logFileName);
            oLog = Logger.getLogger(sCallingClass);
            oLog.addHandler(oLogFile);      
            oLog.setLevel(Level.ALL);
        }Everything is being logged correctly to the /AppLogs/yyyymmdd_HHMMSS.xml file. The problem is that there is another file that is being created in my home directory, which incidentally, is not where the program is located. The name, java01.log, matches the default logging.properties file set up, but I have removed all that and changed the file to the following (minus all the comments):
    handlers= java.util.logging.FileHandler
    .level= INFO
    java.util.logging.FileHandler.level = ALL
    java.util.logging.FileHandler.limit = 50000
    java.util.logging.FileHandler.count = 1
    java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
    java.util.logging.ConsoleHandler.level = INFO
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    The java01.log file contains the exact same contents as the file I am purposely logging to, the AppLogs/yyyymmd_HHMMSS.xml one.
    Does anyone have any clue what is causing this file to get created, and if so, how do I stop it?
    Message was edited by:
    malakh

    Man, I REALLY hate to do this, but it looks like I may be forced to work around it instead of fixing the issue. I'll have to add some code to manually remove the java01.log file when it's done writing to it.
    Navy - Turns out that Log4j is pretty much the same thing as java.util.logging, except on steroids. It is almost identical syntactically, just has more options and more flexibility than JUL.

  • Java.util.logging: write to one log file from many application (classes)

    I have a menuapp to launch many applications, all running in same JVM and i want to add logging information to them, using java.util.logging.
    Intention is to redirect the logginginfo to a specific file within the menuapp. Then i want all logging from all applications written in same file. Finally, if needed (but i don't think it is), i will include code to write logging to specific file per app (class). The latter is probably not neccessary because there are tools to analyse the logging-files and allow to select filters on specific classes only.
    The applications are in their own packages/jars and contain following logging-code:
            // Redirect error output
            try {
                myHandler = new FileHandler("myLogging.xml",1000000,2);
            } catch (IOException e) {
              System.out.println("Could not create file. Using the console handler");
            myLogger.addHandler(myHandler);
            myLogger.info("Our first logging message");
            myLogger.severe("Something terrible happened");
            ...When i launch the menuapplication, it writes info to "myLogging.xml.0"
    but when i launch an application, the app writes info to "myLogging.xml.0.1"
    I already tried to leave out the creation of a new Filehandler (try/catch block in code above) but it doesn't help.
    Is it possible to write loginfo to same specific file?

    You should open/close it somehow at every write from different processes.
    But I personally prefer different file names to your forced merging, though.

  • Getting no output from java.util.logging.FileHandler

    I am new to Java as is the company I work for, but we have just landed a contract that specifies J2EE as the platform, so here we are. :-) Please bear with me.
    I have been charged with determining our logging architecture and it looks like what is available in java.util.logging will do well (though we may use log4j). However, at this point I am just trying to get anything to work and not having much luck.
    We are using JSF on the front end and I have created a very simple JSF page to test logging. The relevant code is below and I hope will be self explanatory: This code is not meant to be efficient or anything. It is just a proof of concept.
        public String button1_action() {
            // User event code here...
            try {
                Logger l = java.util.logging.Logger.getLogger(Page1.class.getName());
                l.entering(Page1.class.getName(), "button1_action");
                l.info(this.textField1.getValue().toString());
                l.exiting(Page1.class.getName(), "button1_action");
                java.util.logging.Handler h = l.getHandlers()[0];
                h.flush();
            catch(Exception ex) {
                //I have tested this and we aren?t catching any errors.
                System.err.println(ex);
            return "";
        }My logger.properties files looks like this:
    handlers= java.util.logging.FileHandler
    .level= FINEST
    java.util.logging.FileHandler.pattern = c:/sun/logs/test-%u.log
    java.util.logging.FileHandler.limit = 50000
    java.util.logging.FileHandler.count = 1
    java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatterI have developed and tested this in Sun Studio Creator 2004Q2 What is happening is that I am getting three log files in c:/sun/logs
    test-0.log, test-1.log and test-2.log. The first two contain output from various sun components. (sun.rmi.transport for example). The third log remains empty. (zero length)
    I have also deployed the test app to a tomcat 5.0.28 server and get similar results. The only difference is I get only one two log files and the second one remains empty.
    Any assistance or suggestions as to what direction I should be taking would be appreciated.
    --Ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Do not use default logger as getLoggers[0] , but use your java.util.Logger.FileHandler and add filehandler object to log your fButtonActions and you do not need to mess with logger.properties too.

  • How to prevent java.util.logging from displaying pop-up dialog on SEVERE?

    Hi,
    I'm new to using java.util.logging. I notice that whenever I try to make a call to logger.SEVERE(msg) or logger.WARNING(msg), not only does it write the output to file (which I want), but it also pops up a dialog box displaying the exception. I don't want this pop up to appear. How do I prevent the logger from doing this?

    What are you talking about?
    Hello,
    In order to better assist you with your issue please provide us with a screenshot. If you need help to create a screenshot, please see [[How do I create a screenshot of my problem?]]
    Once you've done this, attach the saved screenshot file to your forum post by clicking the '''Browse...''' button below the ''Post your reply'' box. This will help us to visualize the problem.
    Thank you!

  • Creating a new Handler (java.util.logging API)

    Hi,
    I'm developping a new Handler (extending the java.util.logging.StreamHandler) and I need to get some initialisation properties from the LogManager. I was taking example from the existing Handlers (SocketHandler, FileHandler...) and wanted to use the LogManager.getLevelProperty, getFilterProperty and so on). Unfortunately these methods are not public.
    Is there any good reason for that ? As we are still dealing with a beta version, can't we have them public (same old Open Source problem).
    Antonio

    I am in a similar situation and agree completely with the above comments. Using the LogManager getProperty() is incredibly cumbersome.
    Ciao Ric

  • Help with java.util.logging SocketHandler - Simple TCP Server

    I have a simple TCP serverString clientSentence;
                 ServerSocket welcomeSocket = new ServerSocket(5050);
                 while(true) {
                    Socket connectionSocket = welcomeSocket.accept();
                    BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                    while ((clientSentence = inFromClient.readLine()) != null) {
                         System.out.println("Received: " + clientSentence);
                 }And I have a java.util.logging logger using a SocketHandler. I'm just calling logger.log("my message"); I get the expected result to System.out: "my message". But when I go on to call again logger.log("my next message") I get both messages in queue: "my message" and "my next message" on the next line. So, I get from these two calls to logger.log() the following result in System.out
    my message
    my message
    my next message...whereas I expected
    my message
    my next messageWhy is "my message" being saved even after being passed through the TCP connection to the server? I tried handler.flush() but that doesn't help. Pretty sure the problem isn't at the server end because when I create two loggers with their own SocketHandlers the server doesn't double up on their messages. (In other words, if I let one logger say simply "my message" and the second logger say "my next message" I get the expected output. It's like each logger needs to be flushed after sending to the server.
    Any advice appreciated.

    Yes, I was just rereading your post and it's apparent that you were suspecting the client code. Your posting only the server led me to believe that you were focusing on that and I kind of skipped over the last part.
    So to answer your question, yes, the server code looks okay. And you were suspecting the client anyway, so problem solved.

  • Using java.util.logging Properly

    Hello,
    I have implemented java.util.logging in my application by creating a kind of "wrapper" class that I call for handling logging. It doesn't extend the logging classes, it just provides an object with helper methods that I can call when I want it.
    public class LogCleanerLogger {
        private static final String cleanerLogfile = "logcleanerlog%g.txt";
        private static final String loggerName = "LogCleaner";
        private Logger cleanerLogger = null;
        public LogCleanerLogger() throws IOException{
            this.cleanerLogger = Logger.getLogger(getLoggerName());
            cleanerLogger.setUseParentHandlers(false);
            FileHandler logFile = new FileHandler(getCleanerLogfile(),10000,1, true);
            logFile.setFormatter(new SimpleFormatter());
            cleanerLogger.addHandler(logFile);
        public void writeLogInfoMessage(String message){
            cleanerLogger.info(message);
        public void writeLogWarningMessage(String message){
            cleanerLogger.warning(message);
        public void writeLogErrorMessage(String message){
            cleanerLogger.severe(message);
    // getters and setters
    } // end class    This all works quite happily and I can log any information I want. Except for one thing -- my log directory ends up with the log file (logcleanerlog0.txt) and a list of what appear to be temporary logs, e.g. logcleanerlog0.txt.1, logcleanerlog0.txt.2, and so on. Each increment of the number corresponds to a log file that has progressively less information in it that the previous one. At the top level, the unnumbered log, logcleanerlog0.txt, has all the logged information in it.
    I cannot make out, from reading the API and other documentation, how I can get rid of these other files, which appear to me to be temporary files used in the construction of the top level file.
    Can someone help me by explaining the mechanism for generating these files and either (a) how I can get rid of them altogether or (b) how I can arrange for them to be generated in a temp dir, while keeping the main log in the present directory (application root).
    Or perhaps there is a "better way" (that is equally as easy, of course ;-).
    Thanks.
    mp

    are you sure you cannot use the classes from a newer
    version. You can put those classes in your own
    directory. If there ar some other classes that need to
    be from the newer version, you can include them, also
    in your project. It is important that your project
    directory to be placed in the classpath variable
    before the jdk jars.
    (this solution might not work)I doubt that is worth trying.
    First, although it probably does not apply in this case, you are not allowed to distribute part of a JVM. So you could never use this solution in a commercial application.
    Secondly the Java API does change. And every execution path that might use the changed code would have to be tested. That is going to take a lot of work. Keep in mind that the logging api uses java.lang.String and java.lang.String definitely changed in 1.4 and almost every class in the Java API uses it.

  • Where to find .jar files so I can implement import java.util.logging

    I'm trying to figure out how to take an application built for Websphere and port it to WebLogic. I've come across this blog entry http://blogs.sun.com/fkieviet/entry/using_java.util.logging_in_bea_weblogic and would like to try creating and using the startup class.
    I have not been able to find the correct jar files.
    import weblogic.common.T3ServicesDef;
    import weblogic.common.T3StartupDef;
    import weblogic.logging.LoggingHelper;
    In reading the documentation on using the NonCatalogLogger APIs at http://download.oracle.com/docs/cd/E12840_01/wls/docs103/i18n/writing.html I also see some code calling for the following imports
    import weblogic.jndi.Environment;
    import weblogic.logging.NonCatalogLogger;
    1. Does anyone know where I can grab these?
    2. There must be a strategy for finding these .jars that people use. If so, what is it?

    I thought I understood you, but the more I look at what you've set here, I'll just be honest and admit that the I don't know what you are saying here:
    'You should be able to add the "weblogic.jar" in the WebLogic distribution to your classpath.' - What doe this mean?
    1. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add external JARS and navigate to the weblogic.jar
    2. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add Library and try to go from there?
    3. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath / Libraries - Select Add Variable and try to go from there?
    4. Go to my xxxWeb app Dynamic Web Project and right-click and select Build Path / Configure Build Bath and do something else?
    5. Something else?
    Also, I don't know what you mean here:
    'You don't need to (and you shouldn't) copy that jar file, just have it in your compilation classpath. It will be present automatically at runtime.'
    Sorry for being so simple here but I've been trouble shooting why I can't follow what look like pretty simple steps to implement over-riding the ApplicationLifecycleListener Class to use existing java.util.logging.Logger code by adding the following to the the weblogic-application.xml:
    <wls:listener>
         <wls:listener-class>com.qualcomm.weblogic.log.listener.UtilLogWrapper</wls:listener-class>
    </wls:listener>
    And including as a referenced jar file, a simple POJO class instance of com.qualcomm.weblogic.log.listener.UtilLogWrapper.
    My resrouces for this are:
    1. http://blogs.sun.com/fkieviet/entry/using_java.util.logging_in_bea_weblogic.
    2. http://www.oracle.com/technology/pub/articles/drolet-ant.html.
    Maybe my weblogic.jar is at the root of the problem.
    I hope you can 'dumb this down' for me with a simple explanation of steps to do what you outlined above.

  • Subclassing java.util.logging.LogManager

    i am trying to subclass the LogManager class and have tried adding the following System property as mentioned in the Java API :-
    java.util.logging.manager = CustomLogger
    where,
    CustomLogger is the name of my subclass of LogManager.
    Still, when I ran the program, the instance of the global log manager (java.util.logging.LogManager) is only created. It's not creating the instance of "CustomLogger".
    I have tried to give the full package name of the subclass as follows, still it is creating the instance of java.util.logging.LogManager only:-
    java.util.logging.manager = com.test.logging.CustomLogger
    Any pointers to resolve this issue will be of great help..
    ~Thanks
    Dev

    devdas_kushe wrote:
    I checked the LoggingPermission stuff, but could not figure out how it works..And did you check the IllegalAccessException stuff too? Like the documentation, which says:
    An IllegalAccessException is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, but the currently executing method does not have access to the definition of the specified class, field, method or constructor.My guess is your class has a private constructor. This could happen if somebody had the bright idea of applying the Singleton pattern to it. If that's the case, drop the Singleton idea in favour of the Just Create One Of Them idea.
    And I second what the others said about (a) preferring Log4J and (b) you probably not needing a custom LogManager.

  • Enabling java.util.logging for Toplink

    JDeveloper 10.1.3.0.4 Build 3673 running Embedded OC4J (jdk1.5.0_02).
    I'm trying to get Toplink to log to a custom handler (a la java.util.logging) while running Embedded OC4J, but nothing I've tried works.
    If I use the java.util.logging.LogManager to loop through and print out all of the existing loggers, none of the 145 listed in the Embedded OC4J environment mention anything about toplink. So presumably Toplink is not running in "java" logging mode. I'm not using toplink workbench which seems to have a UI checkbox to enable java logging, and I haven't found a way to turn it on using JDeveloper. I've tried using the system property -Dtoplink.log.destination=JAVA (no effect) and adding my handler to j2ee-logging.xml (couldn't find my custom logging handler class, and won't help anyway if toplink isn't using java.util.logging), and various attempts at hacking sessions.xml with using log-type and java-log elements (I couldn't get them right--xml parse errors).
    What do I need to do to get Toplink to log to a custom handler?
    TIA,
    Clark

    Hi Clark,
    You can use either java or server log when running an application in OC4J.
    1 When you run a CMP application, use system property (e.g. Dtoplink.log.destination=JAVA)
    2 When you run a non CMP server application, use the logging tag in sessions.xml (e.g. <logging xsi:type="server-log"/>)
    You have the following options to get TopLink to log to a custom handler
    1 If you want to do the entire configuration from logging.properties, remove all handlers/loggers declarations from j2ee-logging.xml and in that case all configuration will be from logging.properties
    2 Use a combination of j2ee-logging.xml and logging.properties. You can define certain attributes in j2ee-logging.xml. They are "name", "class", "level", "errorManager", "filter", "formatter" and "encoding", and they correspond to the attributes of java.util.logging.Handler. Attributes in subclasses of Handler are not supported. All other properties for the handler are defined in logging.properties. j2ee-logging.xml is processed on top of logging.properties, which means j2ee-logging.xml takes the precedence for certain attributes/properties. Take FileHandler for an example,
    j2ee-logging.xml:
         <log_handlers>
         <log_handler name='my-handler' class='java.util.logging.FileHandler'
              formatter='java.util.logging.SimpleFormatter' level='INFO'/>
         </log_handlers>
    logging.properties:
         java.util.logging.FileHandler.pattern = %h/java%u.log
         java.util.logging.FileHandler.limit = 10000
         java.util.logging.FileHandler.count = 2
    If there are no properties defined in logging.properties, it will use its default values, which are documented in the FileHandler javadoc.
    Shannon

  • Unable to capture messages from java.util.logging

    I have a class called (Caller.java) which invokes a method called foo from another java class(Util.java) using reflection API.Now this method foo logs messages using Java's logger.My requirement is to call foo for 3 times from Caller and capture/redirect the log messages into 3 log files.
    But only the first log file is capturing the log messages(from logger) and other two are not ?
    Plz suggest if I am doing somethin wrong here ?
    Caller.java
    package project2;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintStream;
    import java.lang.reflect.Method;
    public class Caller {
        public Caller() {
        public static void main(String[] args) throws Exception {
            Caller caller = new Caller();
            for (int i = 0 ;i<3 ;i++ )  {
                caller.createLogStream(i);
                System.setOut(caller.getPs());
                System.setErr(caller.getPs());
                /*****************Invoking Util.java*****************************/
                Class clas = Class.forName("project2.Util");
                Method m = clas.getMethod("foo",null);
                Object obj =clas.newInstance();
                m.invoke(obj,null);
        public void createLogStream(int i) throws FileNotFoundException {
            ps = new PrintStream(new File(System.getenv("HOME")+File.separator+"MyLog"+i+".log"));
        public void closeLogStream(){
            ps.close();
            ps = null;
        private PrintStream ps = null;
        public PrintStream getPs() {
            return ps;
    } Util.java
    package project2;
    import java.util.logging.Logger;
    public class Util {
        Logger logger = null;
        public Util() {
            logger = Logger.getLogger(this.getClass().getName());
        public void foo(){
            System.out.println("Hello out stream");
            System.err.println("Hello error stream");
            logger.info("This is an information");
            logger.warning("This is a warning message");
            logger.severe("This is fatal!! ");
    }First Log file MyLog0.log:
    Hello out stream
    Hello error stream
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!!
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!!
    Feb 16, 2009 7:55:55 PM project2.Util foo
    INFO: This is an information
    Feb 16, 2009 7:55:55 PM project2.Util foo
    WARNING: This is a warning message
    Feb 16, 2009 7:55:55 PM project2.Util foo
    SEVERE: This is fatal!! Other 2 log files have only this much
    Hello out stream
    Hello error stream

    A stale Connection Factory or Connection Handle may be used in SOA 11g
    Regards,
    Anuj

  • Doubt in java.util.logging

    Hi,
    I have doubt in logging api provided in java 1.4.
    I have a simple program to get the logger and output log into it.
    This is how the program looks.
    LogTest.java
    import java.util.logging.*;
    import java.util.*;
    public class LogTest {
    public static void main(String args[]) {
         LogManager manager = LogManager.getLogManager();
         Logger l = manager.getLogger("global");
         System.out.println(l);
         l.severe("Test");
         System.out.println(manager.getLogger("ivy"));
         System.out.println(manager.getLogger("test"));
    I able to get the instance of the global logger, but im not able to get instance of other logger. I getting null for all the other logger
    test.properites
    =================
    handlers = java.util.logging.ConsoleHandler
    java.util.logging.ConsoleHandler.level=INFO
    java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
    ivy.level = INFO
    .ivy.level = INFO
    =================
    Compilation Command
    java -Djava.util.logging.config.file=C:\WorkSpace\test.properties LogTest Output:
    java.util.logging.Logger@13f5d07
    Jan 25, 2006 7:19:24 PM LogTest main
    SEVERE: Test
    null
    null
    I also tried the same with no config properties, Still im getting the null for logger.
    Can I know is there anything that im missing. Is there any property that must be set or do i hav set some config properties.
    Thanks,
    Siva

    Well, basically that's part of the formatdefinition
    that Properties uses. If you don't do it, then you
    aren't really using Properties format and you'llhave
    to do your own IO.Thanks for the reply. Is there anyother api or class
    that can be used to resolve my problem.What is the problem? A character is escaped, but you will get : when you read the value. You don't have a problem as long as all reading / writing is done through that class.

  • How is java.util.logging used to log to unix syslog?

    I'm trying to log out to syslog using the java.util.logging that is now in 1.4. I've read all I can find on this topic (not much) and have solicited the used of some syslog free ware (protomatter) but still can't get this to work. I feel like I'm missing something simple here, any help would be appreciated....
    Here is my latest attempt:
    import java.util.logging.*;
    import java.util.*;
    import java.io.*;
    import com.protomatter.syslog.SyslogHandler;
    public class SyslogTest
    public static void main(String argv[]){
    Logger logger2 = Logger.getLogger("local3");
    SyslogHandler ch = new SyslogHandler();
    ch.setLevel(Level.WARNING);
    logger2.addHandler(ch);
    logger2.warning("this is a log message");
    if (logger2.isLoggable(Level.WARNING)) {
    System.out.println("Is LOGGABLE");
    else {
    System.out.println("Is not loggable");
    When this is run nothing is printed to any of the local3 facilities. I've verified that syslog is running fine from the command line using unix logger, so the problem seems to be isolated to my java.
    Thanks.

    Hi,
    What is in your logging.properties file? Can you also include the contents of this file?
    Cheers,
    Craig.

Maybe you are looking for