One Star

Problem: Unable to write log to database using log4j

Hi,
I am able to get the log info written to a file (When I run my Talend job, I can see the info such as time, payload etc. in the text file) but I am unable get that info logged into my mssql database.
I have a Logs database table:
lLogKey (bigint, not null)
dt (datetime, null)
Logger (nvarchar(100), null)
Lvl (nvarchar(100), null)
Msg(nvarchar(max), null)
AND
I have created the DB database appender in my org.ops4j.pax.logging configuration file as shown below.
# Root logger
log4j.rootLogger=INFO, out, DB, osgi:VmLogAppender, osgi:eventloglistener
log4j.throwableRenderer=org.apache.log4j.OsgiThrowableRenderer
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
# File appender
log4j.appender.out=org.apache.log4j.RollingFileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{ABSOLUTE} | %-5.5p | %-16.16t | %-32.32C %4L | %X{bundle.id} - %X{bundle.name} - %X{bundle.version} | %m%n
log4j.appender.out.file=${karaf.home}/log/mylog.log
log4j.appender.out.append=true
log4j.appender.out.maxFileSize=1MB
log4j.appender.out.maxBackupIndex=10
# DB logging appender
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DB.URL=jdbc:sqlserver://testserver:1433;instanceName=testserver;databaseName=LogDB;schema=dbo
log4j.appender.DB.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
log4j.appender.DB.user=TestUser
log4j.appender.DB.password=TestPass
log4j.appender.DB.layout=org.apache.log4j.PatternLayout
log4j.appender.DB.layout.OutputHeader=false
log4j.appender.DB.sql=INSERT INTO Logs (dt, Logger, Lvl, Msg) VALUES('%d','%C','%p','%m')
Please advice me on how I can get my log info written to my database table using log4j - I greatly appreciate your help.
Thanks
1 REPLY
Moderator

Re: Problem: Unable to write log to database using log4j

Hi,
Are you using Service Locator server logs? Have you checked document TalendHelpCenter:Logging?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.