Last change
on this file since 21925 was 21925, checked in by sjm84, 14 years ago |
The logger now creates the log file if it does not exist
|
File size:
980 bytes
|
Line | |
---|
1 | package org.greenstone.admin;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 |
|
---|
5 | import javax.swing.JTextArea;
|
---|
6 |
|
---|
7 | import org.apache.log4j.Logger;
|
---|
8 | import org.apache.log4j.PropertyConfigurator;
|
---|
9 |
|
---|
10 | public class LoggedMessageArea extends JTextArea
|
---|
11 | {
|
---|
12 | Logger _logger = null;
|
---|
13 | boolean _loggingLoaded = false;
|
---|
14 |
|
---|
15 | public LoggedMessageArea(Class loggerClass)
|
---|
16 | {
|
---|
17 | if(!_loggingLoaded){
|
---|
18 | try{
|
---|
19 | File logPath = new File(".." + File.separatorChar + "ext" + File.separatorChar + "logs");
|
---|
20 | File logFile = new File(".." + File.separatorChar + "ext" + File.separatorChar + "logs" + File.separatorChar + "ext.log");
|
---|
21 |
|
---|
22 | if(!logPath.exists()){
|
---|
23 | logPath.mkdirs();
|
---|
24 | }
|
---|
25 |
|
---|
26 | if(!logFile.exists()){
|
---|
27 | logFile.createNewFile();
|
---|
28 | }
|
---|
29 | }
|
---|
30 | catch(Exception ex){
|
---|
31 | ex.printStackTrace();
|
---|
32 | }
|
---|
33 | PropertyConfigurator.configure("log4j.properties");
|
---|
34 | _loggingLoaded = true;
|
---|
35 | }
|
---|
36 | _logger = Logger.getLogger(loggerClass);
|
---|
37 | }
|
---|
38 |
|
---|
39 | public void append(String s)
|
---|
40 | {
|
---|
41 | super.append(s);
|
---|
42 | _logger.info(s);
|
---|
43 | }
|
---|
44 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.