Questions on logging in JDK 1.4

Hi,
This is my second try at getting some help on these questions. I thought I would try posting into the advanced language topics forum since I didn't get any response in the Java topics forum. I could really use some help on these two questions...
I'm using the following code to test the new logging faciliites of
SDK 1.4. I have two questions I would like to resolve.
1) Why is this coming out in XML format, and how to I change it so
it comes out in text format.
2) How can I format the log to format a single log record into a
single line, with the following fields (I want to make the log
sortable by time and date).
"date" "time" "class" "method" "thread" "message"
and will look something like this
2002-03-20 13:21:09 <SimpleLogExample:main:10> log message #4
2002-03-20 13:21:09 <SimpleLogExample:main:10> log message #5
2002-03-20 13:21:09 <SimpleLogExample:main:10> log message #6
HERE IS THE ACTUAL (PARTIAL) OUTPUT FROM THE PROGRAM
<?xml version="1.0" encoding="windows-1252" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2002-03-20T13:21:09</date>
<millis>1016652069894</millis>
<sequence>449148</sequence>
<logger>main</logger>
<level>CONFIG</level>
<class>SimpleLogExample</class>
<method>main</method>
<thread>10</thread>
<message>log message #4</message>
</record>
</log>
HERE IS THE PROGRAM
import java.util.logging.*;
import java.io.*;
public class SimpleLogExample {
public static void main(String argv[]) throws IOException {
Logger logger = Logger.getLogger("main");
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
FileHandler fh = new FileHandler("%t/logfiles/Main.%g.log", 10485760, 3);
fh.setLevel(Level.ALL);
logger.addHandler(fh);
for (int i=0; i<100000; i++) {
logger.severe("log message #1");
logger.warning("log message #2");
logger.info("log message #3");
logger.config("log message #4");
logger.fine("log message #5");
Thank you,
Joel

Here's a class I wrote to output one line per log record:
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Synchronous Designs</p>
* @author Andrew Malcolm
* @version 1.0
import java.util.Date;
import java.util.logging.*;
import java.text.NumberFormat;
class OneLinePerRecordFormatter extends SimpleFormatter
private long m_startTime=System.currentTimeMillis();
private NumberFormat m_numberFormat=NumberFormat.getInstance();
/** constructor */
public OneLinePerRecordFormatter()
m_numberFormat.setMinimumIntegerDigits(8);
m_numberFormat.setGroupingUsed(false);
/** format */
public String format(LogRecord logRecord)
StringBuffer stringBuffer=new StringBuffer();
stringBuffer.append("TIME ");
stringBuffer.append(m_numberFormat.format(logRecord.getMillis()-m_startTime));
stringBuffer.append(" DATE ");
stringBuffer.append(new Date());
stringBuffer.append(" THREAD UID ");
stringBuffer.append(m_numberFormat.format(logRecord.getThreadID()));
stringBuffer.append(" MESSAGE ");
stringBuffer.append(logRecord.getMessage());
if (logRecord.getSourceClassName()!=null)
stringBuffer.append(" CLASS ");
stringBuffer.append(logRecord.getSourceClassName());
else
stringBuffer.append(logRecord.getLoggerName());
if (logRecord.getSourceMethodName()!=null)
stringBuffer.append(" METHOD ");
stringBuffer.append(logRecord.getSourceMethodName());
if(logRecord.getThrown()!=null)
stringBuffer.append(" EXCEPTION ");
stringBuffer.append(logRecord.getThrown().getMessage());
stringBuffer.append(" ");
for(int line=0;line<logRecord.getThrown().getStackTrace().length;line++)
stringBuffer.append(logRecord.getThrown().getStackTrace()[line]);
stringBuffer.append(" ");
stringBuffer.append("\r\n");
return stringBuffer.toString();
here's the test code:
private static Logger m_logger=Logger.global;
private static FileHandler m_fileHandler;
public static void main(String[] args)
try
m_fileHandler=new FileHandler("log.txt",true);
m_fileHandler.setFormatter(new OneLinePerRecordFormatter());
m_logger.addHandler(m_fileHandler);
catch(Exception e)
&etc

Similar Messages

  • I typed a question before logging on.  What happened to it?????????

    I typed a question before logging on.  What happened to it?????????

    Q - "Flash plugin" vs. "player"?
    When I unistalled Flash Player using the control panel insted of Adobe uninstall, I unistalled 2 icons, one was Flash Player pluin, and I believe the other was labeled Flash Player.  Unfortunately, i did not do a screen shot first.
    Q - What exactly means "doesn't work"; what do you see instead of the expected Flash content?
    When I go to Adobe Flash help, http://helpx.adobe.com/flash-player.html
    I get the following, where is doesn't display what version I have, or even an error message, but nothing:
    Thanks for your help.

  • Newbie question on logging in to Apex 4 / Oracle 11gR1 after installation

    I've been unable to log in to Apex after successfully completing the installation of the database and Apex.
    I tried using the function to send a list of workspaces to my email account and received nothing.
    I then tried using the 'Internal' workspace along with my email address and what I thought was my pw. That did not work either and I did not receive any error messages.
    Resetting my pw and attempting to use the Administration function to manually create a new workspace likewise failed without any error messages.
    Is there a magic bullet that I'm missing? Can someone be kind and point me to the most likely manual to consult for these issues?
    Thanks in advance for any help that might be offered.
    Ron

    Thank you for the timely reply to my question.
    I have not set up a mail server because I have yet been able to access the Administration Functions menu.
    Before I go on, I'm attempting to access Apex v 4. using :
    http://cwtk7b1:8080/apex/f?p=4550:1:3141657078302382 where cwtk7b1 is a recently virtualized server.
    I tried to change the admin pw using the script and it errored out. I noticed that the script was setting the schema to apex_030200 and I don't see that user listed when I go into Oracle 11g. I changed that value to apex_040000 (which is listed) and the script ran to completion. Is it possible that I have multiple versions of Apex that might be causing my heartache?
    Speaking of Oracle 11g. When I attempt to run it I get a warning message :
    There is a problem with the security certificate with this website. I was allowed to proceed to Oracle 11g with a warning. I'm thinking that we might have some security issues. I'm not the network administrator.
    Also, when Apex requests my credentials, most of the options available on that screen (reset pw, locate workspace, admin, etc) have a sequare that contains a small circle with an '\' through it.
    Now, having successfully changed my admin pw for user apex_040000, when I try to go to Apex administration from the initial Apex menu, it just hangs there without an error message.
    When I tried accessing Administration using
    http:.../.../.../apex_admin the same thing as above happens.
    When I tried accessing Administration using
    http:.../.../pls/apex/apex_admin I got a screen
    The server cwtk7b1 @ xdb requires a username and pw
    *** Warning, this server is requesting that your user and pw be
    sent in an insecure fashion.
    And the last little tidbit of info, we just embarked on a virtualization project and our environment is pretty outdated version wise. (I don't control the environment nor do I have a say in what versions of this or that to upgrade to.). I'm just charged with getting Apex 4 to run using Oracle 11g.
    Thanks again for any help you can offer even if it's just pointing me in a particular direction.
    Ron

  • Question on logging in SAP Netweaver Servlet

    Hi,
    I am on SAP Netweaver 7, and have written a servlet to be deployed on the app server. I have written the servlet using the Dev Studio.
    My question is regarding logging messages from the server.
    I can log messages to the browser using PrintWriter class, and can log messages to another file using other logging framework. Not an issue.
    However, I want to know, when I write
    System.out.println("mesg");
      in the servlet, where does this get logged?
    For instance, when I do this on a tomcat servlet, it gets logged to catalina.out. What happens in the case of SAP Netweaver app server?

    Hi,
    It goes to the default traces. However you have to change the severity of location System.out to ALL. You can do this via Visual Admin or NWA. No restart is needed in order to have the changes applied.
    Best regards,
    Vesselin

  • 10gr2 standard edition standby question - archive log shipping

    Hello,
    I have 2 servers with 10gr2 standard edition, one is production(primary) and secondary is standby on windows platform. To keep standby synchronized i use a script to copy archived logs from primary to standby and applying manually (with scripts).
    My question is: can i use redo transport service in order to copy archivelogs from primary to standby ?
    Thank you in advance.

    Hi,
    It is a bit of topic.
    According to the Licensing Document page 10 DataGuard is not supported for standard edition.
    http://download.oracle.com/docs/cd/B28359_01/license.111/b28287.pdfRegards,
    Tycho

  • Urgent - Question about logging and debugging.

    Hi,
    I have a question about the logging and debugging supported by
    Weblogic 6.0. From what I understood by reading the documentation
    it has classes e.g. NotCatalogLogger class for logging the information.
    The class has one method callded
    debug() for writing the debugging information. I want to log the
    debug messages only in some situation. Can I control this using
    some property? Because the documentation says that the debug information
    is logged only if application is running in debug mode. Now how
    do I change the mode of an application??
    Thanks and Reagrds,
    Manoj

    Hi,
    I have a question about the logging and debugging supported by
    Weblogic 6.0. From what I understood by reading the documentation
    it has classes e.g. NotCatalogLogger class for logging the information.
    The class has one method callded
    debug() for writing the debugging information. I want to log the
    debug messages only in some situation. Can I control this using
    some property? Because the documentation says that the debug information
    is logged only if application is running in debug mode. Now how
    do I change the mode of an application??
    Thanks and Reagrds,
    Manoj

  • Feature Question - Audit Logging

    Hello forum. Sorry if this is the wrong thread for this topic, but I was wondering if audit logging is a Standard Edition feature or if it's Enterprise only.
    I can't find anything specifically saying that it is or isn't, and it's not enabled on my database so other than trying to enabling it and getting an error message (or not) I can't find an answer.
    Sorry if this is a noob question, but I couldn't find anything about whether RMAN backup encryption was a Standard or Enterprise feature either, and it bit me in the ass when I found out it was Enterprise only.
    Thanks in advance...

    My apologies if you think I wasn't thorough enough in my own research before asking the question. I did do my own research using oracle's docs and google, and my final resource was the 10g Oracle Database Security Guide, which mentioned nothing about which versions supported which features.
    I did post my original question yesterday morning and received no response. As you said, this is a volunteer forum, and I'm grateful for the assistance, but as sad as you think it is that I asked for an answer within a time frame, I was left with no choice. The question was posed to me yesterday morning and I needed to return an answer this afternoon.
    In any event, thank you for the information.

  • A dumb question about logging

    Hi all,
    i ran into some problems using the pregenerated static Location "logger" instance of an arbitrary WD controller for logging.
    So far i used this logger in conjunction with a superior Category instance only, e.g. the logging (and tracing, if minimum severity is configurated at a proper level) output was related to a category like "/Application/MaterialManagement" or whatever.
    Now i tried to use the logger without a category after a long time again, but i didn't succeed to generate any output!?!
    So my question is: What do i have to do (configurate) to produce some output from this Location? I remember, that in earlier versions there has been a (file-based) WDRx.log, which kept all WD-related output of the configurated severity level. Do i have to reactivate this somehow?
    Thanks in advance.
    Regards
    Stefan

    Hmmm,
    i found it by myself. I looked into the wrong trace (dispatcher's default trace instead of server's default trace, aehem).
    For all of you who want to know where the logging output goes by default:
    If you use the
      private static final com.sap.tc.logging.Location logger =
        com.sap.tc.logging.Location.getLocation(Your.class);
    generated by the WD generation framework for example like
      public void wdDoInit()
        final String _methodName = "wdDoInit()";
        try {
          logger.entering(_methodName);
          logger.infoT("Time to do something useful.");
        } finally {
          logger.exiting();
    the complete output of the logger will be output to the trace which is displayable in the "Log Viewer" service of the Visual Admin at "Cluster (xx)->Server xx->.\log->10:defaultTrace.trc"
    Since there's an identical entry under the "Dispatcher xx" node (should have number 32), take care not to view the wrong one
    Regards
    Stefan

  • A question about version of  JDK

    hello!
    My cpu is Turion x64 TL-50,but I use WinXp sp2 (32bit-version)
    then which jdk shall i download?windows-i586 or windows amd-64?
    jdk's version depends on os only?

    yep, 32 bit software normally run on 64 bit cpu (not XP 64 bit, the environment) unless ur using win 64.

  • I just filled out a question before logging in. Did you get it?

    Did you get my last question? Problem with installing update to Flash???
    Fred
    [email address removed]

    No, this is your first post.  But you need to provide more info: http://forums.adobe.com/thread/1195540
    P.S. this is a public forum; please do not post your email address!

  • NOOB question.  Log and capture vs transfer?

    What is the difference between log and capture vs log and transfer? I have files on the hard drive of my video camera that I just want to import and store on my computer. Which one would be best for this, and what are they both primarily used for? Thanks! Cheers!

    Also, does Final Cut typically not recognize a camera through a USB connection? Does it have to be a firewire? I have a USB out, A/V R, and HDMI out ports on my sony handycam, but all I have is the USB cable for now. Thanks for any additional help.

  • Question about logging

    Hi guys! How the log() method from ExternalContext works and how can i use log4j to log messages in my application??

    hi;
    Please take a look to log4j usage in the folloing link.
    http://logging.apache.org/log4j/docs/manual.html
    I use log4j for a long time, I suggest that initialize log4j using a servlet
    http://asahin.net

  • 2 questions call log n media card

    I hav a 8300 curve and new to it I tried a lot but didn't find a way to open my downloaded zip file. Infact I don't know how can I view it ihave stored it on my media card. Also I can't check my call history folder how can I acess the same. Need help urgently Regards Afzal

    Hi and welcome to the forums!
    You cannot unzip files on the curve unless you use a utility like ziplorer.
    Call logs can be accessed by pressing the call log icon. I have attached a screen
    shot.
    Thanks,
    Bifocals
    Please remember to resolve your thread.
    Put the check mark in the green box that contained your answer! Thanks   
    http://www.blackberryinsight.com/2008/04/12/howto-zip-and-unzip-files-on-your-blackberry/
    Icon
    Message Edited by Bifocals on 01-04-2009 07:22 AM
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

  • Basic question on log and temp files

    Hi,
    I need to create a new database in this way:
    - 2 GB for the data file
    - 1 GB for log and temp files
    This is the command I'm issuing to create the db:
    create tablespace xyz datafile '<path>\xyz.dbf' size 2000M reuse;
    How can I say the size of log and temp files?
    Thank you
    Nicola
    Ps-I'm on windows platform

    user575754 wrote:
    - 1 GB for log and temp filesWhat's the link between log file size and tempfile ?
    This is the command I'm issuing to create the db:
    create tablespace xyz datafile '<path>\xyz.dbf' size 2000M reuse;This command does not actually create a database, but a tablespace. If you ran it, that means your db aleady exists.
    So, not sure to follow you on this thread.
    Nicolas.

  • Question on logging to file

    I am doing java logging to file using the logger class. In order to write logs to the file, a file handler was created using the 'append' mode.
    However, when the
    log entries are written to the log file, they are all entered on a single line.
    How do I make each new log entry start on a new line?
    boolean append = true;
    FileHandler filehandler = new FileHandler(errorFile,append);
    Logger logger = Logger.getLogger("Logging");
    logger.addHandler(filehandler);
    logger.log(Level.INFO,"Unable to zip file:");

    1)Do you view the file in Microsoft Windows?
    If you are using MS Windows, please open the log file with wordpad.
    If you still find all your result are on a single line in wordpad.
    2)You can try this
    String nl = System.getProperty ( "line.separator" );
    logger.log(Level.INFO,"Unable to zip file:"+nl);

Maybe you are looking for

  • Barcode input to excel and read data

    Hello, I am creating a program where I would scan a barcode into LV and from there LV scans an excel spreadsheet for that barcode and returns the data from that row. I found an example online that helps with the barcode number find in excel but I am

  • Playstation 3 to iMac

    hello! Is it possible to connect my playstation 3 to the iMac so that I could use it as a Monitor to play on? How, and what kind of additional cables will I need? thanks!

  • Photo library gone!

    I had lots of albums in my iphoto library yesterday.  I just went to download some more photos and all of my albums are gone.  The only thing in my library are the photos that I have just downloaded, can anyone help?

  • Has anyone else encountered a distorted/skewed Ai CC 2014 Welcome screen?

    I'm running Ai CC 2014.0.0 (v18.0.0) on Mac OS X 10.7.5 Lion. The the content of the Welcome screen is distorted/skewed. Has anyone else encountered - and resolved - this? NOTE: I just now updated Ai CC from v18.0.0 to v18.1.0. I get the same thing:

  • PS, Epson Color Management in OSX 10.6

    I know this is a problem way from way back but I thought I would revisit. It's clear that OSX 10.6 broke color management between Photoshop (PS)and my Epson R800. Since Epson no longer considers an R800 as a current printer I've resigned myself that