source: osm/applications/editors/josm/plugins/slippy_map_chooser/src/Logger.java@ 7199

Last change on this file since 7199 was 7199, checked in by tim, 17 years ago

Initial import of slippy_map_chooser source version 1.1

File size: 1.3 KB
Line 
1// License: GPL. Copyright 2007 by Tim Haussmann
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.io.FileOutputStream;
6import java.io.IOException;
7
8
9/**
10 *
11 * @author Tim Haussmann
12 */
13
14public class Logger {
15
16 private static Logger iSelf;
17
18 private File iLogFile;
19 private FileOutputStream iFout;
20
21 private Logger(String aLogFilePath){
22 if(aLogFilePath != null && !aLogFilePath.equals(""))
23 iLogFile = new File(aLogFilePath);
24 else
25 iLogFile = new File("c:/LogFile.txt");
26
27 try {
28 iFout = new FileOutputStream(iLogFile, false);
29 } catch (FileNotFoundException e) {
30 e.printStackTrace();
31 }
32 }
33
34 public static void log(String aMessage){
35 if(iSelf == null)
36 iSelf = new Logger(null);
37 iSelf.logMessage(aMessage);
38 }
39
40 public static void close(){
41 iSelf.saveLog();
42 iSelf = null;
43 }
44
45 private void saveLog() {
46 try {
47 iFout.flush();
48 iFout.close();
49 } catch (IOException e) {
50 e.printStackTrace();
51 }
52 }
53
54 public static void setLogFile(String aLogFilePath){
55 iSelf = new Logger(aLogFilePath);
56 }
57
58 private void logMessage(String aMessage){
59 try {
60 iFout.write((aMessage + "\n").getBytes());
61 iFout.flush();
62 } catch (IOException e) {
63 e.printStackTrace();
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.