(OAF) JDeveloper integrates log4j and outputs the log to the specified file and writes to the database

Source: Internet
Author: User
Tags log4j

Reference:

How to configure log4j in Jdev 11g

Ever wanted to use log4j in your ADF project? Well though Oracle doesn ' t recommends the use of log4j, I say its purely your choice to use it or not.

So how does we configure log4j in ADF? Pretty simple. Just follow these steps

1) Add log4j jars in the project library

2) Create a file log4j.properties in your application Sources Directory (this folder was seen in Jdev–in both Viewcontrol Ler and Model Folder).

The For model project is the present at <path of model PROJECT>MODEL\SRC.

For Viewcontroller Project This file have to be present as <path of model PROJECT>VIEWCONTROLLER\SRC

3) Paste The following contents

****************************

# Set Root logger level to INFO and it only appender to ConsoleOut.
Log4j.rootlogger=info,consoleout,f
# consoleout is set to be a consoleappender.
Log4j.appender.consoleout=org.apache.log4j.consoleappender
# ConsoleOut uses Patternlayout.
Log4j.appender.consoleout.layout=org.apache.log4j.patternlayout
log4j.appender.consoleout.layout.conversionpattern=%-5p: [%d]%c{1}–%m%n
Log4j. Logger.org.apache.jsp=debug
Log4j.appender.f=org.apache.log4j.fileappender
Log4j.appender.f.file=c:/logs/logger.log
Log4j.appender.f.layout=org.apache.log4j.patternlayout
log4j.appender.f.layout.conversionpattern=%d{[ EMAIL&NBSP;PROTECTED]:MM:SS,SSS}%-5p (%13f:%l)%3x–%m%n

#Addon for
Com.sun.faces.level=fine

****************************

Local Integration development Testing

1. Add the log4j jars to the project.

2. Create a new log4j.properties and place it into the MyClasses directory and add the following to it

3.log4j.properties content (This file is just a brief log usage, more detailed log generation settings, please refer to the official documentation and other people's learning notes)

# Set Root logger level to INFO and it only appender to ConsoleOut.log4j.rootLogger=info,consoleout,f,database# ConsoleOut is set to be a ConsoleAppender.log4j.appender.ConsoleOut=org.apache.log4j.consoleappender# ConsoleOut uses PatternLayout.log4j.appender.ConsoleOut.layout=Org.apache.log4j.PatternLayoutlog4j.appender.ConsoleOut.layout.ConversionPattern=%-5p: [%d]%c{1}–%m%nlog4j.logger.org.apache.jsp=DEBUGLOG4J.APPENDER.F=Org.apache.log4j.FileAppender
#由于本地windows系统默认支持中文, so local even if not configured encoding method will not garbled, if the server garbled, please adjust the encoding method log4j.appender.f.encoding=gbk# will generate the log file to the specified directory, for example, the project is in D, then the logs directory is generated to the D drive #log4j.appender.f.file=/logs/logger.txt# a local test, the log file is generated to \JDEVHOME\JDEV\SYSTEM\ORACLE.J2EE.10.1.3.41. $\embedded-Oc4j\config\logs Directory
#服务器若有多个oacore节点, the resulting log results are not yet clear log4j.appender.f.file=./logs/Logger.txtlog4j.appender.f.datepattern='.'yyyy-mm-DDLog4j.appender.f.layout=Org.apache.log4j.patternlayout#log4j.appender.f.layout.conversionpattern=%d{yyyy-mm-DD@HH: Mm:ss,sss}%-5p (%13f:%l)%3x–%m%Nlog4j.appender.f.layout.conversionpattern=%d{yyyy-mm-DD@HH: mm:ss,sss}%-5p%c.%m:%l-%m%N

#DATABASE

Log4j.appender.database=org.apache.log4j.jdbc.jdbcappender
Log4j.appender.database.url=jdbc:oracle:thin: @host:p Ort:sid
Log4j.appender.database.driver=oracle.jdbc.driver.oracledriver
Log4j.appender.database.user=username
Log4j.appender.database.password=password
Log4j.appender.console.threshold=error
Log4j.appender.database.sql=insert into Log4j_test (Stamp,thread, infolevel,class,messages) VALUES ('%d{yyyy-MM-dd HH : Mm:ss} ', '%t ', '%p ', '%l ', '%m ')

# INSERT into log4j (Message) VALUES (' [Framework]%d-%c-%-4r [%t]%-5p%c%x-%m%n ')

# Write to table in database log4j in the Message field, content%d (date)%c: Log information location (class name)%p: Log information level%m: Log specific information generated%n: line-Wrapping of output log information
Log4j.appender.database.layout=org.apache.log4j.patternlayout
log4j.appender.database.layout.conversionpattern=%d%-5p [%c]%m%n

 for Com.sun.faces.level=fine

4. Code

Import Org.apache.log4j.Logger;  Public class Xxxco   extends oacontrollerimpl{privatestatic Logger Logger = Logger.getlogger (Xxxco.  Class. GetName ());    Public void ProcessRequest (Oapagecontext pagecontext,                             oawebbean Webbean)  {logger.info ("Test 123");}   } 

(OAF) JDeveloper integrates log4j and outputs the log to the specified file and writes to the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.