diff --git a/tests/examples/JDBC/JDBCDemo/.gitignore b/tests/examples/JDBC/JDBCDemo/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d587e5fe38efd731e74c77f1ec4d68d7363117bd --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/.gitignore @@ -0,0 +1,2 @@ +out/ +logs/ diff --git a/tests/examples/JDBC/JDBCDemo/pom.xml b/tests/examples/JDBC/JDBCDemo/pom.xml index 92d757edfdea304084b5971613da231db2b9daef..f3a31d08a026db8cf8fc841ef8a439dba781b643 100644 --- a/tests/examples/JDBC/JDBCDemo/pom.xml +++ b/tests/examples/JDBC/JDBCDemo/pom.xml @@ -63,7 +63,12 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.4 + 2.0.6 + + + log4j + log4j + 1.2.17 diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcTaosdemo.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcTaosdemo.java new file mode 100644 index 0000000000000000000000000000000000000000..461a639682c4cb3cd7bf363b1e57b9f5de4ae6c0 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/JdbcTaosdemo.java @@ -0,0 +1,285 @@ +package com.taosdata.example; + +import com.taosdata.example.domain.JdbcTaosdemoConfig; +import com.taosdata.example.task.CreateTableTask; +import com.taosdata.example.task.InsertTableDatetimeTask; +import com.taosdata.example.task.InsertTableTask; +import com.taosdata.example.utils.TimeStampUtil; +import com.taosdata.jdbc.TSDBDriver; +import org.apache.log4j.Logger; + +import java.sql.*; +import java.util.*; +import java.util.concurrent.atomic.AtomicLong; + +public class JdbcTaosdemo { + + private static Logger logger = Logger.getLogger(JdbcTaosdemo.class); + private static AtomicLong beginTimestamp = new AtomicLong(TimeStampUtil.datetimeToLong("2005-01-01 00:00:00.000")); + private final JdbcTaosdemoConfig config; + private Connection connection; + private static final String[] locations = {"Beijing", "Shanghai", "Guangzhou", "Shenzhen", "HangZhou", "Tianjin", "Wuhan", "Changsha", "Nanjing", "Xian"}; + private static Random random = new Random(System.currentTimeMillis()); + + public JdbcTaosdemo(JdbcTaosdemoConfig config) { + this.config = config; + } + + private static void printHelp() { + System.out.println("Usage: java -jar JDBCConnectorChecker.jar -h host [OPTION...]"); + System.out.println("-p port The TCP/IP port number to use for the connection. Default is 6030"); + System.out.println("-u user The TDengine user name to use when connecting to the server. Default is 'root'"); + System.out.println("-P password The password to use when connecting to the server.Default is 'taosdata'"); + System.out.println("-d database Destination database. Default is 'test'"); + System.out.println("-m tablePrefix Table prefix name. Default is 'd'"); + System.out.println("-T num_of_threads The number of threads. Default is 10"); + System.out.println("-t num_of_tables The number of tables. Default is 10000"); + System.out.println("-n num_of_records_per_table The number of records per table. Default is 100000"); + System.out.println("-D delete table Delete data methods. Default is false"); + System.out.println("--help Give this help list"); + } + + public static void main(String[] args) { + JdbcTaosdemoConfig config = JdbcTaosdemoConfig.build(args); + + boolean isHelp = Arrays.asList(args).contains("--help"); + if (isHelp) { + printHelp(); + return; + } + if (config.getHost() == null) { + printHelp(); + return; + } + + boolean infinite = Arrays.asList().contains("--infinite"); + JdbcTaosdemo taosdemo = new JdbcTaosdemo(config); + taosdemo.init(); + taosdemo.dropDatabase(); + taosdemo.createDatabase(); + taosdemo.useDatabase(); + taosdemo.createSuperTable(); + taosdemo.createTableMultiThreads(); + if (infinite) { + taosdemo.insertInfinite(); + } else { + taosdemo.insertMultiThreads(); + taosdemo.countFromSuperTable(); + if (config.isDeleteTable()) + taosdemo.dropSuperTable(); + taosdemo.close(); + } + } + + + /** + * establish the connection + */ + private void init() { + try { + Class.forName("com.taosdata.jdbc.TSDBDriver"); + connection = getConnection(config); + if (connection != null) + logger.info("[ OK ] Connection established."); + } catch (ClassNotFoundException | SQLException e) { + logger.error(e.getMessage()); + throw new RuntimeException("connection failed: " + config.getHost()); + } + } + + public static Connection getConnection(JdbcTaosdemoConfig config) throws SQLException { + Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, config.getHost()); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, config.getUser()); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, config.getPassword()); + properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + return DriverManager.getConnection("jdbc:TAOS://" + config.getHost() + ":" + config.getPort() + "/" + config.getDbName() + "", properties); + } + + /** + * create database + */ + private void createDatabase() { + String sql = "create database if not exists " + config.getDbName() + " keep " + config.getKeep() + " days " + config.getDays(); + execute(sql); + } + + private void dropDatabase() { + String sql = "drop database if exists " + config.getDbName(); + execute(sql); + } + + /** + * use database + */ + private void useDatabase() { + String sql = "use " + config.getDbName(); + execute(sql); + } + + private void createSuperTable() { + String sql = "create table if not exists " + config.getStbName() + "(ts timestamp, current float, voltage int, phase float) tags(location binary(64), groupId int)"; + execute(sql); + } + + /** + * create table use super table with multi threads + */ + private void createTableMultiThreads() { + try { + final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads(); + List threads = new ArrayList<>(); + for (int i = 0; i < config.getNumberOfThreads(); i++) { + Thread thread = new Thread(new CreateTableTask(config, i * tableSize, tableSize), "Thread-" + i); + threads.add(thread); + thread.start(); + } + for (Thread thread : threads) { + thread.join(); + } + logger.info(">>> Multi Threads create table finished."); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + private void insertInfinite() { + try { + final long startDatetime = TimeStampUtil.datetimeToLong("2005-01-01 00:00:00.000"); + final long finishDatetime = TimeStampUtil.datetimeToLong("2030-01-01 00:00:00.000"); + + final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads(); + List threads = new ArrayList<>(); + for (int i = 0; i < config.getNumberOfThreads(); i++) { + Thread thread = new Thread(new InsertTableDatetimeTask(config, i * tableSize, tableSize, startDatetime, finishDatetime), "Thread-" + i); + threads.add(thread); + thread.start(); + } + for (Thread thread : threads) { + thread.join(); + } + logger.info(">>> Multi Threads insert table finished."); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + private void insertMultiThreads() { + try { + final int tableSize = config.getNumberOfTable() / config.getNumberOfThreads(); + final int numberOfRecordsPerTable = config.getNumberOfRecordsPerTable(); + List threads = new ArrayList<>(); + for (int i = 0; i < config.getNumberOfThreads(); i++) { + Thread thread = new Thread(new InsertTableTask(config, i * tableSize, tableSize, numberOfRecordsPerTable), "Thread-" + i); + threads.add(thread); + thread.start(); + } + for (Thread thread : threads) { + thread.join(); + } + logger.info(">>> Multi Threads insert table finished."); + } catch (InterruptedException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + public static String insertSql(int tableIndex, JdbcTaosdemoConfig config) { + float current = 10 + random.nextFloat(); + int voltage = 200 + random.nextInt(20); + float phase = random.nextFloat(); + String sql = "insert into " + config.getDbName() + "." + config.getTbPrefix() + "" + tableIndex + " " + + "values(" + beginTimestamp.getAndIncrement() + ", " + current + ", " + voltage + ", " + phase + ") "; + return sql; + } + + public static String insertSql(int tableIndex, long ts, JdbcTaosdemoConfig config) { + float current = 10 + random.nextFloat(); + int voltage = 200 + random.nextInt(20); + float phase = random.nextFloat(); + String sql = "insert into " + config.getDbName() + "." + config.getTbPrefix() + "" + tableIndex + " " + + "values(" + ts + ", " + current + ", " + voltage + ", " + phase + ") "; + return sql; + } + + + public static String createTableSql(int tableIndex, JdbcTaosdemoConfig config) { + String location = locations[random.nextInt(locations.length)]; + return "create table d" + tableIndex + " using " + config.getDbName() + "." + config.getStbName() + " tags('" + location + "'," + tableIndex + ")"; + } + + private void countFromSuperTable() { + String sql = "select count(*) from " + config.getDbName() + "." + config.getStbName(); + executeQuery(sql); + } + + private void close() { + try { + if (connection != null) { + this.connection.close(); + logger.info("connection closed."); + } + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + /** + * drop super table + */ + private void dropSuperTable() { + String sql = "drop table if exists " + config.getDbName() + "." + config.getStbName(); + execute(sql); + } + + /** + * execute sql, use this method when sql is create, alter, drop.. + */ + private void execute(String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + boolean execute = statement.execute(sql); + long end = System.currentTimeMillis(); + printSql(sql, execute, (end - start)); + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + private void printSql(String sql, boolean succeed, long cost) { + logger.info("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql); + } + + private void executeQuery(String sql) { + try (Statement statement = connection.createStatement()) { + long start = System.currentTimeMillis(); + ResultSet resultSet = statement.executeQuery(sql); + long end = System.currentTimeMillis(); + printSql(sql, true, (end - start)); + printResult(resultSet); + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } + + private void printResult(ResultSet resultSet) throws SQLException { + ResultSetMetaData metaData = resultSet.getMetaData(); + while (resultSet.next()) { + StringBuilder sb = new StringBuilder(); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String columnLabel = metaData.getColumnLabel(i); + String value = resultSet.getString(i); + sb.append(columnLabel + ": " + value + "\t"); + } + logger.info(sb.toString()); + } + } + +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/domain/JdbcTaosdemoConfig.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/domain/JdbcTaosdemoConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..efaddbfa0d8124bfeb83e627db56a008db4a0d81 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/domain/JdbcTaosdemoConfig.java @@ -0,0 +1,183 @@ +package com.taosdata.example.domain; + +public class JdbcTaosdemoConfig { + + //The host to connect to TDengine. Must insert one + private String host; + //The TCP/IP port number to use for the connection. Default is 6030. + private int port = 6030; + //The TDengine user name to use when connecting to the server. Default is 'root' + private String user = "root"; + //The password to use when connecting to the server. Default is 'taosdata' + private String password = "taosdata"; + //Destination database. Default is 'test' + private String dbName = "test"; + + // + private int keep = 365 * 20; + + private int days = 30; + + //Super table Name. Default is 'meters' + private String stbName = "meters"; + + + //Table name prefix. Default is 'd' + private String tbPrefix = "d"; + //The number of threads. Default is 10. + private int numberOfThreads = 10; + //The number of tables. Default is 10000. + private int numberOfTable = 10000; + //The number of records per table. Default is 100000 + private int numberOfRecordsPerTable = 100000; + //Delete data. Default is false + private boolean deleteTable = true; + + /** + * parse args from command line + * + * @param args command line args + * @return JdbcTaosdemoConfig + */ + public static JdbcTaosdemoConfig build(String[] args) { + JdbcTaosdemoConfig config = new JdbcTaosdemoConfig(); + for (int i = 0; i < args.length; i++) { + if ("-h".equals(args[i]) && i < args.length - 1) { + config.setHost(args[++i]); + } + if ("-p".equals(args[i]) && i < args.length - 1) { + config.setPort(Integer.parseInt(args[++i])); + } + if ("-u".equals(args[i]) && i < args.length - 1) { + config.setUser(args[++i]); + } + if ("-P".equals(args[i]) && i < args.length - 1) { + config.setPassword(args[++i]); + } + if ("-d".equals(args[i]) && i < args.length - 1) { + config.setDbName(args[++i]); + } + if ("-m".equals(args[i]) && i < args.length - 1) { + config.setTbPrefix(args[++i]); + } + if ("-T".equals(args[i]) && i < args.length - 1) { + config.setNumberOfThreads(Integer.parseInt(args[++i])); + } + if ("-t".equals(args[i]) && i < args.length - 1) { + config.setNumberOfTable(Integer.parseInt(args[++i])); + } + if ("-n".equals(args[i]) && i < args.length - 1) { + config.setNumberOfRecordsPerTable(Integer.parseInt(args[++i])); + } + if ("-D".equals(args[i]) && i < args.length - 1) { + config.setDeleteTable(Boolean.parseBoolean(args[++i])); + } + + } + return config; + } + + public void setHost(String host) { + this.host = host; + } + + public String getHost() { + return host; + } + + public String getDbName() { + return dbName; + } + + public void setDbName(String dbName) { + this.dbName = dbName; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getStbName() { + return stbName; + } + + public void setStbName(String stbName) { + this.stbName = stbName; + } + + public String getTbPrefix() { + return tbPrefix; + } + + public void setTbPrefix(String tbPrefix) { + this.tbPrefix = tbPrefix; + } + + public int getNumberOfThreads() { + return numberOfThreads; + } + + public void setNumberOfThreads(int numberOfThreads) { + this.numberOfThreads = numberOfThreads; + } + + public int getNumberOfTable() { + return numberOfTable; + } + + public void setNumberOfTable(int numberOfTable) { + this.numberOfTable = numberOfTable; + } + + public int getNumberOfRecordsPerTable() { + return numberOfRecordsPerTable; + } + + public void setNumberOfRecordsPerTable(int numberOfRecordsPerTable) { + this.numberOfRecordsPerTable = numberOfRecordsPerTable; + } + + public boolean isDeleteTable() { + return deleteTable; + } + + public void setDeleteTable(boolean deleteTable) { + this.deleteTable = deleteTable; + } + + public int getKeep() { + return keep; + } + + public void setKeep(int keep) { + this.keep = keep; + } + + public int getDays() { + return days; + } + + public void setDays(int days) { + this.days = days; + } +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/CreateTableTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/CreateTableTask.java new file mode 100644 index 0000000000000000000000000000000000000000..167dbdb648a3b6e42c4601884d0418dc6e5c27ea --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/CreateTableTask.java @@ -0,0 +1,44 @@ +package com.taosdata.example.task; + +import com.taosdata.example.JdbcTaosdemo; +import com.taosdata.example.domain.JdbcTaosdemoConfig; +import org.apache.log4j.Logger; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +public class CreateTableTask implements Runnable { + + private static Logger logger = Logger.getLogger(CreateTableTask.class); + private final JdbcTaosdemoConfig config; + private final int startIndex; + private final int tableNumber; + + public CreateTableTask(JdbcTaosdemoConfig config, int startIndex, int tableNumber) { + this.config = config; + this.startIndex = startIndex; + this.tableNumber = tableNumber; + } + + @Override + public void run() { + try { + Connection connection = JdbcTaosdemo.getConnection(config); + for (int i = startIndex; i < startIndex + tableNumber; i++) { + Statement statement = connection.createStatement(); + String sql = JdbcTaosdemo.createTableSql(i + 1, config); +// long start = System.currentTimeMillis(); + boolean execute = statement.execute(sql); +// long end = System.currentTimeMillis(); +// printSql(sql, execute, (end - start)); + statement.close(); + logger.info(">>> " + sql); + } + connection.close(); + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableDatetimeTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableDatetimeTask.java new file mode 100644 index 0000000000000000000000000000000000000000..a54f73a25808aea212bb82a5c25e8f0e8359231b --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableDatetimeTask.java @@ -0,0 +1,47 @@ +package com.taosdata.example.task; + +import com.taosdata.example.JdbcTaosdemo; +import com.taosdata.example.domain.JdbcTaosdemoConfig; +import org.apache.log4j.Logger; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +public class InsertTableDatetimeTask implements Runnable { + private static Logger logger = Logger.getLogger(InsertTableDatetimeTask.class); + + private final JdbcTaosdemoConfig config; + private final int startTableIndex; + private final int tableNumber; + private final long startDatetime; + private final long finishedDatetime; + + public InsertTableDatetimeTask(JdbcTaosdemoConfig config, int startTableIndex, int tableNumber, long startDatetime, long finishedDatetime) { + this.config = config; + this.startTableIndex = startTableIndex; + this.tableNumber = tableNumber; + this.startDatetime = startDatetime; + this.finishedDatetime = finishedDatetime; + } + + @Override + public void run() { + try { + Connection connection = JdbcTaosdemo.getConnection(config); + for (long ts = startDatetime; ts < finishedDatetime; ts++) { + for (int i = startTableIndex; i < startTableIndex + tableNumber; i++) { + String sql = JdbcTaosdemo.insertSql(i + 1, ts, config); + Statement statement = connection.createStatement(); + statement.execute(sql); + statement.close(); + logger.info(Thread.currentThread().getName() + ">>> " + sql); + } + } + connection.close(); + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableTask.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableTask.java new file mode 100644 index 0000000000000000000000000000000000000000..88f65f739d8b3f2b7812e75500893cecc22fcb3a --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/task/InsertTableTask.java @@ -0,0 +1,45 @@ +package com.taosdata.example.task; + +import com.taosdata.example.JdbcTaosdemo; +import com.taosdata.example.domain.JdbcTaosdemoConfig; +import org.apache.log4j.Logger; + +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.Statement; + +public class InsertTableTask implements Runnable { + private static Logger logger = Logger.getLogger(InsertTableTask.class); + + private final JdbcTaosdemoConfig config; + private final int startIndex; + private final int tableNumber; + private final int recordsNumber; + + public InsertTableTask(JdbcTaosdemoConfig config, int startIndex, int tableNumber, int recordsNumber) { + this.config = config; + this.startIndex = startIndex; + this.tableNumber = tableNumber; + this.recordsNumber = recordsNumber; + } + + @Override + public void run() { + try { + Connection connection = JdbcTaosdemo.getConnection(config); + for (int i = startIndex; i < startIndex + tableNumber; i++) { + for (int j = 0; j < recordsNumber; j++) { + String sql = JdbcTaosdemo.insertSql(i + 1, config); + Statement statement = connection.createStatement(); + statement.execute(sql); + statement.close(); + logger.info(Thread.currentThread().getName() + ">>> " + sql); + } + } + connection.close(); + } catch (SQLException e) { + logger.error(e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/utils/TimeStampUtil.java b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/utils/TimeStampUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..2ec91ef1cb8ff690d9317f5ef02075bbf0b0aaa7 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/java/com/taosdata/example/utils/TimeStampUtil.java @@ -0,0 +1,35 @@ +package com.taosdata.example.utils; + +import java.sql.Date; +import java.text.ParseException; +import java.text.SimpleDateFormat; + +public class TimeStampUtil { + private static final String datetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS"; + + public static long datetimeToLong(String dateTime) { + SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); + try { + return sdf.parse(dateTime).getTime(); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + public static String longToDatetime(long time) { + SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); + return sdf.format(new Date(time)); + } + + public static void main(String[] args) { + final String startTime = "2005-01-01 00:00:00.000"; + + long start = TimeStampUtil.datetimeToLong(startTime); + System.out.println(start); + + String datetime = TimeStampUtil.longToDatetime(1519833600000L); + System.out.println(datetime); + } + + +} diff --git a/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties b/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties new file mode 100644 index 0000000000000000000000000000000000000000..b445e5f52edf1a2b19c35c1be187716d17cdd7b1 --- /dev/null +++ b/tests/examples/JDBC/JDBCDemo/src/main/resources/log4j.properties @@ -0,0 +1,21 @@ +### 设置### +log4j.rootLogger=debug,stdout,DebugLog,ErrorLog +### 输出信息到控制抬 ### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n +### 输出DEBUG 级别以上的日志到=logs/error.log ### +log4j.appender.DebugLog=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DebugLog.File=logs/debug.log +log4j.appender.DebugLog.Append=true +log4j.appender.DebugLog.Threshold=DEBUG +log4j.appender.DebugLog.layout=org.apache.log4j.PatternLayout +log4j.appender.DebugLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n +### 输出ERROR 级别以上的日志到=logs/error.log ### +log4j.appender.ErrorLog=org.apache.log4j.DailyRollingFileAppender +log4j.appender.ErrorLog.File=logs/error.log +log4j.appender.ErrorLog.Append=true +log4j.appender.ErrorLog.Threshold=ERROR +log4j.appender.ErrorLog.layout=org.apache.log4j.PatternLayout +log4j.appender.ErrorLog.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [ %t:%r ] - [ %p ] %m%n \ No newline at end of file