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.

Page 1 of 2 12 LastLast
Results 1 to 25 of 36

Thread: can't seem to find the log

  1. #1
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default can't seem to find the log

    Hi
    Following is the user class Logger
        class Logger {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod12.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
     
            public Logger(IConsole cons, String lf, boolean inf, boolean err, boolean dbg) {
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {}
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {}
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {}
                     }
                 } catch (IOException e) {
                 }
             } // end LogToFile
    ***********************************************
    Having the following
    private String   logFile  = "C:/Users/Bob/Documents/BM_mod12.log";
    why do I not find a log file in the documents folder ?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    Are there any exceptions thrown? Empty catch blocks ignore any exception.
     catch (IOException e) {}
    Add a call to printStackTrace to the catch blocks to print a message/trace if there is an exception.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    Have done !

    Will see what the output is, if any, on Monday [today is Saturday here in NZ]

    Bob M

  4. #4
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    no exceptions !

    currently INFO: messages appear on the console

    Bob M

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    Have you solved your problem now?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    no - can't seem to produce the log

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    I get this when I execute the code:
    java.io.IOException: Stream closed
    at sun.nio.cs.StreamEncoder.ensureOpen(Unknown Source)
    at sun.nio.cs.StreamEncoder.flush(Unknown Source)
    at java.io.OutputStreamWriter.flush(Unknown Source)
    at BobsLogger.LogToFile(BobsLogger.java:72)
    at BobsLogger.main(BobsLogger.java:87)
    Are you sure you put a call to printStackTrace in all the catch blocks?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    current code
        class Logger {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod10.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
     
            public Logger(IConsole cons, String lf, boolean inf, boolean err, boolean dbg) {
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                     }
                 } catch (IOException e) {
                        System.out.println("Error: " + e.getMessage());
                        e.printStackTrace();
                         }
     
             } // end LogToFile
     
        } // end of class Logger

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    Where is a main method for testing the code?
    What is printed on the console when the code is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    Hi Norm

    "Where is a main method for testing the code?"
    Unsure what you mean - I am simply running the whole code

    "What is printed on the console when the code is executed?"

    The various INFO statements I would expect when a trade is initiated

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    I usually add a main method to simple utility classes like this to allow easy standalone testing. Here is an example of the one I used with your code. It allows both of us to execute the same code for testing without any other requirements.
             public static void main(String[] args) {
                BobsLogger bl = new BobsLogger(new IConsole(), logFile, false, false, false);
                bl.Log("This is  a test 2");
             }
    Add a main to your code so that it can be executed by itself and demonstrate the problem.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    Thanks Norm

    Will do

    Bob M

  13. #13
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    Am I correct in thinking that the 3 flushes and closes are the reason that the log file is gone by the time I go to look for it ?

    Bob M

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    No. The flush clears any data left in the buffer.

    Did you make a small, complete class with a main that can be compiled and executed for testing to demonstrate the problem?
    Please post it and the contents of the console from when it is executed.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    I am confused as usual................

    Are we running this on the Dukascopy platform
    It seems we are with IConsole
    but we need other Dukascopy components as well

    or are we running a stand alone java program ?

    --- Update ---

        class Logger {
     
            public static void main(String[] args) {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod10.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
                BobsLogger bl = new BobsLogger(new IConsole(), logFile, false, false, false);
                bl.Log("This is  a test 2");
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                     }
                 } catch (IOException e) {
                        System.out.println("Error: " + e.getMessage());
                        e.printStackTrace();
                         }
     
             } // end LogToFile
          }
       } // end of class Logger

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    We are testing the code in the Logger class to find the problem you are having. The rest of the code is not needed for the test.

    Here is a version of IConsole for testing:
       class IConsole {      // ADDED <<<<<<<<
          PrintStream getOut() {
             return System.out;
          }
       }
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    but running on the Dukascopy platform or as a stand alone program ?

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    Stand alone.
    If you don't understand my answer, don't ignore it, ask a question.

  19. #19
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    but running on the Dukascopy platform or as a stand alone program ?

    --- Update ---

    output

    c:\Users\rgmat\Desktop>javac logger.java
    logger.java:5: error: illegal start of expression
    private IConsole console = null;
    ^
    logger.java:12: error: <identifier> expected
    bl.Log("This is a test 2");
    ^
    logger.java:12: error: illegal start of type
    bl.Log("This is a test 2");
    ^
    logger.java:13: error: <identifier> expected
    console = cons;
    ^
    logger.java:14: error: <identifier> expected
    logFile = lf;
    ^
    logger.java:15: error: <identifier> expected
    info = inf;
    ^
    logger.java:16: error: <identifier> expected
    error = err;
    ^
    logger.java:17: error: <identifier> expected
    debug = dbg;
    ^
    logger.java:18: error: illegal start of type
    if (!"".equals(lf)) new File(logFile).delete();
    ^
    logger.java:18: error: invalid method declaration; return type required
    if (!"".equals(lf)) new File(logFile).delete();
    ^
    logger.java:18: error: <identifier> expected
    if (!"".equals(lf)) new File(logFile).delete();
    ^
    logger.java:18: error: ';' expected
    if (!"".equals(lf)) new File(logFile).delete();
    ^
    logger.java:21: error: class, interface, or enum expected
    public void info(String Data) {
    ^
    logger.java:24: error: class, interface, or enum expected
    Log(Data);
    ^
    logger.java:25: error: class, interface, or enum expected
    }
    ^
    logger.java:28: error: class, interface, or enum expected
    public void error(String Data) {
    ^
    logger.java:31: error: class, interface, or enum expected
    Log(Data);
    ^
    logger.java:32: error: class, interface, or enum expected
    }
    ^
    logger.java:35: error: class, interface, or enum expected
    public void debug(String Data) {
    ^
    logger.java:38: error: class, interface, or enum expected
    Log(Data);
    ^
    logger.java:39: error: class, interface, or enum expected
    }
    ^
    logger.java:45: error: class, interface, or enum expected
    LogToFile(Data);
    ^
    logger.java:46: error: class, interface, or enum expected
    } catch (Exception e) {
    ^
    logger.java:53: error: class, interface, or enum expected
    if ("".equals(logFile)) return;
    ^
    logger.java:55: error: class, interface, or enum expected
    File file = new File(logFile);
    ^
    logger.java:56: error: class, interface, or enum expected
    FileOutputStream fos = new FileOutputStream(file, true);
    ^
    logger.java:57: error: class, interface, or enum expected
    OutputStreamWriter osw = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
    ^
    logger.java:58: error: class, interface, or enum expected
    BufferedWriter bw = new BufferedWriter(osw);
    ^
    logger.java:59: error: class, interface, or enum expected
    try {
    ^
    logger.java:61: error: class, interface, or enum expected
    } finally {
    ^
    logger.java:64: error: class, interface, or enum expected
    bw.close();
    ^
    logger.java:65: error: class, interface, or enum expected
    } catch (IOException e) {
    ^
    logger.java:67: error: class, interface, or enum expected
    e.printStackTrace();
    ^
    logger.java:68: error: class, interface, or enum expected
    }
    ^
    logger.java:71: error: class, interface, or enum expected
    osw.close();
    ^
    logger.java:72: error: class, interface, or enum expected
    } catch (IOException e) {
    ^
    logger.java:74: error: class, interface, or enum expected
    e.printStackTrace();
    ^
    logger.java:75: error: class, interface, or enum expected
    }
    ^
    logger.java:78: error: class, interface, or enum expected
    fos.close();
    ^
    logger.java:79: error: class, interface, or enum expected
    } catch (IOException e) {
    ^
    logger.java:81: error: class, interface, or enum expected
    e.printStackTrace();
    ^
    logger.java:82: error: class, interface, or enum expected
    }
    ^
    logger.java:86: error: class, interface, or enum expected
    e.printStackTrace();
    ^
    logger.java:87: error: class, interface, or enum expected
    }
    ^
    44 errors

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    Can you post the actual code in the logger.java file that you passed to the javac.exe command?

    --- Update ---

    I am done for tonight. I'll be back tomorrow.
    If you don't understand my answer, don't ignore it, ask a question.

  21. #21
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    output 2 errors
    c:\Users\rgmat\Desktop>javac logger.java
    logger.java:5: error: illegal start of expression
    private IConsole console = null;
    ^
    logger.java:91: error: class, interface, or enum expected
    } // end of class Logger
    ^
    2 errors - not sure how to get rid of these 2

    class Logger {
     
            public static void main(String[] args) {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod10.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
                BobsLogger bl = new BobsLogger(new IConsole(), logFile, false, false, false); {
                bl.Log("This is  a test 2");
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                     }
                 } catch (IOException e) {
                        System.out.println("Error: " + e.getMessage());
                        e.printStackTrace();
                         }
     
             } // end LogToFile
    	}     
       } // end of class Logger
    Last edited by BobM; March 16th, 2021 at 09:31 PM.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    The structure of the source file needs fixing. The structure should be like this:
    class statement {
    fields for the class
    method declarations with {}s
    } at end of class

    Start with the code in post#8
    add a main method just before the } at the end of the class.
      public static void main(String[] args) {
        //  add code here to declare an instance of the logger class
        //  add code to call some of the logger class's methods
      }  // end main
    }  // end of logger class

    Did you write the code for the logger class? Or was it copied from somewhere else?
    I am having a hard time understanding your java knowledge. The person that wrote the logger class would know how to add a method to the class.
    If you don't understand my answer, don't ignore it, ask a question.

  23. #23
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    current code
    class Logger {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod14.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
     
            public Logger(IConsole cons, String lf, boolean inf, boolean err, boolean dbg) {
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                     }
                 } catch (IOException e) {
                        System.out.println("Error: " + e.getMessage());
                        e.printStackTrace();
                         }
     
             } // end LogToFile
     
    		 public static void main(String[] args) {
        //  add code here to declare an instance of the logger class
             BobsLogger bl = new BobsLogger(new IConsole(), logFile, false, false, false);
             bl.Log("This is  a test 2");
     
        //  add code to call some of the logger class's methods
            class IConsole {      // ADDED <<<<<<<<
               PrintStream getOut() {
               return System.out;
               }
            }      
     
    	  }  // end main
     
        } // end of class Logger

    20 errors ?????

    I did not write the code for the logger class

    My java knowledge only comes from altering other people's code
    Bit by bit, I have picked up small snippets of knowledge

  24. #24
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: can't seem to find the log

    The name of your version of the class is Logger. That is what you need to use in the main method, not BobsLogger.
    For my testing I changed it to BobsLogger to keep from having a confusing class in my work area.

    I created the class IConsole because I do not have a version of that class. I expected you to have a definition for that class because you normally compile with it. For the testing, the definition of that class should not be inside of the main method.

    Where are the import statements? They are needed for the java io classes like File and IOException.

    How does your code call the Logger class's constructor? What statements have: new Logger() in them?
    How does your code call the Logger class's methods?

    --- Update ---

    I did not write the code for the logger class
    Can you give me some history of where the Logger class came from?
    Did it ever work?
    Can you contact the author for a fix?
    If you don't understand my answer, don't ignore it, ask a question.

  25. #25
    Member
    Join Date
    Mar 2021
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: can't seem to find the log

    errors..........
    c:\Users\rgmat\Desktop>javac logger.java
    location: class Logger.IConsole
    logger.java:113: error: non-static variable this cannot be referenced from a static context
    Logger l = new Logger(new IConsole(), logFile, false, false, false);
    ^
    logger.java:113: error: non-static variable logFile cannot be referenced from a static context
    Logger l = new Logger(new IConsole(), logFile, false, false, false);
    ^
    2 errors
    *********************************************
    current code
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.OutputStreamWriter;
    import java.io.IOException;
    import java.util.HashSet;
    import java.util.Vector;
    import java.text.DecimalFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;
    import java.util.Set;
    import java.util.TimeZone;
    import java.io.*;
     
    class Logger {
     
            private IConsole console = null;
            private String   logFile  = "C:/Users/Bob/Documents/BM_mod14.log";
            private boolean  info     = true;
            private boolean  error    = true;
            private boolean  debug    = true;
     
     
            public Logger(IConsole cons, String lf, boolean inf, boolean err, boolean dbg) {
                console = cons;
                logFile = lf;
                info    = inf;
                error   = err;
                debug   = dbg;    
                if (!"".equals(lf)) new File(logFile).delete();
            }
     
            //  add code to call some of the logger class's methods
            class IConsole {      // ADDED <<<<<<<<
               PrintStream getOut() {
               return System.out;
               }
            }      
     
    		public void info(String Data) {
                if (info) {
                    Data = "INFO  : " + Data;
                    Log(Data);
                }
            }
     
            public void error(String Data) {
                if (error) {
                    Data = "ERROR :  " + Data;
                    Log(Data);                
                }            
            }
     
            public void debug(String Data) {
                if (debug) {
                    Data = "DEBUG :  " + Data;
                    Log(Data);                
                }            
            }
     
            private void Log(String Data) {
                 try {
                     if (console != null) console.getOut().println(Data);
                     LogToFile(Data);
                 } catch (Exception e) {
                 }
             }    
     
             private void LogToFile(String Data) {
                 try {    
                     if ("".equals(Data)) return;
                     if ("".equals(logFile)) return;
     
                     File                 file = new File(logFile);                                
                     FileOutputStream     fos  = new FileOutputStream(file, true);
                     OutputStreamWriter   osw  = new OutputStreamWriter(fos, "Cp1252" /* "ISO-8859-1" */);
                     BufferedWriter       bw   = new BufferedWriter(osw);
                     try {
                         bw.write(Data + "\n");
                     } finally {
                         try {
                             bw.flush();
                             bw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             osw.flush();
                             osw.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                         try {
                             fos.flush();
                             fos.close();
                         } catch (IOException e) {
                             System.out.println("Error: " + e.getMessage());
                             e.printStackTrace();
                         }
                     }
                 } catch (IOException e) {
                        System.out.println("Error: " + e.getMessage());
                        e.printStackTrace();
                         }
     
             } // end LogToFile
     
    		 public static void main(String[] args) {
        //  add code here to declare an instance of the logger class
             Logger l = new Logger(new IConsole(), logFile, false, false, false);
             l.Log("This is  a test 2");
     
        //  add code to call some of the logger class's methods
     
    	  }  // end main
     
        } // end of class Logger

    Answers:-
    "Can you give me some history of where the Logger class came from?"
    It is a small part of a rather large strategy I have a copy of - dates from Jan 2010

    "Did it ever work?"

    I can not tell

    "Can you contact the author for a fix?"

    No

    The IConsole class comes from the Dukascopy API
    Last edited by BobM; March 18th, 2021 at 03:26 PM.

Page 1 of 2 12 LastLast

Similar Threads

  1. Can't find the out put
    By javab4 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 4th, 2013, 05:07 PM
  2. Is there a way to find the url of the applet?
    By micro kid in forum Java Applets
    Replies: 1
    Last Post: June 11th, 2012, 07:21 AM
  3. Cannot find symbol
    By BadgerWatch in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 6th, 2011, 11:25 PM
  4. Cannot find symbol?
    By stealthmonkey in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 10th, 2010, 10:02 PM
  5. find LCS
    By Anemone_ in forum Algorithms & Recursion
    Replies: 1
    Last Post: November 28th, 2010, 02:03 PM