openfire开发中添加日志输出

来源:互联网 发布:国民经济数据 编辑:程序博客网 时间:2024/06/09 12:07

有时在开发openfire插件时希望添加一些日志信息,调试时使用system.out输出比较方便,但是项目发布时需要去除这些日志会比较麻烦。此时可以配置使用openfire中的日志系统来使用。如下为一个配置demo


1、配置日志和日志级别

  本例中需要配置包名   “com.tgram.buddy.plugin.push”下的日志输出,打开openfire项目build目录中的如下文件,在其中追加包名和日志的level。


2、代码中输出log

通过LoggerFactory获取log对象后,直接调用对应的方法输出log。

package com.tgram.buddy.plugin.push;import java.io.File;import org.jivesoftware.openfire.container.Plugin;import org.jivesoftware.openfire.container.PluginManager;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class PushNodesPlugin implements Plugin {    private static final Logger Log = LoggerFactory.getLogger(PushNodesPlugin.class);@Overridepublic void destroyPlugin() {// TODO Auto-generated method stubSystem.out.println("PushNodesPlugin destroy...");Log.debug("PushNodesPlugin destroy...");}@Overridepublic void initializePlugin(PluginManager manager, File pluginDirectory) {// TODO Auto-generated method stubSystem.out.println("PushNodesPlugin initialize...");Log.debug("PushNodesPlugin initialize...");}}

3、查看log

输出的log存放在openfire输出路径“target\openfire\logs”目录下,打开对应的log日志即可查看到输出的log信息。




4、log4j.xml的更多配置

本文只是简述了一下日志的使用,更多的配置未在文中给出,需要做更多配置可以参考如下日志:

http://blog.csdn.net/coolcoffee168/article/details/6368949


0 0
原创粉丝点击