Formatting Log message for Java.Util.Logger

Hi,
I want to format out put that i get when i logg the message
example
Sep 23, 2009 5:32:56 PM com.log.utils.helper info
INFO: in Logging messagingI was wondering if I could get output like
Sep 23, 2009 5:32:56 PM INFO: in Logging messagingThis is the code which i have used to generate logs
public Logger logs() {
        makeLogFolder();
        Logger log = Logger.getLogger(UtilityHelper.class.getName());
        try {
            int limit = Integer.parseInt(loadProperties(
Constants.PROPERTY_FILE_NAME)
.getProperty(Constants.MAX_SIZE_OF_LOG_FILES));
            int numLogFiles = Integer.parseInt(getProperties(
Constants.MAX_NO_OF_LOG_FILES));
            String LogFileName = getProperties(Constants.LOG_FOLDER) +
File.separator + getLogInDate() + File.separator +
getProperties(Constants.LOG_FILE) + getLogDate() +
" " + getLogTime() + "_%g.log";
            FileHandler fh1 = new FileHandler(LogFileName, limit, numLogFiles);
            fh1.setFormatter(new SimpleFormatter());
            log.addHandler(fh1);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (SecurityException ex) {
            ex.printStackTrace();
        return log;
log.info(message);please let me know how can i do it
thanks for the reply

Note: This thread was originally posted in the [Java Virtual Machine (JVM)|http://forums.sun.com/forum.jspa?forumID=37] forum, but moved to this forum for closer topic alignment.

Similar Messages

  • Usage of java.util.Logger

    I have an API which has logs messages using java.util.Logger.
    While using this API to perform activities, i need those log messages to tell me when something is going wrong. How can I view those log messages in console?
    For eg: I have a class with following structure:-
    public class sample
    public static void main (String[] args)
    APIClass api = new APIClass();
    api.doStuff();
    Now i want the messages which are printed inside api to appear in my system console, but only SEVERE messages seems to come out, not INFO, FINE etc.
    Please let me how i can achieve this?

    I was able to get the messages out by following
    java.util.logging.Logger LOGGER = java.util.logging.Logger.getLogger("com.foo");
    java.util.logging.ConsoleHandler ch = new java.util.logging.ConsoleHandler();
    ch.setLevel(Level.FINE);
    LOGGER.addHandler(ch);
    LOGGER.setLevel(Level.FINE);

  • 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

  • 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?

  • For weeks I have been viewing a doggy day care via their web cam.  This weekend I upgraded to Lion and have been unable to view the center since.  I get an error message for java webcam class not found.  All of my software is up to date--suggestions?

    For weeks I have been viewing a doggy day care center via their web cam.  This weekend I upgraded to Lion and have been unable to view the center.  I get an error message for Java plug-in 1.6.0_29 ....webcam class not found.  Any suggestions on how to fix this?

    Sorry, don't know what else to suggest unless there's a URL to the problem stream that someone here can try. Otherwise we can't test it to try and determine what might be wrong.
    BTW, make sure they're testing it with a Mac, not with a Windows system. If they test only with Windows, what they say is or is not working doesn't mean much.
    Regards.

  • RFC used for java.util.regex

    Hi,
    Does anyone know the RFC used for java.util.regex ??
    Thanks & Regards,
    Gurushant Hanchinal

    Can you please give me the link to view to specifications for java.util.regex.. I have tried the link which is available in :
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html page with name " Java Language Specification"
    on click of this link, i am getting page not found error..
    Please give me any other alternate links to view the regular expression specifications..
    Thanks,
    Gurushant Hanchinal

  • OracleLog.properties for java.util.logging

    In the Oracle JDBC FAQ the answer to the question "How do I configure java.util.logging to get useful trace output from Oracle JDBC?" <http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#36_03> mentions the file "OracleLog.properties" provided in the "demo.zip" file.
    I cannot find the file "OracleLog.properties" anywhere?
    Any suggestions?
    Kindest Regards,
    Gerhard Hofmann

    It seems a logger instance HAS been created for my Test class, I've added the lines below. Though it didn't appear in the logger names enumeration.
    java.util.logging.Logger logger = java.util.logging.Logger.getLogger(name);
    System.out.println(logger.getName()+"="+logger.getLevel().getName());
    logger.severe("severe");
    logger.warning("warning");
    logger.info("info");
    logger.config("config");
    logger.fine("fine");
    logger.finer("finer");
    logger.finest("finest");Output:Test=FINEST
    6/10/2003 16:00:01 Test <init>
    SEVERE: severe
    6/10/2003 16:00:01 Test <init>
    WARNING: warning
    6/10/2003 16:00:01 Test <init>
    INFO: infoObservations:
    1) Despite my Test class having the FINEST log level, the default ConsoleHandler had log level of INFO, and hence only up to INFO logged.

  • Log messages for 'auditing' are different in 'general'  and'application log

    Hi,
    From UI, When I audit a file using a profile which comprises of user-defined 'rules/categories/analyzers', I will get log messages at ''File-name(Application) log window' and 'Messages' log window, which are located at bottom of Jdev UI page. One common message in both the log windows is
    " <n1> violations, <n2> exceptions, <n3> documents, <n4> seconds>.
    But here the 'n1,n2,...' numbers are dfferent in two windows though the log output is for a same file. In this the 'file-name' log shows the correct
    Example:-
    In 'file-name' log window ,it shows as:
    3 documents, 8 violations, no exceptions
    In messages window, it shows as
    "Audit starting on EFC.jpr (Default)
    Audit completed: no violations, no exceptions, 3 documents, 1 second"
    If I use the 'pre-existed'(Jdev's) rules profile, I will get similar output in both log windows.
    From this I concluded that there is something missing to register for a new 'rule/category/analyzer'.
    Could you suggest me in this case. Do I forgot anything to do in any files of '<rule-implementation.java>', 'audit.properties', <add-in launcher>.java, extension.xml.
    Actually, I want to use 'ojaudit' executable from command line to my project files. Here I observed that the output of the 'ojaudit' is similar to the above explained 'Message' log window in JDeveloper UI. But where the 'Message' log window output is not correct for user-defined rules.
    Regards
    Madhu

    Romano,
    In the upcoming production release (planned to be released next week), we added caching of authorized roles and permissions in JhsAuthorizationProxy class.
    I suggest you wait for this relase, if the problem persists, it is most likely an ADF issue (as is the logging)
    Steven Davelaar,
    JHeadstart team.

  • Log Messages from Transaction Event Logger

    I have 4 instances of MII v12.1 and within a transaction I want to add a message to the log when the transaction runs so I can view it through the message logger. All 4 MII instances were installed by the same consultant a few years ago so there "should" be no differences in the log configs. On 3 of the instances this is working fine - I have created a very simple transaction with one Event Logger action configured with a message "Test Message" and when I execute the transaction I see the correct entry in the log viewer. On the fourth however, although the transaction executes without error I am not seeing anything in the viewer for this event. I am using the standard "last 24 hours" log viewer with no filters and no specific log locations selected, and no customisations. I am seeing other system generated messages. I found some documentation about logging and the viewer and I found the Netweaver log config but as far as I can see it looks consistent between the instance which is working and the one which is not working. Is there some other config which needs to be done to enable Event Logging from transactions? My user has the same access across all instances. Any guidance would be appreciated. I attach a screen shot of what I am expecting to see (taken from one of the instances which is working).

    Hi Partha
    Many thanks for your reply. I have tried this and unfortunately it makes no difference. I also checked on the other instances and found they have their tracing levels all set to error, not Info. I have also noticed that on the instance which is working, in the System Configuration section at the bottom of the Log Config page - for Applications and all sub categories I see the entry .\log\applications_00.log in the Pattern column. On the instance which is not working I see that entry for the Applications root but not for any of the sub categories (even after selecting Copy to subtree). I cannot see where I can set this value (there is no modify function available, even under Administrator login).
    Also, when I look at the log messages which have generated when setting the Event Type to Error on the instance which is not working, it shows one entry and the Category and Location columns show <com.sap.xmii.bls.executables.action.logging.LoggingActions>. When I generate an event with type Error on the instance which is working I get 2 log messages, one with the Category and Location <com.sap.xmii.bls.executables.action.logging.LoggingActions> and the other with Category /Applications/XMII/Xacute/Event and Location <com.sap.xmii.bls.executables.action.logging.LoggingActions>.
    I guess that the .\log\applications_00.log should be showing for all subtree items under Applications and because it is not then the messages are not going into any application log. Not sure how to fix this however.
    I have also reset to the default configuration and it does not change the above.
    Best Rgds
    Richard

  • Message Mapping - java.util.Map

    Hi There
    I would like to know if there is any way, using java.util.Map map; to get the "data type" field name in a UDF? Passing a constant with the field name would not be practical.. I'm looking for a object oriented process to use in all my mappings.
    Also where could I look for the methods I can use in the map trace object?
    Regards,
    Jan

    But I'm still missing the field name..
    Let say I have a message mapping going from Field ACB to Field QAZ and a UDF called CheckLen.
    In my UDF I'm looking at the incoming field and if it's length is correct. if not I'm writing an entry into a table stating there was an incorrect field but what I can't get is the the field name so I can write to the table "Invalid length on field ACB" The only way to get this field name value is by passing a constant of "ACB" to the UDF and using that. But we have hundreds of MMs so implementing this would be much more difficult than a OOP way..

  • Formating Log Messages

    I am trying to format a message in the UCM log using html entities. Something like
    <p>The Tanager Virus Scanner received the following file.
    <ul>
    <li><em>Title:</em>This One For You</li>
    <li><em>Author:</em>Pons B Brit</li>
    <li><em>Original Name:</em>bad.txt</li>
    <li><em>Content Id:</em>999998</li>
    <li><em>Checkout User:</em>Art</li>
    <li><em>Type:</em>WEB_CONTENT</li>
    <li><em>Security Group:</em>public</li>
    <li><em>Revision:</em>3</li>
    <li><em>dID:</em>661</li>
    </ul>
    </p>
    Using intradoc.common.SystemUtils.info I log the above out as a string without the <p> and </p>. The logging method translates all < to &#60; and > to #62; which destroys the formating. Is it possible to format messages or is this a lost cause?
    Thanks, Art

    Content server by default is script. You cannot insert things that wiill remotely resemble script syntax.

  • Customize the "update message" for Java Web Start

    For the default value (false) of silentInstallLicenseAcceptance in Java Web Start when an application's server side has changed, the user will be asked with a message box whether he/she wants to update his local application now or quit the application.
    I would like to know if I can manipulate the message that Java Web Start should ask the user. I also would like to know if I can change the button from Yes/No to Upgrade Now and Upgrade Later.
    Any API reference, idea, tutorial or sample code would be appreciated.

    I'm pretty sure that list is not accurate for the Java Web Start released in Update 4 recently. I have an app which attempts to specify heap and stack sizes using java-vm-args="-Xmx1024m -Xms1024m -Xss8m"; when I use the Java console to display memory usage, it shows that the heap is 81MB (which is the default). If I use initial-heap-size="1024m" max-heap-size="1024m" in the same JNLP file, the heap size is set properly.
    Unfortunately I don't think there's any way other than -Xss to set the stack size in a JNLP file, and I need to do that too.
    It's also possible that I screwed something up which caused this problem, but I reproduced it on both my Mac Pro and my Macbook Pro.

  • Creating toString() for java.util.Stack

    When I create a Stack it prints out
    [0, 1, 2, 3, 4, 10, 20]
    How can I printout only the values.
    I tried using the charAt() and loops, but with no success.
    Please help.

    The toString() method in java.util.Stack comes from the toString() method in Vector, which just calls super.toString(), which goes to AbstractList and then AbstractCollection, and eventually has this code:
        public String toString() {
         StringBuffer buf = new StringBuffer();
         buf.append("[");
            Iterator i = iterator();
            boolean hasNext = i.hasNext();
            while (hasNext) {
                Object o = i.next();
                buf.append(o == this ? "(this Collection)" : String.valueOf(o));
                hasNext = i.hasNext();
                if (hasNext)
                    buf.append(", ");
         buf.append("]");
         return buf.toString();
        }If you want to print stuff out in a different format, just create a new class that extends stack, write a new toString() method that suits your needs, and instead of making a Stack, just instantiate objects using this new class.
    If you give me an idea of how you want this to look rather than what it's printing out now, I'll give it a shot at writing it.

  • Help to create log message for the failure of procedure

    Hi,
    I want to create a log message ,if my stored procedure stops executing or gets hanged due to some reasons.
    Can any one guide me how can i include this log message in some external file so as each time my stored procedure fails a message will be logged in the file that the procedure has failed or hanged.
    pls help
    regds
    debashis

    I'm afraid I don't understand what you're trying to accomplish here. What is "command is successfully executed" intended to represent in your CREATE statement and in the anonymous PL/SQL block.
    What do you mean "it should occur in row by row order" and "success message of execution should be displayed in the log file"?
    Why are you trying to log to an external file rather than a table in the database? When you start talking about "row by row" and "success message", that starts to imply that you're going to be logging a lot of stuff. Logging a lot of data to an external file is going to be a substantial performance burden. Are you sure that is what you want to accomplish?
    Justin

  • Open Document Format - No library for Java???

    Hi guys,
    I'm looking for a library that let's me access Open Document Files, like *.ods.
    There SHOULD BE something like that...
    Does anybody of you know anything?
    Greetz
    Sascha

    On the OpenOffice.org site, look under projects, and there's an Open Document Toolkit for Java. I've no idea of its status though.

Maybe you are looking for

  • My Safari keeps crashing even after clearing cache/history/etc. Help?

    I have tried resetting, clearing cache, and erasing the history. I'm not sure what is going on with my Safari. I did notice I kept getting those "Mackeeper" popups, but I never downloaded it or anything. Could this be the issue? I have looked through

  • Substitution in UWL from SPS12

    Hi, As SAP Mentioned that the User Substitution feature is availanle from SPS12 for KMC. And as per the note of UWL they says for details to refer the End User Guide. But there is no info about how to enable the substitution feature and also no clue

  • How to play video through flickr, cest posible?

    Using Flickr for video screen is great, but can I run videos as well? Using FLICKR? I tried but could not.. Perhaps you know if it is possible and how?

  • Router Problems

    Hi people... I wanted to set up a wireless network off the back of my 10mb Virgin Cable connection, so I bought a Belkin (F6D4230-4) Wireless Router today - Mac compatible obviously. It installed fine. Speaks to the Virgin Cable modem perfectly. I ha

  • FCP serial number recovery.

    I have had a major hardware fault, and have had to buy a new laptop!!! I have recovered my data from Time Machine, but all my serials for FCP don't seem to have transferred, and the ap won't run! Luckily I have access to the old laptops HDD (via and