0
A
回答
1
你可以參考以下幾點:
package org.apache.log4j.jdbcplus.examples.test;
import java.sql.Driver;
import java.sql.Types;
import java.sql.DriverManager;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.jdbcplus.JDBCAppender;
import org.apache.log4j.jdbcplus.JDBCLogType;
import org.apache.log4j.jdbcplus.examples.MyColumnHandler;
import org.apache.log4j.jdbcplus.examples.MyIDHandler;
// Here is a code example to configure the JDBCAppender without a configuration-file using the JDBCIDHandler and JDBCColumnHandler :
public class SourceConfigOracleTest {
// Create a category instance for this class
static Logger logger = Logger.getLogger(Log4JTest.class.getName());
public static void main(String[] args) {
// A JDBCIDHandler
MyIDHandler idhandler = new MyIDHandler();
// A JDBCColumnHandler
MyColumnHandler colHandler = new MyColumnHandler();
// Ensure to have all necessary drivers installed !
try {
Driver d = (Driver) (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
DriverManager.registerDriver(d);
} catch (Exception e) {
e.printStackTrace();
}
// Set the priority which messages have to be logged
logger.setLevel(Level.INFO);
// Create a new instance of JDBCAppender
JDBCAppender ja = new JDBCAppender();
// Set options with method setOption()
ja.setConnector("org.apache.log4j.jdbcplus.examples.OracleConnectionHandler");
ja.setUrl(
"jdbc:oracle:thin:@"
+ "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 62.52.100.41)(PORT = 1521)))"
+ "(CONNECT_DATA = (SERVICE_NAME = oracle8i)))");
ja.setUsername("danko");
ja.setPassword("danko");
ja.setTable("logtest");
ja.setColumn("id", JDBCLogType.ID, idhandler, "INTEGER", Types.INTEGER);
ja.setColumn("prio", JDBCLogType.PRIO, "", "VARCHAR", Types.VARCHAR);
ja.setColumn("cat", JDBCLogType.CAT, "", "VARCHAR", Types.VARCHAR);
ja.setColumn("msg", JDBCLogType.MSG, "", "VARCHAR", Types.VARCHAR);
ja.setColumn("info", JDBCLogType.DYNAMIC, colHandler, "VARCHAR", Types.VARCHAR);
ja.setColumn("addon", JDBCLogType.EMPTY, "", "VARCHAR", Types.VARCHAR);
ja.setColumn("the_timestamp", JDBCLogType.TIMESTAMP, "", "TIMESTAMP", Types.TIMESTAMP);
ja.setColumn("created_by", JDBCLogType.STATIC, "ME", "VARCHAR", Types.VARCHAR);
// other options
//ja.setBuffer("1");
//ja.setCommit("Y");
// Add the appender to a category
logger.addAppender(ja);
// These messages with Priority >= setted priority will be logged to the database.
logger.debug("debug");
logger.info("info");
logger.error("error");
logger.fatal("fatal");
// not required
logger.removeAppender(ja);
}
}
相關問題
- 1. 如何以編程方式配置log4cpp?
- 2. 如何以編程方式配置ELMAH?
- 3. 如何以編程方式配置MessageDispatcherServlet
- 4. 如何以編程方式配置UITableViewCell?
- 5. iOS:如何以編程方式安裝配置配置文件
- 6. 以編程方式配置IPhone設置
- 7. 以編程方式配置ResourceBundleMessageSource
- 8. 以編程方式配置ACS
- 9. 以編程方式啓用配置api?
- 10. ServiceStack 4.5以編程方式配置log4net
- 11. 以編程方式配置多個NIC
- 12. 以編程方式配置記錄器
- 13. 以編程方式配置Log4NetLoggerFactoryAdapter
- 14. 以編程方式配置LogBack DBAppender
- 15. 以編程方式配置Android設備
- 16. 以編程方式配置Log4NetLoggerFactoryAdapter(重試)
- 17. 以編程方式配置MATLAB
- 18. 以編程方式配置LogBack appender
- 19. 以編程方式修改ServiceInstall配置
- 20. 以編程方式配置Apache ActiveMQ
- 21. Log4net以編程方式配置adoAppender
- 22. 如何以編程方式配置Windows cmd.exe設置?
- 23. 如何以編程方式設置WCF端點標識配置?
- 24. 如何以編程方式設置ImageResizer配置?
- 25. 如何以編程方式設置Magento商店配置數據?
- 26. Android如何以編程方式添加/配置Exchange設置?
- 27. 如何以編程方式配置Jetty以執行JSP頁面?
- 28. 如何以編程方式配置JDK記錄器格式?
- 29. 如何以編程方式設置passwordToggleEnabled