log4j 日志输出数据库
public void jdbcCreateTable() throws Exception {
Connection connection =DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=true&serverTimezone=UTC", "root", "" );
Class.forName( "com.mysql.cj.jdbc.Driver" );
connection.createStatement().execute( "CREATE TABLE `log_info` ( "
+ " `Id` int(11) NOT NULL AUTO_INCREMENT, "
+ " `level` varchar(255) NOT NULL DEFAULT ‘‘ COMMENT ‘优先级‘, "
+ " `category` varchar(255) NOT NULL DEFAULT ‘‘ COMMENT ‘类目‘, "
+ " `thread` varchar(255) NOT NULL DEFAULT ‘‘ COMMENT ‘进程‘, "
+ " `time` varchar(30) NOT NULL DEFAULT ‘‘ COMMENT ‘时间‘, "
+ " `location` varchar(255) NOT NULL DEFAULT ‘‘ COMMENT ‘位置‘, "
+ " `note` text COMMENT ‘日志信息‘, "
+ " PRIMARY KEY (`Id`) "
+ ")" );
}
四:添加测试代码
/** *
*
* @author zhanchaohan
*
*/
public class PrintTest {
private static Logger logger = Logger.getLogger(PrintTest. class );
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure(PrintTest. class .getResource("/log4j.properties" ));
logger.info( "普通Info信息" );
logger.debug( "调试debug信息" );
logger.error( "报错error信息" );
logger.warn( "警告warn信息" );
logger.fatal( "严重错误fatal信息" );
}
}
log4j 日志输出数据库
标签:depend pid sql tco etl 调试 connector pen user
查看更多关于log4j 日志输出数据库的详细内容...
阅读:26次