20
21
public abstract class EcologiaIO
23
public static boolean verbose = false;
22
24
public static boolean debugging = false;
23
public static boolean verbose = false;
25
public static boolean analysing = false;
24
26
public static boolean logging = false;
26
28
public final static int CONTINUABLE_ERROR = 0;
27
29
public final static int BREAK_ERROR = 1;
28
30
public final static int FATAL_ERROR = 2;
33
* Print a log message if the verbose flag is set.
34
* This is meant to be used for important runtime events in the program,
35
* and for fundamental (e.g. life and death) events during the simulation.
36
* For more detailed output, use either debug() or analysis().
40
public static void log(String message)
43
message = "LOG: "+message;
44
System.out.println(message);
45
if (logging) writeFile(message);
31
* Print a debug message if the debug flag is set
50
* Print a debug message if the debug flag is set.
51
* This is meant to be used to show that Ecologia is functioning
52
* properly when the --debug flag is set, as well as for temporary
53
* debug statements during development.
34
57
public static void debug(String message)
44
* Print a log message if the verbose flag is set
67
* Print an analysis message if the analysing flag is set.
68
* This is meant to be used for simulation data output relevant only to a
47
public static void log(String message)
73
public static void analysis(String message)
50
message = "LOG: "+message;
76
message = "ANALYSIS: "+message;
51
77
System.out.println(message);
52
78
if (logging) writeFile(message);
85
111
public static void error(String message, int errorType)
87
if (errorType == CONTINUABLE_ERROR) {
88
message = "ERROR: "+message;
90
else if (errorType == BREAK_ERROR) {
113
String logMessage = "ERROR: "+message;
114
if (errorType == BREAK_ERROR) {
91
115
World.getInstance().setRunning(false);
92
message = "ERROR: "+message+" - simulation paused";
116
logMessage = logMessage+" - simulation paused";
117
JOptionPane.showMessageDialog(null, message, "Error!",
118
JOptionPane.ERROR_MESSAGE);
94
120
else if (errorType == FATAL_ERROR) {
95
message = "ERROR: "+message+" - simulation will terminate";
121
logMessage = logMessage+" - simulation will terminate";
122
JOptionPane.showMessageDialog(null, message+"\nEcologia is shutting down.",
123
"Error!", JOptionPane.ERROR_MESSAGE);
97
System.out.println(message);
98
if (logging) writeFile(message);
99
// TODO Add a graphic warning of imminent shutdown
125
System.out.println(logMessage);
126
if (logging) writeFile(logMessage);
100
127
if (errorType == FATAL_ERROR) System.exit(0);
146
173
if (logging) EcologiaIO.debug("Logging ON");
147
174
else EcologiaIO.debug("Logging OFF");
148
if (EcologiaIO.debugging) EcologiaIO.debug("Debugging ON");
149
175
if (EcologiaIO.verbose) EcologiaIO.debug("Verbose ON");
150
176
else EcologiaIO.debug("Verbose OFF");
177
if (EcologiaIO.analysing) EcologiaIO.debug("Analysing ON");
178
else EcologiaIO.debug("Analysing OFF");
179
if (EcologiaIO.debugging) EcologiaIO.debug("Debugging ON");