OSDN Git Service

パッケージ変更
[chemicraft/ChemiCraftNext.git] / src / asia / tcrs / ccnp / chemicraftnext / ChemiCraftLogging.java
1 package asia.tcrs.ccnp.chemicraftnext;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.FileWriter;
6 import java.io.IOException;
7
8 public class ChemiCraftLogging {
9
10         private FileWriter outStream;
11         private String directoryPath;
12         private File file;
13
14         public ChemiCraftLogging(String directoryPath) {
15                 this.directoryPath = directoryPath;
16         }
17
18         public void startLogging() {
19                 this.file = new File(this.directoryPath + "/ChemiCraft.log");
20                 if (!this.file.exists()) {
21                         try {
22                                 this.file.createNewFile();
23                         } catch (IOException e) {
24                                 e.printStackTrace();
25                         }
26                 }
27
28                 try {
29                         this.outStream = new FileWriter(this.file);
30                 } catch (FileNotFoundException e) {
31                         e.printStackTrace();
32                 } catch (IOException e) {
33                         e.printStackTrace();
34                 }
35         }
36
37         public void write(String writeStr) {
38                 String s = writeStr;
39                 try {
40                         this.outStream.write(writeStr);
41                 } catch (IOException e) {
42                         e.printStackTrace();
43                 }
44         }
45
46         public void write(String writeStr, EnumLoggingType type) {
47                 String s = writeStr;
48                 switch (type) {
49                 case NORMAL:
50                         break;
51                 case ERROR:
52                         s = "[Error]" + s;
53                         break;
54                 case WARNING:
55                         s = "[Warning]" + s;
56                         break;
57                 case INFO:
58                         s = "[Info]" + s;
59                         break;
60                 default:
61                         throw new IllegalStateException();
62                 }
63                 try {
64                         this.outStream.write(s + "\n");
65                         this.outStream.flush();
66                 } catch (IOException e) {
67                         e.printStackTrace();
68                 }
69         }
70
71 }