Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Custom Log level help

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Logger custom level help

    Ok, i know that i am doing something wrong and if possible would like to be pointed in the right direction. Im just learning java, my background is in c/c++.

    I need to be able to add custom levels to the logger and im defiantly doing it wrong. Couldnt find much on the internet about it.

    Any help would be greatly appreciated. Here is my code so far.

    import java.util.Scanner;
    import java.util.logging.FileHandler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.io.*;
     
     
    public class LogRunner {
    	public static void main(String[] args) {
     
     
                       // This is what i could come up with so far but its wrong.
    		   // Create the new levels
     
    	 final Level LogRunner debug = new LogRunner();
    	 final Level LogRunner error = new LogRunner();
     
                    try{	
     
    			FileHandler hand = new FileHandler("application.log");
    			  Logger log = Logger.getLogger("log_file");
     
    			  log.addHandler(hand);
    			  log.debug("This is bad debug it! ");
    			  log.info("Here is the info ");
    			  log.warning("DANGER DANGER ");
    			  log.error("There seems to be an error ");
    			  System.out.println(log.getName());
    		}
    		catch(IOException e){}
    	}
     
    }

    Thanks in advance for any help

    seanman
    Last edited by seanman; September 25th, 2011 at 08:39 PM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,343
    Thanks
    182
    Thanked 831 Times in 774 Posts
    Blog Entries
    5

    Default Re: Custom Log level help

    1) Create a new class definition that extends Level. You must implement one of the protected constructors, and call the super constructor within this constructor.
    2) Create an instance of this new class using the constructor defined in (1), be sure to set its level value as needed (see the API for Level for the values defined in the default Level classes).
    3) Set the level of the Logger using this custom level.
    Try the above, and if you get stuck post back with all relevant code.

Similar Threads

  1. Setting a transparency level of a picture issue
    By Asido in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2012, 05:42 AM
  2. can i use custom buttons ?
    By Gaurav18 in forum Member Introductions
    Replies: 3
    Last Post: September 12th, 2011, 09:56 AM
  3. Quick, beginner-level Java question.
    By DHG in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2011, 12:06 PM
  4. Custom Table using AbstractTableModel
    By dumb_terminal in forum AWT / Java Swing
    Replies: 11
    Last Post: November 16th, 2010, 09:02 AM
  5. need help w/ entry level homework...
    By rbread80 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 3rd, 2010, 10:24 PM