logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Can we add FileAppender and JDBCAppender together
Date Fri, 14 Nov 2008 17:23:20 GMT

On Nov 14, 2008, at 3:23 AM, manish_goyal wrote:

>
> Hi,
>
> Please tell me can we add FileAppender and JDBCAppender together in a
> log4j.properties file.

I don't know any reason you could not.

>
>
> I configured my log4j.properties file for both FileAppender and
> JDBCAppender, FileAppender is working fine but JDBCAppender is not  
> working.
> My log4j.properties file is :-
>
> log4j.rootCategory=JDBC
> log4j.appender.JDBC=DBError
> log4j.logger.com.cvs.eph.test=info,myAppender,DBError
>
> # File appender
> log4j.appender.out=org.apache.log4j.RollingFileAppender
> log4j.appender.out.file=D:/Data/myLog.log
> log4j.appender.out.maxFileSize=1024KB
> log4j.appender.out.maxBackupIndex=5
> log4j.appender.out.append=true
> log4j.appender.out.layout=org.apache.log4j.PatternLayout
> log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p  
> %-30.30c{1} -
> %m%n
>
> # DBError DB Options
> log4j.appender.JDBC=org.apache.log4j.jdbcplus.JDBCAppender
> log4j.appender.JDBC.URL=jdbc:oracle:thin:@10.87.187.163:1521:EPHOD1
> log4j.appender.JDBC.user=test
> log4j.appender.JDBC.password=test
> log4j.appender.JDBC.driver=oracle.jdbc.driver.OracleDriver
> #SQL statement to be used (with multiple columns formated)
> log4j.appender.JDBC.layout=org.apache.log4j.PatternLayout
> log4j.appender.JDBC.layout.ConversionPattern=%d [%-15.15t] %-5p  
> %-30.30c{1}
> - %m%n
> log4j.appender.JDBC.sql=INSERT INTO MYTABLE(CODE1,CODE2,REQUESTID)  
> values
> (code1,code2,requestID)
>
> log4j.appender.JDBC.bufferSize=3
>

org.apache.log4j.jdbcplus.JDBCAppender is using an Apache Software  
Foundation package name, but as far as I know is not an Apache  
Software Foundation product.  You should contact the author of that  
appender for support.


> and my JAVA file is :-
>
> import org.apache.log4j.jdbcplus.JDBCAppender;
>
> JDBCAppender DBError = new JDBCAppender();


This is creating a distinct appender instance and is not related to  
the one configured in the configuration file.  The local variable name  
DBError in no way connects this instance with the instance from the  
configuration file.  If you want to programmatically modify that  
appender, you need to call something like:



>
> DBError.setLayout(myLayout);
> try
>          {
>    			Driver d =
> (Driver) 
> (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
>    			DriverManager.registerDriver(d);
>    		}
>          catch(Exception e){}
> String url =
>    	    "jdbc:oracle:thin:@"
>    	      + "(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP) 
> (HOST
> = 10.87.187.163)(PORT = 1521)))" +
>    	        "(CONNECT_DATA = (SERVICE_NAME = EPHOD1)))";
> DBError.setUrl(url);
> DBError.setUsername("test");
> DBError.setPassword("test");
> DBError.setTable("MYTABLE");

To follow the log4j programmatic configuration pattern, you should call:

DBError.activateOptions();

after setting the properties.

>
> myLogger.addAppender(DBError);
>
> I am getting  following error:-
> log4j:ERROR JDBCAppender::flush_buffer(), :
> java.sql.SQLException: ORA-01732: data manipulation operation not  
> legal on
> this view
>
>
> for the myLogger.info("Hello");
>
>
> Please give me pointers to solve this problem.
>
> Thanks.
>
> Regards,
> Manish
>
>
>
> -- 
> View this message in context: http://www.nabble.com/Can-we-add-FileAppender-and-JDBCAppender-together-tp20497197p20497197.html
> Sent from the Log4j - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message