设为首页 收藏本站
查看: 870|回复: 0

[经验分享] ADFLogger日志与weblogic 日志配置与应用

[复制链接]
发表于 2017-2-18 06:01:58 | 显示全部楼层 |阅读模式
  最近要用到ADF日志,所以找了一下文档,自我理解了一下,记录在案,以备后用
  之前没做到日志,所以对日志也不是很了解,所以这次看资料也辛苦的
  在ADF代码中根据需求记录日志信息,确保日志信息在内容上和反应问题的严重程度上的准确而且恰当,是程序员需要做好的重要任务
  要用ADF日志,首先要引包,但是JEV工具已集成了日志包,剩下的就是代码中直接写了,其中最重要的一句就是创建ADFLogger
  如private static ADFLogger logger=ADFLogger.createADFLogger(DataServiceBase.class);
  其中createADFLogger()方法有多个构造函数,大概有6个,
  然后就可以在代码中编写要输出的日志了,其中有两种方式。
  方式一:logger.log(Level.INFO,param);
  方式二:logger.info(param);
  其中param为字符串类型的要输出的日志。
  例如servere消息
  log.log(Level.SEVERE, "exception", nfe);

og.severe("Unexpected exception doing complex thing",nfe);
  日志Level,分为5种
  日志按严重性由高到低的顺序提供了如下的级别



  • SEVERE 严重的错误,导致系统中止。期望这类信息能立即显示在状态控制台上

  • WARNING 潜在问题的级别,它是不符合预期的状态但还不至于成为“错误”,例如使用了废弃的API等等。期望这类信息能立即显示在状态控制台上

  • INFO 运行时产生的有意义的一些信息,主要用于报告消息的目的。期望这类信息能立即显示在状态控制台上

  • CONFIG 静态配置消息,用来输出一些系统配置信息。期望这类信息仅被写入日志文件中

  • FINE 指示提供跟踪信息,简单输出一些跟踪信息。期望这类信息仅被写入日志文件中

  • FINER 指示提供一条相当详细的跟踪消息。期望这类信息仅被写入日志文件中

  • FINEST 指示提供一条最详细的跟踪消息。期望这类信息仅被写入日志文件中
  日志记录方法划分为 5 个主要类别:


  • 一系列的 "log" 方法,这种方法带有日志级别、消息字符串,以及可选的一些消息字符串参数。
  • 一系列的 "logp" 方法(即 "log precise"),其与 "log" 方法相似,但是带有显式的源类名称和方法名称。
  • 一系列的 "logrb" 方法(即 "log with resource bundle"),其与 "logp" 方法相似,但是带有显式的在本地化日志消息中使用的资源包名称。
  • 还有跟踪方法条目("entering" 方法)、方法返回("exiting" 方法)和抛出异常("throwing" 方法)的便捷方法。
  • 最后,还有一系列在非常简单的情况下(如开发人员只想为给定的日志级别记录一条简单的字符串)使用的便捷方法。这些方法按标准级别名称命名("severe"、"warning"、"info" 等等),并带有单个参数,即一个消息字符串。
  如severe级别的方法有如下:


  • severe(java.lang.String msg)
  • severe(java.lang.String message, java.lang.Object param)
  • severe(java.lang.String message, java.lang.Object[] params)
  • severe(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
  • severe(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg, java.lang.Object param1)
  • severe(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg, java.lang.Object[] params)
  • severe(java.lang.String message, java.lang.Throwable t)
  • severe(java.lang.Throwable t)
  其它的方法和方法的详细信息可以查看Java Doc
  在代码中编写好了,可是怎么运行和输出呢,输出又分为输出到控制台和日志文件,运行又分为在测试时JDV自带的WLS和独产的WLS服务器内。
  private static ADFLogger log=ADFLogger.createADFLogger(TestService.class);

public void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

String aa="sss";

try {

int n = Integer.valueOf(aa);

} catch (NumberFormatException nfe) {

System.out.println(nfe.getMessage());

log.log(Level.SEVERE, "exception", nfe);

log.severe("Unexpected exception doing complex thing",

nfe);

}


log.log(Level.WARNING, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  以上代码首先要在JDV开发工具中调试使用的话,先打开文件loggin.xml配置文件,打开方式有三种
  第一,直接在按照路径直接找到,大概位置如下C:\Users\Administrator\AppData\Roaming\JDeveloper\system11.1.1.7.40.64.93\DefaultDomain\config\fmwconfig\servers\DefaultServer,这个只是我电脑上的,看了以后也许你就知道在哪了
There are two ways to get to the logging configuration screen.
第二 Open the Application Server Navigator (Ctrl + Shift + G), right mouse click on theIntegratedWeblogicServerand select Configure Oracle Diagnostic Logging for "IntegratedWeblogicServer".
第三 From the Log window (usually docked underneath your editor) pull down theActionsmenu and selectConfigure Oracle diagnostic Logging.
找到后在配置文件中修改消息类别,不自己写了,直接COPY一下
Both approaches open the same editor on top of the logging.xml file. Here it is, I've expanded the first couple of levels in the tree to make it interesting:

So what we see here is ahierarchyof all the packages in the running app server. Notice that some of the icons are green, these are packages or classes that have a presence in the logging.xml already and some are yellow. This latter group are
transient, that is, we can temporarily set up logging on that package or class for the duration of the application server, but once the application server shuts down all the logging configuration will be reverted.. You'll notice the checkbox at the top of
this screen that is labeledHide Transient Loggers, well you can guess what that does now.

Step 3 - Configure Some Logging

The rest is all fairly selfexplanatory. To configure logging at any level you click on the level column and from the pull down select the level you want to look at. In the image above you can see that I've set the logging for the Root Logger
to the INFO level. This implicitly means that any child of that node (everything in this case because it's the root) will also be logging at the INFO level unless it explicitly overrides. Normally your root logger would log at WARNING or SEVERE, you just
want to keep an eye out for any and all problems at that level.
So perhaps we wanted to switch on CONFIG level logging for everything under the oracle.demo root we would just set that in the level column. Of course with Config level Info messages would still be printed out as well. So you can be as fine grained
about this as you want, controlling the logging level on a class by class or package by package basis.
If need to set up a logger on a class / package that is not visible in the structure (yet) you can use the green add (+) button at the top left of the editor to add a new one in. The loggers you add can be persistent (stored in the logging.xml)
or transient (discarded at the end of the session) Note that transient loggers can only be created when you are actually running the internal WLS instance.
As well as the logging levels it is also possible to configure the handlers. In logging, the handler is the thing that takes your log message and does something with it - prints it to the console, writes it to a file etc. If you select the root
logger in the editor here you will see that it defines three handlers listed in the Handler Declaration section of the screen at the bottom of the editor:



  • odl-handler
  • wls-domain
  • console


The first two would be the default for a standalone WLS instance, but the console we've automatically added for you in the case of the embedded WLS so that you will be able to see the output of your carefully placed logging commands in the log window
of the IDE (Hint-Now is a good time to go toTools>Preferencesand increase the size of your logging buffer). I recommend
that you do not change these handlers and just continue to inherit from the root. The reason for this will become evident in a later installment.
For example in thesampleI'm running here I have a few CONFIG and INFO level logging calls in the code and this generates the following output on the console:

<Library> <initSampleData> Setting up Library sample data
<MainPageBackingBean> <<init>> Creating a new Instance
<MainPageBackingBean> <handleSlotCartridgeMove> Dropping Module : 1 : Left-12
<MainPageBackingBean> <<init>> Creating a new Instance
<MainPageBackingBean> <handleSlotCartridgeMove> Dropping Module : 1 : Left-14
<TaskFlowUtils> <diagnosticInitializer> Key:"displaySlot" Value:"Module : 1 : Left-9" Type:[oracle.demo.whippet.model.Slot]
Cryptic yes - but I know what it all means in the context of this application and it's exactly the information that I need to monitor what's going on. It tells me that by backing bean classes are being created for every request, and in this case
the drophander for some drag and drop processing has received the payload I expect. Finally one of my standard pieces of instrumentation which I embed in my task flow initializer call is reporting all of the parameters passed to it. All good stuff.
Next time we'll take a look at this output information in more detail and explore some of the real power of this logging once you start to relate all of this information together into sequences of events.
接下来就是,添加运行配置器的JVM选项
运行配置器的JVM选项中添加如下的选项
  -Djbo.debugoutput=adflogger -Djbo.adflogger.level=FINE
  添加了这个选项之后,JDeveloper控制台中也会打印出日志信息,如果希望将日志信息输出到一个日志文件,可以配置logging.xml文件,添加
log_handler
来输出重定向,具体可以看上面给出的示例
二 如果在独立服务器上的话,就需要直接进行EM控制台进行日志配置
登陆EM ,打开内部应用程序,找到目标应用,右键点击,日志选日志配置,点开日志文件,然后选择创建日志,
在创建日志中,选择日志路径和生成记录地时间段,有效期等。
其实,在配置好后,打开服务器上的logging.xml,会发现生成了和DEV中一样的代码,贴一下如下
<log_handler name='odl-handler' class='oracle.core.ojdl.logging.ODLHandlerFactory' filter='oracle.dfw.incident.IncidentDetectionLogFilter'>

<property name='path' value='${domain.home}/servers/${weblogic.Name}/logs/${weblogic.Name}-diagnostic.log'/>

<property name='maxFileSize' value='10485760'/>

<property name='maxLogSize' value='104857600'/>

<property name='rotationFrequency' value='daily'/>

<property name='retentionPeriod' value='week'/>

<property name='encoding' value='UTF-8'/>

<property name='useThreadName' value='true'/>

<property name='supplementalAttributes' value='J2EE_APP.name,J2EE_MODULE.name,WEBSERVICE.name,WEBSERVICE_PORT.name,composite_instance_id,component_instance_id,composite_name,component_name,DSID'/>

</log_handler>

时间有点急,写的有点乱,有时间再整理!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-343561-1-1.html 上篇帖子: 为何WebLogic 12c 发生stuck 时无法显示具体的请求路径 下篇帖子: 在应用服务器上部署我的接口程序:weblogic\jboss\spring\hibernate\myeclipse
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表