Coverage report

| %line | %branch
--- | --- | ---
tsukuba_bunko.peko.Logger |
0% |
0% |

1 |  |
     /*
2 |  |
      * "Peko" Visual Novel System
3 |  |
      *
4 |  |
      * All Rights Reserved.
5 |  |
      * Copyright (c) 1999-2003 Tsukuba Bunko.
6 |  |
      *
7 |  |
      * $Id: Logger.java,v 1.2 2005/07/11 14:07:31 ppoi Exp $
8 |  |
      */
9 |  |
     package tsukuba_bunko.peko;
10 |  |
11 |  |
     import	java.io.File;
12 |  |
13 |  |
     import	java.util.Properties;
14 |  |
15 |  |
     import	javax.swing.JOptionPane;
16 |  |
17 |  |
     import	org.apache.log4j.BasicConfigurator;
18 |  |
     import	org.apache.log4j.PropertyConfigurator;
19 |  |
     import	org.apache.log4j.LogManager;
20 |  |
     import	org.apache.log4j.Priority;
21 |  |
22 |  |
     import	tsukuba_bunko.util.ResourceLocator;
23 |  |
24 |  |
25 |  |
     /**
26 |  |
      * "Peko" の各モジュールに対しロギングの機能を提供します。
27 |  |
      * @author	$Author: ppoi $
28 |  |
      * @version	$Revision: 1.2 $
29 |  |
      */
30 |  |
     public class Logger	{
31 |  |
32 |  |
     	/**
33 |  |
     	 * ログ
34 |  |
     	 */
35 | 0 |
     	private static	org.apache.log4j.Logger	_logger = null;
36 |  |
37 |  |
38 |  |
     	/**
39 |  |
     	 * <code>Logger</code> のインスタンスを作成します。
40 |  |
     	 */
41 |  |
     	public Logger()
42 |  |
     	{
43 | 0 |
     		super();
44 | 0 |
     	}
45 |  |
46 |  |
47 |  |
     	/**
48 |  |
     	 * ログシステムを初期化します。このメソッドは、PekoSystem が初期化時に一度だけ呼び出します。
49 |  |
     	 * それ以外のクラス、状態でのメソッド呼び出しは禁止します。
50 |  |
     	 */
51 |  |
     	public static void prepare()
52 |  |
     	{
53 | 0 |
     		LogManager.resetConfiguration();
54 |  |
     		try	{
55 | 0 |
     			Properties	props = new Properties();
56 | 0 |
     			props.load( Logger.class.getResourceAsStream("log4j.properties") );
57 |  |
58 | 0 |
     			ResourceLocator	locator = ResourceLocator.newInstance();
59 | 0 |
     			File	base = locator.findLocation( "tsukuba_bunko/peko/PekoSystem.class" );
60 | 0 |
     			if( base.isFile() )	{
61 | 0 |
     				base = base.getParentFile();
62 |  |
     			}
63 |  |
64 | 0 |
     			props.setProperty( "log4j.appender.file.File", base.getAbsolutePath() + File.separator + "pvns.log" );
65 | 0 |
     			String	debug = System.getProperty( "pvns.debug", "off" ).toLowerCase();
66 | 0 |
     			if( "on".equals(debug) || "yes".equals(debug) || "true".equals(debug) )	{
67 | 0 |
     				props.setProperty( "log4j.rootLogger", "DEBUG, file" );
68 | 0 |
     			}
69 |  |
     			else	{
70 | 0 |
     				props.setProperty( "log4j.rootLogger", "INFO, file" );
71 |  |
     			}
72 |  |
73 | 0 |
     			PropertyConfigurator.configure( props );
74 |  |
     		}
75 | 0 |
     		catch( Exception e )	{
76 | 0 |
     			BasicConfigurator.configure();
77 | 0 |
     		}
78 | 0 |
     		_logger = LogManager.getLogger( "peko" );
79 | 0 |
     		_logger.info( "[logging] start logging." );
80 | 0 |
     	}
81 |  |
82 |  |
83 |  |
     	/**
84 |  |
     	 */
85 |  |
     	public static final void debug( String message )
86 |  |
     	{
87 | 0 |
     		_logger.debug( message );
88 | 0 |
     	}
89 |  |
90 |  |
     	/**
91 |  |
     	 */
92 |  |
     	public static final void debug( String message, Throwable e )
93 |  |
     	{
94 | 0 |
     		_logger.debug( message, e );
95 | 0 |
     	}
96 |  |
97 |  |
     	/**
98 |  |
     	 */
99 |  |
     	public static final void info( String message )
100 |  |
     	{
101 | 0 |
     		_logger.info( message );
102 | 0 |
     	}
103 |  |
104 |  |
     	public static final void info( String message, Throwable e )
105 |  |
     	{
106 | 0 |
     		_logger.info( message, e );
107 | 0 |
     	}
108 |  |
109 |  |
     	public static final void warn( String message )
110 |  |
     	{
111 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
112 | 0 |
     			_logger.warn( message );
113 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
114 |  |
     		}
115 | 0 |
     	}
116 |  |
117 |  |
     	public static final void warn( String message, Throwable e )
118 |  |
     	{
119 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
120 | 0 |
     			_logger.warn( message, e );
121 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
122 |  |
     		}
123 | 0 |
     	}
124 |  |
125 |  |
     	public static final void warn( MessageID messageID )
126 |  |
     	{
127 | 0 |
     		String	message = messageID.getMessage();
128 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
129 | 0 |
     			_logger.warn( message );
130 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
131 |  |
     		}
132 | 0 |
     	}
133 |  |
134 |  |
     	public static final void warn( MessageID messageID, Object[] params )
135 |  |
     	{
136 | 0 |
     		String	message = messageID.getMessage( params );
137 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
138 | 0 |
     			_logger.warn( message );
139 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
140 |  |
     		}
141 | 0 |
     	}
142 |  |
143 |  |
     	public static final void warn( MessageID messageID, Throwable e )
144 |  |
     	{
145 | 0 |
     		String	message = messageID.getMessage();
146 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
147 | 0 |
     			_logger.warn( message, e );
148 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
149 |  |
     		}
150 | 0 |
     	}
151 |  |
152 |  |
     	public static final void warn( MessageID messageID, Object[] params, Throwable e )
153 |  |
     	{
154 | 0 |
     		String	message = messageID.getMessage( params );
155 | 0 |
     		if( _logger.isEnabledFor(Priority.WARN) )	{
156 | 0 |
     			_logger.warn( message, e );
157 | 0 |
     			JOptionPane.showMessageDialog( null, message, "WARNING", JOptionPane.WARNING_MESSAGE );
158 |  |
     		}
159 | 0 |
     	}
160 |  |
161 |  |
     	public static final void error( String message )
162 |  |
     	{
163 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
164 | 0 |
     			_logger.error( message );
165 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
166 |  |
     		}
167 | 0 |
     	}
168 |  |
169 |  |
     	public static final void error( String message, Throwable e )
170 |  |
     	{
171 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
172 | 0 |
     			_logger.error( message, e );
173 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
174 |  |
     		}
175 | 0 |
     	}
176 |  |
177 |  |
     	public static final void error( MessageID messageID )
178 |  |
     	{
179 | 0 |
     		String	message = messageID.getMessage();
180 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
181 | 0 |
     			_logger.error( message );
182 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
183 |  |
     		}
184 | 0 |
     	}
185 |  |
186 |  |
     	public static final void error( MessageID messageID, Object[] params )
187 |  |
     	{
188 | 0 |
     		String	message = messageID.getMessage( params );
189 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
190 | 0 |
     			_logger.error( message );
191 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
192 |  |
     		}
193 | 0 |
     	}
194 |  |
195 |  |
     	public static final void error( MessageID messageID, Throwable e )
196 |  |
     	{
197 | 0 |
     		String	message = messageID.getMessage();
198 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
199 | 0 |
     			_logger.error( message, e );
200 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
201 |  |
     		}
202 | 0 |
     	}
203 |  |
204 |  |
     	public static final void error( MessageID messageID, Object[] params, Throwable e )
205 |  |
     	{
206 | 0 |
     		String	message = messageID.getMessage( params );
207 | 0 |
     		if( _logger.isEnabledFor(Priority.ERROR) )	{
208 | 0 |
     			_logger.error( message, e );
209 | 0 |
     			JOptionPane.showMessageDialog( null, message, "ERROR", JOptionPane.ERROR_MESSAGE );
210 |  |
     		}
211 | 0 |
     	}
212 |  |
213 |  |
     	public static final void fatal( String message )
214 |  |
     	{
215 | 0 |
     		_logger.fatal( message );
216 | 0 |
     	}
217 |  |
218 |  |
     	public static final void fatal( String message, Throwable e )
219 |  |
     	{
220 | 0 |
     		_logger.fatal( message, e );
221 | 0 |
     	}
222 |  |
223 |  |
     	public static final void fatal( MessageID messageID )
224 |  |
     	{
225 | 0 |
     		_logger.fatal( messageID.getMessage() );
226 | 0 |
     	}
227 |  |
228 |  |
     	public static final void fatal( MessageID messageID, Object[] params )
229 |  |
     	{
230 | 0 |
     		_logger.fatal( messageID.getMessage(params) );
231 | 0 |
     	}
232 |  |
233 |  |
     	public static final void fatal( MessageID messageID, Throwable e )
234 |  |
     	{
235 | 0 |
     		_logger.fatal( messageID.getMessage(), e );
236 | 0 |
     	}
237 |  |
238 |  |
     	public static final void fatal( MessageID messageID, Object[] params, Throwable e )
239 |  |
     	{
240 | 0 |
     		_logger.fatal( messageID.getMessage(params), e );
241 | 0 |
     	}
242 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.