View Javadoc

1   // %265036924:hoplugins.commons.utils%
2   package hoplugins.commons.utils;
3   
4   import java.io.File;
5   import java.io.FileOutputStream;
6   import java.io.PrintStream;
7   
8   import java.util.Date;
9   
10  
11  /***
12   * TODO Missing Class Documentation
13   *
14   * @author TODO Author Name
15   */
16  public class Debug {
17      //~ Static fields/initializers -----------------------------------------------------------------
18  
19      /*** TODO Missing Parameter Documentation */
20      private static final String logFile = "PluginsErrorLog.txt";
21  
22      /*** TODO Missing Parameter Documentation */
23      private static final String separator = "--- ";
24  
25      //~ Constructors -------------------------------------------------------------------------------
26  
27      /***
28       * Creates a new Debug object.
29       */
30      public Debug() {
31      }
32  
33      //~ Methods ------------------------------------------------------------------------------------
34  
35      /***
36       * TODO Missing Method Documentation
37       *
38       * @param s TODO Missing Method Parameter Documentation
39       */
40      public static synchronized void log(String s) {
41          try {
42              PrintStream log = openLog();
43              log.println(s);
44              log.close();
45          } catch (Exception e2) {
46          }
47      }
48  
49      /***
50       * TODO Missing Method Documentation
51       *
52       * @param e TODO Missing Method Parameter Documentation
53       */
54      public static synchronized void logException(Exception e) {
55          try {
56              PrintStream log = openLog();
57              e.printStackTrace(log);
58              log.close();
59          } catch (Exception e2) {
60          }
61      }
62  
63      /***
64       * TODO Missing Method Documentation
65       *
66       * @return TODO Missing Return Method Documentation
67       */
68      private static synchronized PrintStream openLog() {
69          PrintStream log = null;
70  
71          try {
72              // Open log file in append mode.
73              File file = new File(logFile);
74              log = new PrintStream(new FileOutputStream(file, true));
75  
76              // Added timestamp.
77              Date date = new Date();
78              log.print(separator);
79              log.println(date.toString());
80              log.println();
81          } catch (Exception e) {
82          }
83  
84          return log;
85      }
86  }