@@ -20,7 +20,7 @@ public class Bootstrap {
20
20
private static final String PREFIX = "jcoder_" ;
21
21
22
22
public static void main (String [] args ) throws Exception {
23
-
23
+
24
24
for (String arg : args ) {
25
25
if (arg .startsWith ("-f" )) {
26
26
if (arg .contains ("=" )) {
@@ -84,8 +84,7 @@ public static void main(String[] args) throws Exception {
84
84
context .setContextPath ("/" );
85
85
context .setServer (server );
86
86
context .setMaxFormContentSize (0 );
87
- context .setServerClasses (new String [] {
88
- "org.objectweb.asm." , // hide asm used by jetty
87
+ context .setServerClasses (new String [] { "org.objectweb.asm." , // hide asm used by jetty
89
88
"org.eclipse.jdt." , // hide jdt used by jetty
90
89
"-org.eclipse.jetty." // hide other jetty classes
91
90
});
@@ -126,32 +125,30 @@ public static void main(String[] args) throws Exception {
126
125
}
127
126
128
127
/**
129
- * config log4j setting
128
+ * config log4j2 setting
130
129
*
131
130
* @param logPath
132
131
* @throws IOException
133
132
* @throws FileNotFoundException
134
133
*/
135
- private static void createLog4jConfig (File log4jFile , String logPath ) throws FileNotFoundException , IOException {
134
+ private static void createLog4j2Config (File log4jFile , String logPath ) throws FileNotFoundException , IOException {
136
135
137
136
if (log4jFile .exists ()) {
138
137
return ;
139
138
}
140
139
141
- StringBuilder sb = new StringBuilder ();
142
-
143
- sb .append ("log4j.rootLogger=info, stdout,R\n " + "log4j.appender.stdout.Encoding=utf-8\n " + "log4j.appender.R.Encoding=utf-8\n "
144
- + "log4j.appender.stdout=org.apache.log4j.ConsoleAppender\n " + "log4j.appender.stdout.layout=org.apache.log4j.PatternLayout \n "
145
- + "log4j.appender.stdout.layout.ConversionPattern=%c-%-4r %-5p [%d{yyyy-MM-dd HH:mm:ss}] %m%n\n " + "\n "
146
- + "log4j.appender.R=org.apache.log4j.DailyRollingFileAppender\n " + "log4j.appender.R.File=" );
147
-
148
- sb .append (logPath );
149
-
150
- sb .append ("\n " + "log4j.appender.R.DatePattern = '.'yyyy-MM-dd\n " + "log4j.appender.R.layout=org.apache.log4j.PatternLayout\n "
151
- + "log4j.appender.R.layout.ConversionPattern=%d{HH:mm:ss} %c{1} %-5p %m%n\n " + "\n " + "## Disable other log \n "
152
- + "log4j.logger.org.atmosphere.cpr.AsynchronousProcessor=FATAL" );
140
+ String logTemplate = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n " + "<Configuration status=\" INFO\" >\n " + " <properties>\n "
141
+ + " <property name=\" LOG_PATH\" >{{LOG_PATH}}</property>\n " + " </properties>\n " + " <Appenders>\n "
142
+ + " <Console name=\" Console\" target=\" SYSTEM_OUT\" >\n " + " <PatternLayout pattern=\" %c-%-4r %-5p [%d{yyyy-MM-dd HH:mm:ss}] %m%n\" />\n "
143
+ + " </Console>\n " + " <RollingRandomAccessFile name=\" File\" \n "
144
+ + " fileName=\" ${LOG_PATH}\" filePattern=\" ${LOG_PATH}.-%d{yyyyMMddHHmm}-%i\" >\n "
145
+ + " <PatternLayout pattern=\" %d{HH:mm:ss} %c{1} %-5p %m%n\" />\n " + " <Policies>\n "
146
+ + " <TimeBasedTriggeringPolicy interval=\" 10\" />\n " + " <SizeBasedTriggeringPolicy size=\" 1024 MB\" />\n " + " </Policies>\n "
147
+ + " <DefaultRolloverStrategy max=\" 50\" />\n " + " </RollingRandomAccessFile>\n " + " </Appenders>\n " + " <Loggers>\n "
148
+ + " <Root level=\" info\" >\n " + " <AppenderRef ref=\" Console\" />\n " + " <AppenderRef ref=\" File\" />\n " + " </Root>\n "
149
+ + " </Loggers>\n " + "</Configuration>\n " + "" ;
153
150
154
- wirteFile (log4jFile .getAbsolutePath (), "utf-8" , sb . toString ( ));
151
+ wirteFile (log4jFile .getAbsolutePath (), "utf-8" , logTemplate . replace ( "{{LOG_PATH}}" , logPath ));
155
152
156
153
}
157
154
@@ -236,7 +233,7 @@ private static void makeFiles(File JcoderHome, String logPath) throws FileNotFou
236
233
wirteFile (iocFile .getAbsolutePath (), "utf-8" , "var ioc = {\n \n };" );
237
234
}
238
235
239
- createLog4jConfig (new File (resourceDir , "log4j.properties " ), logPath );
236
+ createLog4j2Config (new File (resourceDir , "log4j2.xml " ), logPath );
240
237
}
241
238
242
239
/**
0 commit comments