2 * This file is part of NixNote/NeighborNote
3 * Copyright 2009 Randy Baumgarte
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
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.
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.
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;
27 import cx.fbn.nevernote.Global;
30 public class ApplicationLogger {
32 public final int LOW = 1;
33 public final int MEDIUM = 2;
34 public final int HIGH = 3;
35 public final int EXTREME = 4;
37 FileOutputStream fileStream;
38 PrintStream stdoutPrintStream;
40 // private final List<String> logText;
42 public ApplicationLogger(String name){
43 // logText = new ArrayList<String>();
45 fileStream = new FileOutputStream(Global.getFileManager().getLogsDirFile(name));
46 } catch (FileNotFoundException e) {
47 // TODO Auto-generated catch block
51 // stdoutStream = new OutStream(new ByteArrayOutputStream(), name);
52 stdoutPrintStream = new PrintStream(fileStream);
53 // systemStdoutPrintStream = System.out;
56 // public List<String> getText() {
57 // return stdoutStream.getText();
64 // public List<String> getLogText() {
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);
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);
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);
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-");
99 System.out.println("**************************");
100 System.setOut(stdoutPrintStream);
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-");
111 System.out.print("**************************");