@@ -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,47 @@ 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" );
153
-
154
- wirteFile (log4jFile .getAbsolutePath (), "utf-8" , sb .toString ());
140
+ String logTemplate = "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n " +
141
+ "<Configuration status=\" INFO\" >\n " +
142
+ " <properties>\n " +
143
+ " <property name=\" LOG_PATH\" >{{LOG_PATH}}</property>\n " +
144
+ " </properties>\n " +
145
+ " <Appenders>\n " +
146
+ " <Console name=\" Console\" target=\" SYSTEM_OUT\" >\n " +
147
+ " <PatternLayout pattern=\" %c-%-4r %-5p [%d{yyyy-MM-dd HH:mm:ss}] %m%n\" />\n " +
148
+ " </Console>\n " +
149
+ " <RollingRandomAccessFile name=\" File\" \n " +
150
+ " fileName=\" ${LOG_PATH}\" filePattern=\" ${LOG_PATH}.-%d{yyyyMMddHHmm}-%i\" >\n " +
151
+ " <PatternLayout pattern=\" %d{HH:mm:ss} %c{1} %-5p %m%n\" />\n " +
152
+ " <Policies>\n " +
153
+ " <TimeBasedTriggeringPolicy interval=\" 10\" />\n " +
154
+ " <SizeBasedTriggeringPolicy size=\" 1024 MB\" />\n " +
155
+ " </Policies>\n " +
156
+ " <DefaultRolloverStrategy max=\" 50\" />\n " +
157
+ " </RollingRandomAccessFile>\n " +
158
+ " </Appenders>\n " +
159
+ " <Loggers>\n " +
160
+ " <Root level=\" info\" >\n " +
161
+ " <AppenderRef ref=\" Console\" />\n " +
162
+ " <AppenderRef ref=\" File\" />\n " +
163
+ " </Root>\n " +
164
+ " </Loggers>\n " +
165
+ "</Configuration>\n " +
166
+ "" ;
167
+
168
+ wirteFile (log4jFile .getAbsolutePath (), "utf-8" , logTemplate .replace ("{{LOG_PATH}}" , logPath ));
155
169
156
170
}
157
171
@@ -236,7 +250,7 @@ private static void makeFiles(File JcoderHome, String logPath) throws FileNotFou
236
250
wirteFile (iocFile .getAbsolutePath (), "utf-8" , "var ioc = {\n \n };" );
237
251
}
238
252
239
- createLog4jConfig (new File (resourceDir , "log4j.properties " ), logPath );
253
+ createLog4j2Config (new File (resourceDir , "log4j2.xml " ), logPath );
240
254
}
241
255
242
256
/**
0 commit comments