[UTIL / TIP] Getting the console output (Logger-messages)

Discussion in 'Resources' started by Th3Shad0wOfDeath, Sep 25, 2013.

Thread Status:
Not open for further replies.
  1. Hey guys,

    did you ever want to code a plugin that needs the console output, but you didn't know how to do it?

    Code:
    Code:java
    1. public abstract class ConsoleOutputHandler extends Handler
    2. {
    3.  
    4. public ConsoleOutputHandler()
    5. {
    6. }
    7.  
    8. @Override
    9. public native void flush();
    10.  
    11. @Override
    12. public native void close() throws SecurityException;
    13.  
    14. @Override
    15. public abstract void publish(LogRecord record);
    16.  
    17. }
    18.  


    How to use this class:
    Code:java
    1. public class [YourClass] extends ConsoleOutputHandler
    2. {
    3. public OutputHandling()
    4. {
    5. }
    6.  
    7. @Override
    8. public void publish(LogRecord record)
    9. {
    10. // Do what you want
    11. }
    12.  
    13. }
    14.  


    To implement the Handler you need to add this in onEnable():
    Code:java
    1. getServer().getLogger().addHandler(new [YourClass]());


    BTW I'm going to release a PluginAPI soon, which automaticly registers externel Listeners and Commands and contains some Util classes as this class ontop.
     
  2. where is the native code of the methodes flush() and close() impemented?
     
  3. I really don't know. I "redesigned" the use of this class. I will update the code and the usage of this class!
     
  4. Offline

    Chinwe

    Isn't this the same as this one, that doesn't require a whole new class? :oops:
     
  5. Looks like it, but I did it for my API I'm gonna release soon. I just made this class, that I don't have to implement the flush() and close() methods all over again.
     
Thread Status:
Not open for further replies.

Share This Page