2.添加org.apache.log4j_1.2.13.v200903072027.jar的依赖。 3.在OpenViewAction.java中添加: Logger logger = Logger.getLogger(OpenViewAction.class); logger.log(Level.ERROR, "This is a test..."); 4.运行控制台打印:(只在控制台上,不在.log文件中) log4j:WARN No appenders could be found for logger (myrcp.OpenViewAction). log4j:WARN Please initialize the log4j system properly. 这是因为没有添加Log4j的配置信息。 5.在启动RCP的插件中的start方法里:
public void start(BundleContext context) throws Exception {
super.start(context); plugin = this; Properties prop = new Properties(); try { prop.load(Activator.class.getResourceAsStream("log4j.properties")); //$NON-NLS-1$ } catch (IOException e) { // e.printStackTrace(); } PropertyConfigurator.configure(prop); } 6.在myrcp.Activator同级目录下添加log4j.properties: ### direct log messages to stdout ### 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=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### direct messages to file hibernate.log ### #log4j.appender.file=org.apache.log4j.FileAppender #log4j.appender.file.File=hibernate.log #log4j.appender.file.layout=org.apache.log4j.PatternLayout #log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ### log4j.rootLogger=warn, stdout #log4j.logger.myrcp=debug #log4j.logger.org.hibernate=info log4j.logger.org.hibernate=debug ### log HQL query parser activity #log4j.logger.org.hibernate.hql.ast.AST=debug ### log just the SQL #log4j.logger.org.hibernate.SQL=debug ### log JDBC bind parameters ### log4j.logger.org.hibernate.type=info #log4j.logger.org.hibernate.type=debug ### log schema export/update ### log4j.logger.org.hibernate.tool.hbm2ddl=debug ### log HQL parse trees #log4j.logger.org.hibernate.hql=debug ### log cache activity ### #log4j.logger.org.hibernate.cache=debug ### log transaction activity #log4j.logger.org.hibernate.transaction=debug ### log JDBC resource acquisition #log4j.logger.org.hibernate.jdbc=debug ### enable the following line if you want to track down connection ### ### leakages when using DriverManagerConnectionProvider ### #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace 7.运行。OK。
原文链接:
|
RCP或者插件 log4j
最新推荐文章于 2024-09-10 12:27:18 发布