1 25 package net.sf.javaguard.log; 26 27 import java.io.PrintWriter ; 28 29 30 31 32 37 public class ScreenLogger implements Log { 38 39 private int logLevel; 40 41 42 43 private static ScreenLogger theInstance = null; 44 45 private static String whitespaces = " "; 46 47 48 49 50 53 public static ScreenLogger getInstance() { 54 if (null == theInstance) { 55 theInstance = new ScreenLogger(); 56 } 57 return theInstance; 58 } 59 60 61 62 63 64 private ScreenLogger() { 65 setLoggingLevel(NORMAL); 66 } 67 68 69 70 71 77 public void setLoggingLevel(int level) { 78 logLevel = level; 79 } 80 81 82 85 public int getLoggingLevel() { 86 return logLevel; 87 } 88 89 90 92 public void incrementLoggingLevel() { 93 setLoggingLevel(getLoggingLevel() + 1); 94 } 95 96 97 98 99 103 public void println() { 104 println(""); 105 } 106 107 108 112 public void println(String msg) { 113 log(msg); 114 } 115 116 117 121 public void print(String msg) { 122 log(NORMAL, msg, false); 123 } 124 125 126 130 public void log(String msg) { 131 log(NORMAL, msg); 132 } 133 134 135 140 public void log(int level, String msg) { 141 log(level, msg, true); 142 } 143 144 145 151 public void log(int level, String msg, boolean lineFeed) { 152 if (getLoggingLevel() >= level) { 153 if (level > 0) { 154 if (level > whitespaces.length()) { 155 level = whitespaces.length(); 156 } 157 System.out.print(whitespaces.substring(0, level)); 158 } 159 if (lineFeed) { 160 System.out.println(msg); 161 } else { 162 System.out.print(msg); 163 } 164 } 165 } 166 167 168 169 170 173 public void printStackTrace(Exception ex) { 174 180 ex.printStackTrace(); 181 } 182 } 183 | Popular Tags |