36 |
import org.apache.log4j.Level; |
import org.apache.log4j.Level; |
37 |
import org.apache.log4j.PropertyConfigurator; |
import org.apache.log4j.PropertyConfigurator; |
38 |
import org.apache.log4j.BasicConfigurator; |
import org.apache.log4j.BasicConfigurator; |
39 |
|
import org.apache.log4j.lf5.LogLevelFormatException; |
40 |
|
|
41 |
|
/* |
42 |
|
* A simulator for Storm |
43 |
|
*/ |
44 |
|
|
45 |
public class StormSimulator implements Runnable{ |
public class StormSimulator implements Runnable{ |
46 |
|
|
47 |
|
static private void p(String s) { System.out.println(s); } |
48 |
|
|
49 |
private static final Logger LOG = |
private static final Logger LOG = |
50 |
Logger.getLogger(StormSimulator.class.getName()); |
Logger.getLogger(StormSimulator.class.getName()); |
51 |
|
|
52 |
|
|
53 |
public StormSimulator() { |
public StormSimulator(String[] args) { |
54 |
|
|
55 |
|
if (new File("log4j.properties").isFile()) { |
56 |
|
PropertyConfigurator.configure("log4j.properties"); |
57 |
|
} else { |
58 |
|
BasicConfigurator.configure(); |
59 |
|
if(args != null) setLogLevel(args[0]); |
60 |
|
} |
61 |
|
|
62 |
Thread thread = new Thread(this); |
Thread thread = new Thread(this); |
63 |
thread.setPriority(Thread.NORM_PRIORITY); |
thread.setPriority(Thread.NORM_PRIORITY); |
64 |
thread.start(); |
thread.start(); |
65 |
} |
} |
66 |
|
|
67 |
|
private void setLogLevel(String level) { |
68 |
|
if (level == "ALL") { |
69 |
|
LOG.setLevel(Level.ALL); |
70 |
|
LOG.info("Setting logging level to: ALL"); |
71 |
|
} else if (level == "DEBUG") { |
72 |
|
LOG.setLevel(Level.DEBUG); |
73 |
|
LOG.info("Setting logging level to: DEBUG"); |
74 |
|
} else if (level == "ERROR") { |
75 |
|
LOG.setLevel(Level.ERROR); |
76 |
|
LOG.info("Setting logging level to: ERROR"); |
77 |
|
} else if (level == "FATAL") { |
78 |
|
LOG.setLevel(Level.FATAL); |
79 |
|
LOG.info("Setting logging level to: FATAL"); |
80 |
|
} else if (level == "INFO") { |
81 |
|
LOG.setLevel(Level.INFO); |
82 |
|
LOG.info("Setting logging level to: INFO"); |
83 |
|
} else if (level == "WARN") { |
84 |
|
LOG.setLevel(Level.WARN); |
85 |
|
LOG.info("Setting logging level to: WARN"); |
86 |
|
} else if (level == "OFF") { |
87 |
|
LOG.setLevel(Level.OFF); |
88 |
|
LOG.info("Setting logging level to: OFF"); |
89 |
|
} else { |
90 |
|
LOG.setLevel(Level.DEBUG); |
91 |
|
LOG.info("Setting default logging level to: DEBUG"); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
public void run(){ |
public void run(){ |
96 |
|
|
98 |
|
|
99 |
} |
} |
100 |
|
|
101 |
public static void main(String[] args){ |
public String getLogLevel() { |
102 |
|
if (LOG.getLevel() != null) { |
103 |
if (new File("log4j.properties").isFile()) { |
return LOG.getLevel().toString(); |
|
PropertyConfigurator.configure("log4j.properties"); |
|
104 |
} else { |
} else { |
105 |
BasicConfigurator.configure(); |
return "null"; |
|
LOG.setLevel(Level.DEBUG); |
|
106 |
} |
} |
|
|
|
|
new StormSimulator(); |
|
107 |
} |
} |
108 |
|
|
109 |
|
public static void main(String[] args){ |
110 |
|
new StormSimulator(args); |
111 |
|
} |
112 |
|
|
113 |
} |
} |