[SOLVED]Change text color when using the logger

Discussion in 'Plugin Development' started by TechManDylan, Mar 28, 2012.

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

    TechManDylan

    More or less what the title say I'm doing
    Code:
     Bukkit.getServer().getLogger().warning(" PermissionsEx is not enabled.");
    and I was wondering if I could for instance make it red.
    I tried using ChatColor.RED but it gives an error.
    EDIT: Look below for what's currently going on
     
  2. Offline

    anerach

    try
    Code:java
    1. Bukkit.getServer().getLogger().severe(" PermissionsEx is not enabled.");
     
  3. Offline

    TechManDylan

    Didn't work I tried it and the text remained white. Any other ideas?
     
  4. How did ChatColor.RED give an error?

    Bukkit.getServer().getLogger().warning(ChatColor.RED + "PermissionsEx is not enabled.");
     
  5. Offline

    TechManDylan

    Oh wow I feel like a moron.... had a typo I have been staring at my screen to long thanks for the help looking at that made me realize it thank you
     
  6. Offline

    Lolmewn

    Please tell what the typo was, if other users have the same problem (for some reason) then a typo in ChatColor or whatever might be useful to know.
     
  7. Offline

    TechManDylan

    Oh lemme see if I can duplicate the error real quick and I will post it

    Oh well I just got around to testing this and using
    Code:
    Bukkit.getServer().getLogger().warning( ChatColor.RED + "[Slimey Vines] PermissionsEx is not enabled.");
    Gives me this in the console
    Code:
    07:35:03 [WARNING] ?c[Slimey Vines] PermissionsEx is not enabled.
    Any ideas as to why it's giving me "?c" instead of adding the chat color

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  8. Offline

    TechManDylan

  9. Offline

    ZachBora

    You need a different console. On linux it would work as is I believe. On windows you need to download some special command line program, I don't know what it is. Mac I don't know anything about those.
    For Web console, I guess it depends if the UI reads the log file or reads from the console.
     
  10. Offline

    Father Of Time

    It's because the windows platform is 100% incapable of ANSI escape sequences. It's an issue with legacy programming. Long story short it's impossible without using external libraries, like javacurse.

    http://sourceforge.net/projects/javacurses/?_test=b

    [​IMG]


    Which is a library for console text color and boxed window development. Sorry, windows has just seemed to drop the ball on this one... *hates to ever admit that* :(
     
  11. Offline

    TechManDylan

    Well the weird thing is I'm on hosting this on my Mac Pro OSX Lion and I see other colored chat in the console so that's why I was a bit confused
     
  12. Offline

    ZachBora

    Interesting. Maybe it's a bug, you should verify the leaky.
     
  13. Offline

    TechManDylan

    Ok now that something I don't know how to do, and would be ever so grateful if you explained. :D
     
  14. Offline

    ZachBora

    http://leaky.bukkit.org/
     
  15. Offline

    TechManDylan

    You guys are great just throwing that out there. Thanks for the link I shall scour the page and see if I can find anything.
     
  16. Offline

    dillyg10

    Ok, here is why it isn't working, and why it cannot work.

    First, it is not a bug :D. A logger does not support the char ยง which is the makeup of the ChatColor , so the logger will replace it with a ?, and bukkit doesn't see that as a chatcolor, and doesn't replace the black text with the hexidecimal color value. You can use color tho for a commandsender in the console.
     
    TheKingElessar likes this.
  17. Offline

    TechManDylan

    Oh there we go you just saved me a little bit of digging thank you for helping get this figured out.
     
  18. Offline

    dillyg10

    no prob :).
     
  19. Offline

    Chrono7

    I had this same issue, and for anyone wondering, an easy way to fix it is use this code:

    Code:
    Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "-message here-");
     
    ShadowSplicer and Ultimate_n00b like this.
  20. Offline

    Jnorr44

    (I think) A better way of doing this is triggering an event that normally sends a message to a player, and use a sendMessage.

    An example:
    Code:
        public boolean Command(final CommandSender player, final Command inf, final String Label, final String[] args) {
            Player person = null;
            if (!(player instanceof Player)) {
                person = (Player) player;
            }
            if (player == null){
                person.sendMessage("This is actually a person!");
                return false;
            }else{
                player.sendMessage(ChatColor.BLUE + "This is sent to the console (i think)");
            }
            return false;
        }
     
  21. Offline

    LegendaryViper

    I have the same problem here, Im trying to get my logger in color and I use the following:
    Code:
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() + " v" + org.fusesource.jansi.Ansi.Color.GREEN + pdfFile.getVersion() + " Has Been Enabled!");
        }
    I get the following below when I used this code:
    Code:
    14:11:21 [INFO] [MAX HEAL] Enabling MAX HEAL v2.0
    14:11:21 [INFO] MAX HEAL vGREEN2.0 Has Been Enabled!
    What do I do to get it in code?
     
  22. Offline

    ZachBora

  23. Offline

    LegendaryViper

    I did but it didn't display it in color, I got just some kind of code when I ran the server
     
  24. Offline

    ZachBora

    I believe it depends on the OS you use and how you start it. The coloring stuff to color in windows needs a third party thing installed. You should be able to find what it is on the forum somewhere.

    Edit: just checked for you, you need one of these :
    For windows 64bit : http://www.microsoft.com/en-nz/download/details.aspx?id=15336
    For windows 32bit: http://www.microsoft.com/en-nz/download/details.aspx?id=29
     
  25. Offline

    Ultimate_n00b

    Listen to this guy.
     
    ShadowSplicer likes this.
  26. Offline

    LegendaryViper

    I have Microsoft Visual C++ already, in fact, I have the 2010 version of it and some older versions of it. What do I do now
     
Thread Status:
Not open for further replies.

Share This Page