Request of all plugin developers - Verbose Logging

Discussion in 'Plugin Development' started by TnT, May 13, 2012.

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

    Gravity Retired Staff

    I think about 90% of you guys should also invest some time in getting rid of all those damn plugins.
     
    Sayshal likes this.
  2. Offline

    Jacek

    But moar plugons make mi server c00l ?

    Seriously, I have been trying to et rid of some for ages. It's harder than it looks.
     
    Sayshal likes this.
  3. Offline

    Njol

    I'm writing a plugin that should be able to replace a bunch of smaller plugins. Link is in sig if you're interested.
     
    Sayshal likes this.
  4. Offline

    Taco

    I'm in. I like this idea. I'll definitely keep this in mind with my next releases.
     
    Sayshal likes this.
  5. Offline

    TheRealZuriki

    I'm writing a plugin that I expect to be rather large. No idea if I'll ever release it to the public, but if I do, I'll make sure to have verbosity options.
     
  6. Offline

    number1_Master

    I agree but I think dev. should put any necessary information still.
     
  7. Offline

    LazuliCraft

    I'm in no rush to learn java/plugin deving, but I'm curious, how long does it actually take to know how to make simple bukkit plugins without referring you youtube videos every 10 seconds?
     
  8. Offline

    Sagacious_Zed Bukkit Docs

    It's similar to how one learns to speak a language fluently.
     
    Jacek likes this.
  9. Offline

    LazuliCraft

    lol, Ive been learning Spanish at school for 3 years and I'm terrible at it.
     
  10. Offline

    Sagacious_Zed Bukkit Docs

  11. Offline

    Father Of Time

    I started with C# as my primary Object Oriented Languages(OOL), I would say it was about 3 months before I used classes and variable properly (private, public, etc.), about a year before I began using instances properly, and then about 2 years before I used collections properly, keeping in mind I did it here and there as a hobby, no classes or anything of that nature.

    Now you will begin to use the above things almost immediately, but to use them correctly and efficiently is a different story... It's like playing the piano... Technically playing chop sticks is playing the piano, but so is Beethoven 5th... which would you think is doing it "correct"? Anyone can use collections almost immediately, but it takes practice and experience to learn what collections to use and when, and how to store data in the most efficient manner.

    I feel that you must have a firm understanding of objects, classes, variables and instances before you can truly unleash the power of OOL's.
     
  12. Offline

    Ne0nx3r0

    It's not so much a steady progression, instead it tends to come in leaps; you build up small pieces of knowledge and you find yourself in a moment where you're experienced enough to understand say why a method differs from a function, or when objects are passed by reference, and you can put the pieces together.

    I'd also agree with Sagacious_Zed . In fact you'll probably find yourself referencing MORE, not less as you get better. Very few people are so specialized in a particular language that they never have to look up something (or at least use the hints that modern IDE's give).
     
  13. Offline

    Orcem12

    @h31ix
    I prepared a small example for new developers.

    Example:
    Code:
        public void scm(String s){
            if(plugin.getConfig().getBoolean("verbose-logging") == true){
                plugin.log.info("["+plugin.getName()+"] "+plugin.getDescription().getVersion()+" "+s);
            }else{
                return;
            }
        }
    Or to use it in your main class:

    Code:
        public void scm(String s){
            if(this.getConfig().getBoolean("verbose-logging") == true){
                log.info("["+this.getName()+"] "+this.getDescription().getVersion()+" "+s);
            }else{
                return;
            }
        }
    In configuration:

    Code:
    # log everything in console or not.
    verbose-logging: true
    
    Easy as that.
     
    BobbyD441 likes this.
  14. Offline

    Sagacious_Zed Bukkit Docs

    Orcem12
    you don't need to see if a boolean is equals to true, a boolean can be either true or false....

    e.g.
    Code:
    public void scm(String s){
        if(plugin.getConfig().getBoolean("verbose-logging")){
            plugin.getLogger().info(MessageFormat.format("[{0}}] {1}",
              new String[]{plugin.toString(), s});
        }
    }
    or from the main class
    Code:
    public void scm(String s){
        if(this.getConfig().getBoolean("verbose-logging")){
            this.getLogger().info(MessageFormat.format("[{0}}] {1}",
              new String[]{this.toString(), s});
        }
    }
     
  15. Offline

    Orcem12

    @Sagacious_Zed
    Yes I'm aware but I was just providing a quick example or rather something to build off. For new developers probably most don't know that.
     
  16. Offline

    TnT Retired Staff

    Lots of interest in this, which is great! Now pass on the word to the other developers!
     
  17. Offline

    Orcem12

    Bump to keep awareness.
     
  18. I can certainly do this.
     
  19. Offline

    hatstand

    Long-term project I've been working on has this, as well as a switch for more graceful handling of (some) errors.
     
  20. I thought about this at first, I used a "debug: true/false" to change whenever it should print additional data... but now I'm just printing messages that NEED to be seen (like: "config.yml has been updated, delete it to see changes!") and the other details I send using log.fine/finer/finest() so they'll only be in the server.log but not in the server's console unless the admin specifies he wants fine messages as described here: http://forums.bukkit.org/threads/tagged-logging.55213/
     
  21. Offline

    Sagacious_Zed Bukkit Docs

    Why do people insist on putting if (booleanVariable == true) and if (booleanVariable == false)
    The following is the traditionally accepted way of denoting the same relationship if(booleanVariable) and if(!booleanVariable)
    where booleanVariable is a boolean variable.

    also common convention is to keep the name of the boolean positive.

    If one is writing example code, all the more reason to write proper examples.
     
  22. Offline

    ZachBora

    I have to admit this is a good idea, at the moment my host's web console cuts off displaying lines when too many happen at the same time. It's a pain when there is errors as those get cut and I have to look at the file instead.
     
  23. Offline

    Staartvin

    I'll keep this in my mind for all future plugins!
     
  24. Offline

    user_90681785

    Example code:
    Code:java
    1. public void log(String message, boolean debug, Level level) {
    2. String prefix = "[GuestUnlock] ";
    3. if (!debug) {
    4. logger.log(level, prefix + message);
    5. } else if (debug && configDebug) {
    6. logger.log(level, prefix + message);
    7. } else if (!configDebug && debug) {
    8. return;
    9. } else {
    10. logger.log(level, prefix + message);
    11. }
    12. }


    Then you would type like this when you should log something:
    Code:
     log("message", true/false, Level.INFO) 
    Message: the string you want to print
    True/false: Is this for debugging?
    Level.INFO: The logging level


    On my phone, couldn't copy.

    EDIT: Back on computer now, hereĀ“s the code pasted right in.
     

    Attached Files:

  25. Offline

    Sagacious_Zed Bukkit Docs

    Mylleranton
    stop using (debug == false), a simple (!debug) and (!configDebug) would have been sufficient. The more bad examples are put up, the more likely someone will find only bad examples.
     
  26. Offline

    Jacek

    Here is a better way

    Code:java
    1. if (((debug == false) == true) != false){
    2. // things
    3. }
     
  27. Offline

    Sayshal

    #TrollLogic
     
    ferrybig likes this.
  28. Offline

    Sagacious_Zed Bukkit Docs

    Can't wait for that to show up in someone's plugin /sarcasm
     
  29. Offline

    hatstand

    Wrong. It is far easier for someone who is just learning to code, to understand
    Code:java
    1. if(blah == true)

    as opposed to
    Code:java
    1. if(blah)

    They are both equally as valid, and in some situations, long hand is easier to understand. You're just being pedantic about it, code that doesn't use shorthand with booleans isn't any less valid, or of any lower quality.
     
    Jacek likes this.
  30. Offline

    Njol

    That's why booleans should usually start with 'is', e.g. 'isInDebugMode'.
    For me,
    Code:java
    1. if (isInDebugMode)

    makes much more sense than
    Code:java
    1. if (isInDebugMode == true)
     
Thread Status:
Not open for further replies.

Share This Page