The attribute fh is not a class attribute it is an instance attribute.
Either you change it to be private static or you create an object
MyLogToFileUsingFileHandler inside the main method and access the
attribute through this object.

MyLogToFileUsingFileHandler obj = new MyLogToFileUsingFileHandler();

mylog.addHandler(obj.fh);

On May 9, 3:44 pm, Stephen Adjei <[email protected]> wrote:
> please help me with this one. the file handler object I created gave me an 
> error;
> FileHandler fh = new FileHandler("file.txt");  .can some one correct me?
>
> public class MyLogToFileUsingFileHandler {
> private static Logger logger = Logger.getLogger("loggerdemo");
> private static Logger mylog = Logger.getLogger("myloggerdemo");
> FileHandler fh = new FileHandler("file.txt");  
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) throws Exception {
>         logger.addHandler(new FileHandler("MultipleHandlers.xml"));
>         mylog.addHandler(new FileHandler("myown.txt"));
>         mylog.info("starting operation");
>         mylog.setLevel(Level.ALL);
>         try{
>             System.out.println(3/0);
>         } catch(Exception e){
>             logger.log(Level.SEVERE,"dividing by 0");
>         }finally{
>             mylog.info("cant continue");
>         }
>         mylog.info("terminating");
>     }
>
>     }

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to