1.Eclipse本身已經(jīng)存在了.log文件和Error Log View. 使用Log4j插件有什么意義? 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.運(yùn)行控制臺(tái)打印:(只在控制臺(tái)上,不在.log文件中) log4j:WARN No appenders could be found for logger(myrcp.OpenViewAction). log4j:WARN Please initialize the log4j systemproperly. 這是因?yàn)闆]有添加Log4j的配置信息。 5.在啟動(dòng)RCP的插件中的start方法里: public void start(BundleContext context) throwsException { super.start(context); plugin =this; Properties prop = newProperties(); try{ prop.load(Activator.class.getResourceAsStream("log4j.properties"));//$NON-NLS-1$ } catch(IOException e) { // e.printStackTrace(); } PropertyConfigurator.configure(prop); } 6.在myrcp.Activator同級(jí)目錄下添加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.運(yùn)行。OK。 |
|
來(lái)自: LibraryPKU > 《Java UI》