Just Curious about Log Colors

Discussion in 'Plugin Development' started by number1_Master, Aug 24, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    number1_Master

    I really want to know if it is possible to display colors in the console, but not for everything. Example: display colors for info messages and chosen exceptions, but not for whenever a player chats.
    Is that possible, or as soon as you remove -nojline colors appear whenever possible?

    Essentially, I want to remove color from certain messages sent to the console!
     
  2. Offline

    QuantumDev

    You can use:

    §1-f
     
  3. Offline

    number1_Master

    I'm not asking how to color the console. I'm asking if I can only allow / limit coloring to certain areas of the console.
     
  4. Offline

    QuantumDev

    If you log a message with §1, that message will be that color (or console equivalent).
     
  5. Offline

    number1_Master

    *facepalm* I know how to color console / chat / etc. What I'm asking is to CANCEL COLOR in a certain message. So if I were to cancel chat color in the console, I would have to CANCEL the logging message, change the logging message to have &f or whatever, then print it. Is that possible or is there any similar work around to that?
     
  6. Offline

    QuantumDev

    Going off memory, I think after each log the color automatically resets to default.
     
  7. Offline

    number1_Master

    With -nojline stated in the commandline, no colors will be printed to the console. Without it, colors (whenever possible) will be printed.
    I don't want colors to be printed whenever possible. I would like colors to be printed sometimes, yet not all the time.
     
  8. Offline

    QuantumDev

    For only your plugin or the whole console?
     
  9. ChatColor.stripColor(string) ?

    EDIT after some replies appeared :confused::
    I belive you can get the logger and add a filter to it if you want to remove colors from certain messages... I'm really confused about what you really need tough as I'm yet to see a plugin to print colored console messages (apart from my own xD)
     
  10. Offline

    number1_Master

    Console. I know how to do it for my own plugin :p
    Your edit is pretty much exactly what I'm looking for. I'm wondering if I can filter out colors from certain messages!
     
  11. Offline

    QuantumDev

    Well I don't think (I could be wrong, I've only been making plugins for 2 days) it's possible to change the whole logger within a single plugin :\ In the end, I'm not sure and I could be completely wrong, sorry I couldn't further help :(
     
  12. Offline

    number1_Master

    1.) It is O.K that you can't help. As long as you tried :)
    2.) WHAT THE F**K YOU MEAN IT ... jk jk
    2. (for real) ) Digi states that I can filter it. I'm thinking it is possible, but the easiest way is probably complicated.
     
  13. First get the general logger:
    Code:
    Logger logger = Logger.getLogger("Minecraft");
    You shouldn't use this for sending log messages, use this.getLogger() from your main class or plugin.getLogger().

    Next you can either set a filter or add a handler... a handler would be better because it doesn't override other plugins that might want to change something too... so:
    Code:
    logger.addHandler(new Handler()
    {
    	@Override
    	public void close() throws SecurityException
    	{
    	}
    
    	@Override
    	public void flush()
    	{
    	}
    
    	@Override
    	public void publish(LogRecord log)
    	{
    		log.setMessage(ChatColor.stripColor(log.getMessage()));
    	}
    });
    I'm unsure if ChatColor will strip the colors properly, they might have diferent characters in the console... you should also add some characters as prefix as debug so you know if and what messages are changed.


    I used a filter to block some messages sent by some classes I triggered (not errors), but I set my filter, blocked the messages and then restored the filter, I don't know if that will work for you as you seem to need a constant monitor of the messages, so use whatever method you need.
     
  14. Offline

    number1_Master

    So using that code alone will strip the color for all messages sent to the console?
    Is there a way to detect if the message is from something else, like chat?
     
Thread Status:
Not open for further replies.

Share This Page