Results 1 to 5 of 5
  1. #1
    JavaUser1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default Need help using a class

    Hello,

    I am trying to implement the feature from this link, How to redirect stdout and stderr writing to a log4j appender | SysGears and I need some help with it, please.

    I have compiled the class successfully. The author of the article failed to mention what classes need to be imported and I had to figure that out the hard way, as it took me some time to deduce this. In the next step, the author states to use the class, write the following:

    Java Code:
    System.setErr(new PrintStream(new LoggingOutputStream(
            System.err, Logger.getLogger("outLog"), Level.ERROR)));
    Wonderful. I have a question, though? What does this even mean? Where do I write it? In the same file as the class was declared? In a different file? What should the import declarations be? What would be the full java file, everything included?

    If somebody can help me, I would appreciate it. Thank you.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default

    I suspect that it doesn't matter where you write it, as long as it comes before the stuff you want to log. Try it out in different places. Check out the API for System.setErr() and System.setOut().
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    JavaUser1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    Thank you. Yes, that makes sense. But I am stuck at the format of what the java file should look like. All the author wrote was these two lines but I can't just stick this in a java file and compile it--it won't work. I need to specify at least one import, namely the class the author wrote. So, could someone please show me what the java file should look like? How do I import the class? Thank you.

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    So what aim do you want make?
    I don't know where author that article found this info
    Log4j doesn't support stdout and stderr logging by default.
    Log4j can make it without write extended code.
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    JavaUser1 is offline Member
    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Default

    With Log4j, I wanted to take stdout and stderr and use rollover to specify max file size, number of backups, and date pattern. Consoleappender doesn't log to a specific file, like fileappender. So, this author came up with this routine to directly manipulate stdout and stderr, which is what i'm trying to implement. If there's another way, a simpler way, to write stderr and stdout to a filename of my choosing and allow it to rollover on max file size, backups, and date, using log4j, I'm all ears. Thank you very much for any help.

Similar Threads

  1. Replies: 0
    Last Post: 03-27-2011, 05:49 AM
  2. Replies: 5
    Last Post: 01-26-2011, 06:38 PM
  3. Replies: 8
    Last Post: 04-14-2010, 05:49 AM
  4. Replies: 7
    Last Post: 05-06-2009, 12:42 PM
  5. Replies: 8
    Last Post: 03-21-2009, 09:34 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •