Logging API configuration trouble

Here is my Java code:
private static final String LOGGER_CONFIG_FILE="java.util.logging.config.file";
private static final String CONFIG_FILE="c:/logging.properties";
public static synchronized void init() {
System.setProperty(LOGGER_CONFIG_FILE, CONFIG_FILE);
try {
LogManager.getLogManager().readConfiguration();
} catch (IOException E) {
System.err.println("Error while reading logging configuration file \""+CONFIG_FILE+"\":"+E);
Here is my logging.properties:
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler
.level=INFO
com.mypackage.level=ALL
java.util.logging.ConsoleHandler.level = WARNING
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.level = ALL
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.FileHandler.pattern=c:/java%u.log
java.util.logging.FileHandler.limit=50000
java.util.logging.FileHandler.count=1
Now here is my trouble:
when I'm running init() method all is ok !
when I'm trying to do something like this MyClass.getLogger().severe(msg); then there is an error message in my console:
Can't set level for java.util.logging.ConsoleHandler
Can't set level for java.util.logging.FileHandler
But the fact is, that my servere message is actually displayed in console and in my java0.log file :(
And the second trouble: all FileHanler's output is in XMLFormatter, but in config file there is SimpleFormatter set.
What are the problems, guys, please help !
Thanks

Help somebody, pleaseeee !

Similar Messages

  • How come logging is so hard? - JDK1.4 Logging API

    Have a small project on hand. A standalone java program trigged by unix cron job and do some data cleaning. Need to implement a very simple logger. Tried to use JDK1.4 Logging API, here's my code:
    public class MyLogManager {
         public final static String NAME = "mylog";
         public final static String LOG_FILE_NAME = "C:/my.log";
         private static Logger logger;
         static {
              try {
                   logger = Logger.getLogger(NAME);
                   Handler fh = new FileHandler(LOG_FILE_NAME);
                   fh.setFormatter(new SimpleFormatter());
                   logger.addHandler(fh);
                   logger.setLevel(Level.ALL);
              } catch (Exception e) {
                   System.out.println("Unable to initialize logger: " + e.toString());
                   System.exit(1);
         public static Logger getLogger() {
              return logger;
    and use MyLogManager.getLogger().info("message") to log message.
    It works and my.log was generated with log message. However, the problem is everytime a new job (java myprogam ...) runs, it deletes the old log file and create a new one.
    I want the message to be appended by the end of old log file. What should I do? Any help?

    Use log4j (google for it - it's on http://jakarta.apache.org).
    If log4j.jar is in your classpath, the JDK 1.4 logging framework will use it automatically. Then all you have to do is to configure a log4j.properties file in your classpath to log wherever you want it to.
    And log4j is sorta-smart about multiple programs logging to the same file.

  • WLS logging api

    Hi All,
    My app is running on WLS 8.1. I am using WLS logging api to log the messages and
    I also email those messages. I would like to configure the logging so that I can
    send a particular message once every x time interval.
    e.g. If the same error message is thrown multiple times in an hour, currently
    the app will send those many emails. I want to change it so that even though the
    same error message is thrown multiple times in an hour, the app will send only
    one email.
    Is there a way to do this using WLS api?
    Thanks,
    WD

    I did not set up the email messages within WLS 8.1. I have written my own emailer
    class that I use.
    "Sean C. Sullivan" <nospam@spamfree> wrote:
    >
    How did you setup error email messages with BEA Weblogic Server 8.1?
    Can this be setup from the Admin console?
    WD wrote:
    Hi All,
    My app is running on WLS 8.1. I am using WLS logging api to log themessages and
    I also email those messages. I would like to configure the loggingso that I can
    send a particular message once every x time interval.
    e.g. If the same error message is thrown multiple times in an hour,currently
    the app will send those many emails. I want to change it so that eventhough the
    same error message is thrown multiple times in an hour, the app willsend only
    one email.
    Is there a way to do this using WLS api?

  • Not able to create log files using logging API's

    Hi All,
    I am trying to make use of logging API's of SAP in my standalone java project.
    Below is the following line of code.
    public class TestLog {
    private static final com.sap.tc.logging.Location logger = com.sap.tc.logging.Location.getLocation(testLog.class);
    static
    logger.setEffectiveSeverity(Severity.INFO);
    // logger.addLog(new ConsoleLog());
    logger.addLog(new FileLog("C://temp//testOutput.log", new ListFormatter()));
    public static void main(String[] args) {
    writeLog();
    public static void writeLog()
    logger.entering("entering");
    logger.debugT("In Write Log");
    logger.exiting("exiting");
    But the above codes does not create the testOutput.log file in the dir which i have mentioned . I have added sap.comtcloggingjavaimpl.jar from eclipse plugin folder to make use of these API's .
    Could you please help me on this .
    Thanks & Regards,
    Mitul Adhia.

    Hi,
    Also try adjusting the severity level in nwa(Netweaver Administrator).
    1. Go to http://<host-name>:<port-number>/nwa
    2. Select Problem Management from tabs.
    3. In that select Logs and Traces tab.
    4. Select Log configuration
    5. in Show select Tracing Locations
    6. Select your application and set the severity to be the one lower than that you specify in your code.
    Hope it helps.
    Regards,
    Srinivasan Subbiah

  • Log API: daily roling file appender?

    my task is to replace Log4J with the JDK 1.4 logging API. how can i configure the logging to have a FileHandler that does daily rolling (like Log4J DailyRollingFileAppender) and offer a a date pattern for the file name (like Log4J DatePattern)?
    the result should be that each day, a new log file is created with the old files having a datepattern in the file names.

    Well, i wrote my own now, that supports time rolling (day, week, month, year) and later additional rollings. here's a start:
    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.*;
    import java.util.logging.*;
    * File handler that supports different kind of rolling than java.util.logging.FileHandler.
    * Supported rolling methods are: by date (day).
    * <p>
    * Example of entries in the logging file (system property "java.util.logging.config.file"):
    * <p>
    <table align="center" bgcolor="#ddddff" border=1 cellpadding="10" cellspacing="0"><tr><td><pre>
    logging.RollingFileHandler.level = FINEST
    logging.RollingFileHandler.prefix = MyApp_
    logging.RollingFileHandler.dateFormat = yyyyMMdd
    logging.RollingFileHandler.suffix = .log
    logging.RollingFileHanlder.cycle=day
    logging.RollingFileHandler.formatter = java.util.logging.SimpleFormatter
    </pre></td></tr></table>
    <p>
    * @version $Revision:$ ($Date:$)
    * @author $Author:$
    public class RollingFileHandler extends StreamHandler {
        /** File prefix. */
        private static String prefix = null;
        /** Date format to use in file name. */
        private static String dateFormat = "yyyy-MM-dd"; //default
        /** File suffix. */
        private static String suffix = null;
        /** Time in milliseconds for the next cycle */
        private static long nextCycle = 0;
        /** Time cycle (for file roling) */
        private static String cycle = "day"; //default
         * Constructor.
        public RollingFileHandler() {
            super();
            LogManager manager = LogManager.getLogManager();
            String className = RollingFileHandler.class.getName();
            prefix = manager.getProperty(className + ".prefix");
            String dfs = manager.getProperty(className + ".dateFormat");
            suffix = manager.getProperty(className + ".suffix");
            String c = manager.getProperty(className + ".cycle");
            String formatter = manager.getProperty(className + ".formatter");
            if (dfs != null) {
                dateFormat = dfs;
            if (c != null) {
                if (c.equalsIgnoreCase("day") || c.equalsIgnoreCase("week") || c.equalsIgnoreCase("month") || c.equalsIgnoreCase("year")) {
                    cycle = c;
            if (formatter != null) {
                try {
                    setFormatter((Formatter) Class.forName(formatter).newInstance());
                } catch (Exception e) {
                    e.printStackTrace(System.err);
            openFile();
        }//RollingFileHandler()
          * Open existing or create new log file.
         private synchronized void openFile() {
            //create file name:
            String dateString = dateFormat; //default (to note error in file name)
            Date currentDate= new Date();
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.getDefault());
                dateString = sdf.format(currentDate);
            } catch (IllegalArgumentException iae) {
                /* ignore wrong date format */
            //compute next cycle:
            Date nextDate = null;
            GregorianCalendar gc = new GregorianCalendar();
            gc.setTime(currentDate);
            if (cycle.equalsIgnoreCase("week")) {
                gc.add(Calendar.WEEK_OF_YEAR, 1);
                nextDate = gc.getTime();
            } else if (cycle.equalsIgnoreCase("month")) {
                gc.add(Calendar.MONTH, 1);
                int month = gc.get(Calendar.MONTH);
                int year = gc.get(Calendar.YEAR);
                GregorianCalendar gc2 = new GregorianCalendar(year, month, 1);
                nextDate = gc2.getTime();
            } else if (cycle.equalsIgnoreCase("year")) {
                gc.add(Calendar.YEAR, 1);
                int year = gc.get(Calendar.YEAR);
                GregorianCalendar gc2 = new GregorianCalendar(year, 0, 1);
                nextDate = gc2.getTime();
            } else { //day by default
                gc.add(Calendar.DAY_OF_MONTH, 1);
                nextDate = gc.getTime();
            //to zero time:
            gc = new GregorianCalendar();
            gc.setTime(nextDate);
            gc.set(Calendar.HOUR, 0);
            gc.set(Calendar.HOUR_OF_DAY, 0);
            gc.set(Calendar.MINUTE, 0);
            gc.set(Calendar.SECOND, 0);
            gc.set(Calendar.MILLISECOND, 0);
            nextDate = gc.getTime();
            nextCycle = nextDate.getTime();
            //create new file:
            String fileName = prefix + dateString + suffix;
            File file = new File(fileName);
            //create file:
            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException ioe) {
                    ioe.printStackTrace(System.err);
            //set log file as OutputStream:
            try {
                FileOutputStream fos = new FileOutputStream(file, true);
                setOutputStream(fos);
            } catch (FileNotFoundException fnfe) {
                reportError(null, fnfe, ErrorManager.OPEN_FAILURE);
                fnfe.printStackTrace(System.err);
                setOutputStream(System.out); //fallback stream
        }//openFile()
         * Overwrites super.
        public synchronized void publish(LogRecord record) {
            if (!isLoggable(record)) {
                return;
            super.publish(record);
            flush();
            //check if we need to rotate
            if (System.currentTimeMillis() >= nextCycle) { //next cycle?
                role();
        }//publish()
          * Role file. Close current file and possibly create new file.
         final private synchronized void role() {
            Level oldLevel = getLevel();
            setLevel(Level.OFF);
            super.close();
            openFile();
            setLevel(oldLevel);
        }//rotate()
    }//RollingFileHandler

  • Log API

    Hello,
    I'm new to the log API. I do a test (see below) but no trace are printed.
    public class ATest {
        private static Logger logger = Logger.getLogger(ATest.class.toString());
        public ATest() {
            logger.fine("Prints a trace");
        public static void main(String[] args) throws IOException {
              Handler fh = new FileHandler("pp.log");
              Handler ch = new ConsoleHandler() ;
              Handler sh = new StreamHandler(
                   System.out,
                   new SimpleFormatter()) ;
              Logger.getLogger("").addHandler(fh);
              Logger.getLogger("").addHandler(ch);
              Logger.getLogger("").addHandler(sh);
              Logger.getLogger("").setLevel(Level.ALL) ;
              new ATest() ;
    }Can someone help me ?
    Thx

    Can someone help me ?Perhaps.
    Here
    private static Logger logger =
    er = Logger.getLogger(ATest.class.toString());You get a named logger for the class (assuming you changed this to use the class name, as the earlier post mentioned)
    Here:
    public static void main(String[] args) throws
    rows IOException {
         Handler fh = new FileHandler("pp.log");
         Handler ch = new ConsoleHandler() ;
         Handler sh = new StreamHandler(
              System.out,
              new SimpleFormatter()) ;
         Logger.getLogger("").addHandler(fh);
         Logger.getLogger("").addHandler(ch);
         Logger.getLogger("").addHandler(sh);
         Logger.getLogger("").setLevel(Level.ALL) ;
         new ATest() ;
    }you are getting a logger for "" and adding handlers and such for it. You then try to make a call to the FINE level with your original (and different) logger which is probably using the default config. This default config specifies INFO level in general, and INFO specifically for ConsoleHandler,
    The first thing to do to actually get output is to change your level from FINE to INFO or better. The second thing is to read this:
    See http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html#2.1
    You can control all of this logging from a configuration file which is a better way to go -- then you don't have to recompile to change logging settings.
    - N

  • [svn:osmf:] 14976: Clean up and expose logging API.

    Revision: 14976
    Revision: 14976
    Author:   [email protected]
    Date:     2010-03-23 17:21:14 -0700 (Tue, 23 Mar 2010)
    Log Message:
    Clean up and expose logging API.
    Modified Paths:
        osmf/trunk/apps/samples/framework/SampleLoggers/org/osmf/logging/flex/FlexLogWrapper.as
        osmf/trunk/apps/samples/framework/SampleLoggers/org/osmf/logging/flex/FlexLoggerWrapper.a s
        osmf/trunk/framework/OSMF/org/osmf/logging/ILogger.as
        osmf/trunk/framework/OSMF/org/osmf/logging/ILoggerFactory.as
        osmf/trunk/framework/OSMF/org/osmf/logging/Log.as
        osmf/trunk/framework/OSMF/org/osmf/logging/TraceLogger.as
        osmf/trunk/framework/OSMF/org/osmf/logging/TraceLoggerFactory.as

    a) You can use
    handler = new FileHandler(Constant.LOGFILE, true);
    Check the Javadoc please...
    b) you can configure the property "java.util.logging.FileHandler.append" to "true" (again, check the javadoc of java.util.logging.FileHandler)

  • Apache Sling Logging Writer Configuration

    Hi,
    I'm having an issue where my custom log writer configuration is not being picked up and used by CQ5 sometimes.  I've created a custom error log writer based on the example provided at http://helpx.adobe.com/cq/kb/HowToRotateRequestAndAccessLog.html which I've installed on an author, replicated it to the publishers, and all seemed ok and working correctly.  The settings are:
    Log File: ../logs/error.log
    Number of Log Files: 5
    Log File Threshold: 200MB
    After installing this, the error logs rotated at 200MB resulting in error.log.0, error.log.1 etc as expected.
    However after rebuilds on the machines, this configuration was overwritten (as expected).  So I've installed and replicated the package again, but now the configuration is not taking effect.  I'm using the exact same config package as I was previously, but the logs don't seem to be rotating at all now (not even daily).  I've deleted the config from the Felix console on all authors and publishers, reinstalled on the authors, replicated to the publishers, then restarted the CQ5 service on all machines, but it's still not working.
    So I have a couple of questions about this:
    Is there somewhere else in CQ5 that might be overriding these log writer config settings?
    Is ../logs/error.log correct for the standard log file location?  A note in step 3 of Creating Your Own Loggers and Writers on http://dev.day.com/docs/en/cq/current/deploying/configure_logging.html states:
    Log writer paths are relative to the crx-quickstart/launchpad location.
    Therefore, a log file specified as logs/thelog.log writes to crx-quickstart/launchpad/logs/thelog.log.
    To write to the folder crx-quickstart/logs the path must be prefixed with ../ (as../logs/thelog.log).
    So a log file specified as ../logs/thelog.log writes to crx-quickstart/logs/thelog.log.
         The configs in the log rotation example also use ../logs.  However when looking at the default/standard logging writer config, it uses logs/error.log.  Which one is correct?
    Any help on what's going on here would be appreciated!!
    Thanks,
    K

    Hi,
    I am answering your last question and this one here only.
    1. Log configuration can be override at project via creating config and overriding factory "org.apache.sling.commons.log.LogManager.factory.config-<identifier>" and writer (if required) "org.apache.sling.commons.log.LogManager.factory.writer-<identifier>". So plz check if you have configure log at project level. Now if you are not able to see then plz recheck you log configuration in felix console http://localhost:4502/system/console/slinglog here you can see entire log configuration for CQ system.
    2. both will work but the location will change
         i. CQ 5.5 - log file located under "crx-quickstart" ../logs/<filename>.log will create under this
         ii. CQ 5.4 - logs creates under "crx-quickstart\logs" also under "crx-quickstart\launchpad\logs" so if you select ../logs/ it will go under "crx-quickstart\logs" only but you can change wherever you want to store. Again you can see this configuration info at http://localhost:4502/system/console/slinglog
    3. You can also customize you log via creating at project level and assigning the "identifire" (with all other configure parameters) for more information you can refer http://sling.apache.org/site/logging.html apart from earlier share links.
    I hope above will help you to proceed. Please let me know for more information.
    Thanks,
    Pawan

  • Logging CRS configuration changes

    Hallo,
    in a 10.1 RAC environment,
    is there a file which logs CRS configuration changes, like issuing a oifcfg -setif command?
    Thx

    Yes

  • Logging api hangs

    Im starting a java application from an applet calling Runtime.getRuntime().exec("java bla bla bla")
    Worked fine until I implemented Java 1.4 logging api. Now the application hangs after writing a few info lines to a FileHandler log. It's clearly the logger that hangs because if I set log level = OFF the the program runs just fine.
    Has anyone seen anything similar?
    * To make it harder to debug, the problem only occurs when starting the application from an applet.

    That might happen that spawn process generates lots of output.
    Runtime.getRuntime().exec() returns object of type java.lange.Process. That object provide access to the stdout and stderror of the newly created process. If those streams are not cleaned properly then process will hang as soon as OS buffers of those stdout and stderr streams get full.
    One way to work around it just read output from the process and throw it away. You can try using something like this:
    package com.xxx;
    import java.io.InputStream;
    public class ProcessOutputWaster {
        public ProcessOutputWaster(Process process)
            throws Exception {
            createWorker(process.getErrorStream()).start();
            createWorker(process.getInputStream()).start();
        protected Worker createWorker(InputStream is) {
            return new Worker(is);
        protected static class Worker
                  extends Thread {
            private InputStream inputStream_;
            public Worker(InputStream inputStream) {
                inputStream_ = inputStream;
            public void run() {
                if (getInputStream() != null) {
                    try {
                        byte[] buffer = new byte[1024];
                        int read;
                        while(true) {
                            read = inputStream_.read(buffer);
                            if (read < 0)
                               break;
                    catch(Exception ex) {
                        Handle the error some how. E.g. show the error box.
    Process process = Runtime.getRuntime().exec(strCommand);
    ProcessOutputWaster outputWaster = new ProcessOutputWaster(process);

  • Practical use of Java Logging API

    There was a recent technical tip about the Java Logging API, but after reading it I still don't understand how to use it in a real situation.
    Can anyone help me with this with a practical example?
    At the moment I have try-catch clauses that catch exceptions and print a message in a System.err log that I can consult if there's a specific problem.
    How should I be using the Logging API? I feel sure that it can help me, but can't see how.
    Thanks for any practical information.

    What if you don't want to write to system.err anymore? What if you need to write something to the windows event log? What if system.err is irrelevant (nt service), ...
    Btw, lots of examples on the JDK1.4 logging api:
    http://www.esus.com/docs/GetIndexPage.jsp?uid=265

  • How to set NC Log API

    Hi all,
    I want to use the following NC log API,but I don't know how to initialize the interface's java object and set the parameter "ApplicationVO".
    Interface LogNCApplicationInterface
    Method ApplicationVO addNDone(ApplicationVO applicationvo)
    Please help me.Thank you!
    Qiang Liu

    if you just need to log an NC the minimum fields you need to set are the following:
    CreateNCRequest ncRequest = new CreateNCRequest();
    ncRequest.setActivity("NC500"); // activity where NC is logged - can be any name
    ncRequest.setSfcRef(new SFCBOHandle(site, sfcParent).toString());// the SFC for which you are reporting an NC
    // ncRequest.setValidateNCCodeOperation(true); // no need to set it, it's true by default
    // nc code reference for nc code that is reported
    // nc code must exist in the system
    ncRequest.setNcCodeRef(new NCCodeBOHandle(site,"NCCODE").toString());
    // required custom fields must be set
    CreateNCResponse ncResponse = ncPSI.createNC(ncRequest);

  • Setting Logging API config file

    Hi,
    Is there a way I can set the Logging API's config file (java.util.logging.config.file) from within my program? I have tried using System.setProperty but it doesn't seem to work. The only way I seem to be able to set the property is with -D on the command line.
    Thanks
    Rob

    Is there a way I can set the Logging API's config file (java.util.logging.config.file) from within my program? I have tried using System.setProperty but it doesn't seem to work. The only way I seem to be able to set the property is with -D on the command line.Read the Logging Overview Dokumentation
    anyway
    InputStream inputStream = new FileInputStream("logging.properties");
    LogManager.getLogManager().readConfiguration(inputStream);
    ...

  • Logging API AdapterFramework 3.0

    Hello,
    i still wonder why it was necessary to provide an own API for Logging and Tracing inside the Adapter Framework.
    The Web AS Logging API does the same.
    Developing an JCA Adapter that can be used inside the XI Adapter Framework and as a Basic JCA 1.0 Adapter in the Web AS, theres's need to provide support for both APIs.
    Has anyone an idea to solve this problem?

    There is a lot of logging to the console with 2.3.0 RC1 when I am doing
    any trips to the datastore, is it possible to switch this off? I am
    using Kodo.rar in Jboss 3.0.0Remove the 'com.solarmetric.kodo.Logger' property from your properties file. You can also remove it from the Properties instance you use to construct the PersistenceManagerFactory. If you'd like to log to a file instead, change the property to the name of a file to log to.

  • Forum help for Logging api

    I need help with logging api. Which developer forum do I have to use for the same. Thanks.

    Have you got the SAP Wrapper for logging API? if you got, can you give it to me:)

Maybe you are looking for

  • Mac LION forced restart

    Hi I just installed Mac OS X Lion and have had it working no problem until I did an update today and now I keep getting a dark transparent grey screen popping up saying YOU NEED TO RESTART YOUR COMPUTER. HOLD DOWN THE POWER BUTTON UNTIL IT TURNS OFF,

  • How do I create a Dynamic PDF in ColdFusion

    I am using ColdFusion CS4 and I need to create a dynamic PDF certificate for the user when they finish a short test. Their name is in a session var and should dynamically enter in to the Name field of the certificate as well as the date. The user can

  • Vender quotation statement

    Hello Every Body,             Kindly help me friends.I need help in ALV Report which displays vender quotation statement. Kindly plz give me reply as early as possible

  • Edits to an image in photoshop do not transfer/save back to iPhoto

    I am used to editing images from iPhoto in my Photoshop software. Once saved, the edits used to automatically appear in iPhoto, but recently, the updated/edited images do not appear in iPhoto unless they are selected and enlarged (using the space bar

  • How do I export or save Bookmarks from Firefox

    I have created a few Bookmark folders with Firefox. Each folder of course containers several individual bookmarks. How to I save this few Bookmark folder into a file, and then transfer it to Chrome, Internet Explorer, Opera or other browsers. Regards