Solved Is there a better way to do this?

Discussion in 'Plugin Development' started by tryy3, May 8, 2014.

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

    tryy3

    Hi I am wondering if there is a better way to do this

    Code:java
    1. public static void log(String level, String message)
    2. {
    3. level = level.toUpperCase();
    4. if (level.equalsIgnoreCase("info"))
    5. {
    6. Instance.getLogger().log(Level.INFO, message);
    7. }
    8. }



    pretty much what I am wondering, is there a way to do Level + level instead of needing to type out every Level?
     
  2. tryy3
    I would assume that Level is an enum, so you can use Level.valueOf(level).
     
  3. Offline

    tryy3

    Assist
    The Level is the logging level class, and there is no valueOf method unless I did something wrong!
     
  4. Offline

    HungerCraftNL

    You've to use .toLowerCase() because your check is in lower case too.
     
  5. Offline

    tryy3

    HungerCraftNL
    the toUpperCase() was just me messing around, ignore that :p
     
  6. tryy3
    In that case, use Level.parse(level).
     
  7. Offline

    tryy3

    Assist
    Yeah I found it when I was messing around waiting for a response here, thanks :)
     
  8. Offline

    HungerCraftNL

Thread Status:
Not open for further replies.

Share This Page