OSDN Git Service

ノートコンテンツをwordテーブルに登録しないように変更。
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / utilities / ApplicationLogger.java
1 /*
2  * This file is part of NixNote/NeighborNote 
3  * Copyright 2009 Randy Baumgarte
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
8  * Software distributed under the License is distributed
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10  * express or implied. See the GPL for the specific language
11  * governing rights and limitations.
12  *
13  * You should have received a copy of the GPL along with this
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html
15  * or write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18 */
19
20 package cx.fbn.nevernote.utilities;
21 import java.io.FileNotFoundException;
22 import java.io.FileOutputStream;
23 import java.io.PrintStream;
24 import java.text.SimpleDateFormat;
25 import java.util.Calendar;
26
27 import cx.fbn.nevernote.Global;
28
29
30 public class ApplicationLogger {
31         
32         public final int LOW = 1;
33         public final int MEDIUM = 2;
34         public final int HIGH = 3;
35         public final int EXTREME = 4;
36         
37         FileOutputStream fileStream;
38         PrintStream              stdoutPrintStream;
39         
40 //      private final List<String> logText;
41         
42     public ApplicationLogger(String name){
43 //        logText = new ArrayList<String>();
44         try {
45                         fileStream = new FileOutputStream(Global.getFileManager().getLogsDirFile(name));
46                 } catch (FileNotFoundException e) {
47                         // TODO Auto-generated catch block
48                         e.printStackTrace();
49                 }
50         
51 //        stdoutStream = new OutStream(new ByteArrayOutputStream(), name);
52         stdoutPrintStream  = new PrintStream(fileStream);
53  //     systemStdoutPrintStream = System.out;
54     }
55
56 //    public List<String> getText() {
57 //      return stdoutStream.getText();
58 //    }
59     
60
61         /**
62          * @return the logText
63          */
64 //      public List<String> getLogText() {
65 //              return logText;
66 //      }
67         
68
69     public synchronized void log(int messageLevel, String s) {
70         if (messageLevel <= Global.messageLevel) {
71                 String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss.SS ";
72             Calendar cal = Calendar.getInstance();
73             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
74                         
75                         stdoutPrintStream.println(sdf.format(cal.getTime()) +s);
76 //              System.setOut(stdoutPrintStream);
77 //              System.out.println(sdf.format(cal.getTime()) +s);
78 //              System.setOut(systemStdoutPrintStream); 
79         }
80     }
81     
82     public void log(int level, StackTraceElement e[]) {
83                 if (level >= Global.messageLevel) {
84                         String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss.SS ";
85             Calendar cal = Calendar.getInstance();
86             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
87             
88 //                      System.setOut(systemStdoutPrintStream);
89                         System.out.println(e);
90                 System.out.println("*** Stack Trace Requested ***");
91                 System.out.println(sdf.format(cal.getTime()));
92                 for (StackTraceElement element : e) {
93                         System.out.println("Line Number: " +new Integer(element.getLineNumber()));
94                         System.out.println("Class Name: " +element.getClassName());
95                         System.out.println("Method Name:" +element.getMethodName());
96                         System.out.println("File Name:" +element.getFileName());
97                         System.out.println("-Next Element-");
98                 }
99                 System.out.println("**************************"); 
100                 System.setOut(stdoutPrintStream);
101                         System.out.print(e);
102                 System.out.print("*** Stack Trace Requested ***");
103                 System.out.print(sdf.format(cal.getTime()));
104                 for (StackTraceElement element : e) {
105                         System.out.print("Line Number: " +new Integer(element.getLineNumber()));
106                         System.out.print("Class Name: " +element.getClassName());
107                         System.out.print("Method Name:" +element.getMethodName());
108                         System.out.print("File Name:" +element.getFileName());
109                         System.out.print("-Next Element-");
110                 }
111                 System.out.print("**************************"); 
112                 }
113     }
114 }